Electron webview 标签在执行 JavaScript 后不执行回调 (CoffeeScript)

Electron webview tag does not execute callback after executing JavaScript (CoffeeScript)

我有一个 webview 标签,我正在尝试执行 javscript 并根据文档读取结果:Electron webview tag docs。但是回调永远不会执行:

@webviewOutlet.executeJavaScript("10+2", (n)-> console.log "#{n}") #Nothing in console

我在 NodeJS 中使用 WebView 作为 Atom 包的一部分。

此处缺少必需的参数 userGesture,因此,您将函数传递给预期的布尔变量。

试试这个:

@webviewOutlet.executeJavaScript("10+2", false, (n)-> console.log "#{n}") 

executeJavaScript 函数的第二个参数不是回调,它是 userGesture

该函数的正确使用方法如下:

webview.executeJavaScript('10 + 2', false, (n) => { console.log(n) })

当然,把第二个参数userGesture改成你需要的。

Documentation