gpt4 book ai didi

electron - 使用webcontents.executeJavaScript会导致 'error processing argument'是什么原因?

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

创建新的BrowserWindow后,将在其webContents上启动此代码

newRoom.webContents.executeJavaScript(
client.emit("authentication", {
username: "bob",
password: "1234"
})
);

代码执行正常,但在devtools中抛出错误-
Uncaught (in promise) TypeError: Error processing argument at index 1, conversion failure from #<Object>

代码的格式是否有问题?

最佳答案

和往常一样,阅读文档可能是第一件事也是最好的事情。

webContents方法contents.executeJavaScript期望将字符串作为第一个参数...

这可以达到目的:

newRoom.webContents.executeJavaScript(
'client.emit("authentication", { username: "bob", password: "1234" })'
);

或者:
newRoom.webContents.executeJavaScript(
`client.emit("authentication", {
username: "bob",
password: "1234"
})`
);

但是,最初的问题提到“代码执行得很好”,这意味着甚至不需要将其传递给渲染器进程即可执行...
client.emit("authentication", {
username: "bob",
password: "1234"
});

关于electron - 使用webcontents.executeJavaScript会导致 'error processing argument'是什么原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60196006/

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