gpt4 book ai didi

electron - Webframe executeJavascript传递对象

转载 作者:行者123 更新时间:2023-12-03 12:29:05 27 4
gpt4 key购买 nike

由于要在Webview中加载远程内容,因此我添加了 contextIsolation

使用预加载脚本内部的webFrame.executeJavascript(...),如何将无法序列化的对象传递到内部网页的上下文中?

更具体地说,这是我的示例:

preload.js:

// In the preload.js context
const { ipcRenderer, webFrame } = require('electron')
const ipc = {
send (data) {
ipcRenderer.sendToHost(...)
}
}
// Now I want to pass down ipc to the webpage's context
// This webpage is expecting window.myApp.ipc, so that it could use it like window.myApp.ipc.send(...)
webFrame.executeJavaScript(`window.myApp.ipc = ${ipc}`); // Doesn't work.

最佳答案

无法通过executejavascript发送不可序列化的对象。如果您的预加载脚本是用于Webview的,则可以将某些对象附加到window中以进行全局访问。

关于electron - Webframe executeJavascript传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50629008/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com