[英]how I use webContents.executeJavaScript execute a function that which be defined in preload.js
/* I want to call a function which defined in the preload.js file, but it getting an error. /* 我想调用一个在 preload.js 文件中定义的函数,但它得到一个错误。 Instead, I just execute an alert (" aaaaaa "), which does the job correctly */ main process:相反,我只是执行一个警报(“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); }) });
/-------------------------------------------------------------------------------------------------/ renderer preload.js /------------------------------------------------- ------------------------------------------------/ 渲染器预加载.js
aa = () => { alert(123123123); }
/-------------------------------------------------------------------------------------------------/ /------------------------------------------------- ------------------------------------------------/
but it does not work!但它不起作用! enter image description here
can use contextBridge to export api to mainprocess可以使用contextBridge将api导出到mainprocess
https://www.electronjs.org/docs/api/context-bridge https://www.electronjs.org/docs/api/context-bridge
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.