How does electron get the value in the webview page?

use preload to inject js into webview pages, and how to pass values to preload-injected js, webview pages in that page uses vue

Sep.05,2021

just as the main process communicates with the rendering process, the rendering process can also communicate with webview, as shown in the following code.

you can also add parameters, and you can implement your requirements in the following ways.

/ / on the page
const webview = document.querySelector ('webview')
webview.addEventListener (' ipc-message', (event) = > {
console.log (event.channel)
/ / Prints "pong"
})
webview.send ('ping')

/ / in webview
const {ipcRenderer} = require ('electron')
ipcRenderer.on (' ping', () = > {
ipcRenderer.sendToHost ('pong')
})

Menu