Disable node integration in new BrowserWindows


#1

Hello,

In our Electron app, we’ve disabled node integration in our main BrowserWindow by adding 'node-integration': false to the object we pass to the BrowserWindow constructor.

In certain circumstances, when the web page code within our app calls window.open, we’d like to allow new windows to be opened. However, we need node integration to be disabled for these new windows as well.

Is it possible to disable node integration for new windows opened in this fashion? It seems not, as node integration is enabled by default and there seems to be no way to control the options that are passed to the new BrowserWindow.

I’m aware of the 'new-window' event documented here: http://electron.atom.io/docs/v0.27.0/api/browser-window/, and I understand that we can prevent new windows from being opened by calling preventDefault on the argument event. However, there seems to be no way to access or modify the new BrowserWindow that would be created from inside a 'new-window' event handler.


#2

Could you subclass BrowserWindow to not include Node integration and only use that subclass in your application instead of BrowserWindow?


#3

Thanks for the response leedohm. I couldn’t figure out how to do that after poking around for a while. It would be cool if this was easier to accomplish/part of the public API.


#4

generally i would like to still have node integration but only by explicitly exposing node modules to electron instead of just giving it require access (which also runs havoc with browserify etc)