I'm creating a electron BrowserWindow
using a remote url, so I can't really use the var ipc = require('ipc');
syntax to include ipc. It is possible to send messages from a remote url to the electron main-process? If so where can I get the javascript source for it?
Or maybe there is a better way to pass info to electron main-process? Just need to send the logged in user info.
Note: In electron >= 14.0. 0 , you must use the new enable API to enable the remote module for each desired WebContents separately: require("@electron/remote/main"). enable(webContents) .
IPC channels In Electron, processes communicate by passing messages through developer-defined "channels" with the ipcMain and ipcRenderer modules. These channels are arbitrary (you can name them anything you want) and bidirectional (you can use the same channel name for both modules).
About`@electron/remote` is an [Electron](https://electronjs.org) module that bridges JavaScript objects from the main process to the renderer process. This lets you access main-process-only objects as if they were available in the renderer process.
This question has been asked quite sometime back, but I think this could still be useful. The way you can inject Javascript into the browser window is using the preload lag, in the web preferences, add the options:
const window = new BrowserWindow({
webPreferences:{
preload: <path_to>/preload.js
}
})
// preload.js
const ipcRenderer = require('electron').ipcRenderer;
window.ipcRenderer = ipcRenderer
In the webpage of you the external url you are loading you can directly use window.ipcRenderer
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With