同じところで引っかかったので調べたところ、以下のISSUEが見つかりました。
https://github.com/electron/electron/issues/5113
こちらによると nodeIntegration:false の状態でIPCにアクセス出来ないのは仕様とのことです。
Electron4以降は、nodeIntegrationの指定をしない場合、以下の警告が発生します。
Electron Deprecation Warning (nodeIntegration default change) This window has node integration enabled by default. In Electron 5.0.0, node integration will be disabled by default. To prepare for this change, set {nodeIntegration: true} in the webPreferences for this window, or ensure that this window does not rely on node integration and set {nodeIntegration: false}.
ですので、単純にこの警告を回避したいだけなのであれば、 nodeIntegration:trueを設定し、IPCにアクセスするのが簡単です。
他の方法としては、BrowserWindowのwebPreferences.preloadで読み込む方法もあります。
js
1new BrowserWindow({
2 webPreferences: {
3 nodeIntegration: false,
4 preload: __dirname + '/preload.js', //フルパスの指定が必要
5 }
6});
js
1// preload.js
2const electron = require('electron');
3global.electron = electron;
このようにして、preload.jsからglobalオブジェクトにrequireしたものをセットしておくと、
nodeIntegration:falseであっても、rendererプロセスからwindow.electronのように参照することができます。
但し、この手法を取った場合、Electron4では更に以下のような警告が表示されます。
Electron Deprecation Warning (contextIsolation default change) This window has context isolation disabled by default. In Electron 5.0.0, context isolation will be enabled by default. To prepare for this change, set {contextIsolation: false} in the webPreferences for this window, or ensure that this window does not rely on context isolation being disabled, and set {contextIsolation: true}.
For more information, see https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content
要は、Electron5からはcontextIsolation: trueがデフォルトになるとの警告なのですが、
js
1new BrowserWindow({
2 webPreferences: {
3 nodeIntegration: false,
4 contextIsolation: true,
5 preload: __dirname + '/preload.js',
6 }
7});
とした場合、preload.jsのglobalと、rendererプロセスのwindowが分離されるため、明示的にcontextIsolation: falseを指定する必要があります。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。