[英]webContents.send vs webContents.executeJavaScript
[英]how I use webContents.executeJavaScript execute a function that which be defined in preload.js
/* 我想調用一個在 preload.js 文件中定義的函數,但它得到一個錯誤。 相反,我只是執行一個警報(“aaaaaa”),它正確地完成了工作 */ 主進程:
const winViewBrowser = new BrowserView({ backgroundColor: '#ffffff', webPreferences: { contextIsolation:true, preload: path.join(__dirname, 'preload.js'), } }); win.setBrowserView(winViewBrowser); winViewBrowser.webContents.loadURL(url_local); winViewBrowser.webContents.on('dom-ready', () => { winViewBrowser.webContents.executeJavaScript(aa();, true).then((result) => { console.log(result); }) });
/------------------------------------------------- ------------------------------------------------/ 渲染器預加載.js
aa = () => { alert(123123123); }
/------------------------------------------------- ------------------------------------------------/
但它不起作用! enter image description here
可以使用contextBridge將api導出到mainprocess
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.