I want to detect the specific frame/browserWindow. I have one main process and two browser windows which all three are sending message to each other using same channel . in IPCMain I need to detect one of them. I saw that IPCmain event has a function named frameId but when I use it I get undefined.
ipcMain.once("postMessage", (event, message) => {
if(!activeRequest) return;
activeRequest.json(message).send();
});
You can the get the current webcontent id from the main process by accessing the sender object in the events object which is the first argument.
console.log(event.sender.webContents.id);
you can also pass the id of the window that the eent is coming from via the renderer process.
// in the renderer process do this
electron.ipcRenderer.send("new-message", {
winId: electron.remote.getCurrentWebContents().id ,
message: "Hi"
});
when the main process receives this event, you just have to access the winId
property in the message object
Either you can pass the identity in ipc message payoad, or you can get the windows web content id via, ipc message's sender object.
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