electron: Preload script is not loaded for a window created with window.open
- Output of
node_modules/.bin/electron --version: v4.0.0 - Operating System (Platform and Version): Windows 10
- Output of
node_modules/.bin/electron --versionon last known working Electron version (if applicable): 1.8.8 Started to fail since 2.x versions.
Expected Behavior
Preload script should be loaded also for a window created with window.open and nativeWindowOpen: true, nodeIntegration: false
I don’t see any warning about nodeIntegration.
Actual behavior Preload script is not loaded. I also see a warning about nodeIntegration enabled.
To Reproduce
$ git clone https://github.com/ficristo/electron-quick-start -b issues/16224
$ npm install
$ npm start || electron .
- Open devtools and see the warning about nodeIntegration
- Click the button on the first window
- Open devtools of the new windows and see only an console.log. Try to type window.process to find it is undefined.
Try again with electron@1.8.8
- Open devtools and see no warning about nodeIntegration
- Click the button on the first window
- Open devtools of the new windows and see a couple of console.log also related to the preload script. Try to type window.process to find it is available.
Screenshots N/A
Additional Information N/A
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 18 (1 by maintainers)
I ended up using
BrowserWindow(just like the one in main.js) instead of window.open, if you use this approach, which is not optimal, make sure to set parent as main window , this is the complete code for the function:Also you can read more on this approach here
@electron-triage , how hard is it to make better documentation that actually can render a solution ? I have been all over this document , tried every single thing it is suggesting with no avail, it is a total contraction of itself. This is a problem that my newly opened window can not call electronAPI no more because of this contextIsolation feature, at this point most of the devs do not care about security, just want the app to work. As above for example @ficristo mentions that this can be resolved by setting
contextIsolation: false, this is not even allowed in my app, once i do it then thecontextBridge.exposeInMainWorld('electronAPI', {stops working and of course i get errors about it. why is this enforced, why can’t I choose to make my app less secure? And then as @thorsent mentions I can not use the function suggested in the documentationwebContents.setWindowOpenHandlerto set manually the preload for my new window, why because this does not work when contextIsolation is true. Then what is the solution, i have been trying to resolve for 3 days now, and I can’t rebuild this in a different framework as I got too involved in this app, but it is becoming clear to me why this is a very unpopular framework among devs.