IPC with Child Windows


Is it possible to, from the renderer process, spawn a new browserwindow, and then send ipc messages back to parent? If so, how? If they are both in renderer process… would I just use ipcMain in the first renderer process and ipcRenderer in the second?


I think you can check what I have done in editor-framework. When there are two windows communicate to each other, the process will looks like this:

renderer A send ipc with sesson-id -> main process, store session-id and send another ipc to B -> renderer B

When renderer B reply:

renderer B send ipc with session-id -> main process, get session-id and send ipc back to A -> renderer A

The key is to create and store session-id for each ipc message, this is for renderer reply message back to the sender. But if your message is a one way ticket, just send to main and let main-process help you transfer the message to the target window.

Here is the detail code in editor-framework about it:


That seems like a like a lot of duplication of code just to forward the messages around.

I did actually figure out that you CAN in fact import the ipcMain module into the renderer on both sides. So… instead of sending everything everything back to the main process and then forwarding it to the other renderer I can actually just import ipcMain in the second renderer. Then, I can use ipcRenderer.send() in the first renderer and listen for the event in the second renderer the same way you would in the main process.


This sounds interesting… are there no potential pitfalls with having ipcMain running in two places (main and an arbitrary renderer process)? Mind sharing a small example of your code?