Electron - Rederer process can use Node feature

less than 1 minute read

Setting nodeIntegration true in webPreferences section in main.js will allow to use Node feature in renderer process such as require. And setting webSecurity false will disable CORS in a renderer process.

1
2
3
4
5
6
7
8
  mainWindow = new BrowserWindow({
    width: 1024,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      webSecurity: false
    }
  });

If a renderer process needs to access the self signed web API, the following code will allow to access it.

1
2
3
4
5
6
7
8
9
app.on(
  "certificate-error",
  (event, webContents, url, error, certificate, callback) => {
    // On certificate error we disable default behaviour (stop loading the page)
    // and we then say "it is all fine - true" to the callback
    event.preventDefault();
    callback(true);
  }
);