I have a single page application that right now runs in a single Electron browser window. Is it possible to create a second window that will run in the same Javascript context as my main window? For example, I can directly create elements in the second window or attach event listeners etc.
Asked
Active
Viewed 578 times
0
-
1i guess you mean to unify webContents context - you cant. but you can design your app data(state) driven and pipe data between to windows via main process. or even run an instance just to manage your state. else read EdKnwles answer & links ^^ – Estradiaz Nov 25 '19 at 12:10
-
I suspected this was not possible without (significantly) changing the application architecture. – LeoTietz Nov 26 '19 at 16:28
1 Answers
2
You can try using the BroadcastChannel API.
The BroadcastChannel interface represents a named channel that any browsing context of a given origin can subscribe to. It allows communication between different documents (in different windows, tabs, frames or iframes) of the same origin. Messages are broadcasted via a message event fired at all BroadcastChannel objects listening to the channel.
https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel.
If you just need an input or something from the user, you may want a dialog.
Display native system dialogs for opening and saving files, alerting, etc.
https://electronjs.org/docs/api/dialog
Or just a modal
Easily create modals using child browser windows

Ed Knowles
- 1,925
- 1
- 16
- 24