没有远程模块的 webview 和 main window 之间的通信

Comunication between webview and main window without remote module

有没有办法在不启用远程模块的情况下在 webview 和主 window 之间进行通信?

<webview src="http://www.google.com/" enableremotemodule="false"></webview>

When this attribute is false the guest page in webview will not have access to the remote module. The remote module is avaiable by default.

https://electronjs.org/docs/api/webview-tag#enableremotemodule

不完全是你问的,但我注意到了 Electron 团队的 warning 并选择使用 iframes 而不是 webviews

We currently recommend to not use the webview tag and to consider alternatives, like iframe, Electron's BrowserView, or an architecture that avoids embedded content altogether.

我已经使用 Window.postMessage() 取得了成功,但在这方面我还远未达到 "expert"。

The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.