Relative Content

Tag Archive for webviewelectronipcrenderer

Unable to send message from javascript injected into webview

I am wanting to send messages from javascript injected into a webview element using webview.executeJavaScript, to main or renderer scripts. What I could find on the web sounds pretty straightforward: Add const { ipcRenderer } = require('electron'); to the webview preload script, then call ipcRenderer.send() or ipcRenderer.sendToHost() from the webview javascript content. However, in all my attempts, I get errors saying ipcRenderer is not defined in the injected javascript. Maybe this works if the ipcRenderer call is in the page loaded into the webview (but not for injected js), but I cannot test that as I have no control over the content.