I am trying to convert a web app to electron and still learning about the methods of communicating between main and renderer, etc.
I had a partially working example, with nodeIntegration, but now I am trying to convert it to work with default settings: nodeIntegration:false, contextIsolation:true, sandbox:true, etc. and running into issues.
I have a preload.js script setup to expose some extra interface like so:
const path = require('path')
// All api used from node:
const node = {
path: { join: path.join }
}
contextBridge.exposeInMainWorld('node', node);
There will be other node APIs I plan to expose later but I'm keeping the example simple for now.
This does not work, I guess because path module is not available from a sandboxed preload, as that gives me module not found: "path"
As a quick test I tried temporarily setting sandbox:false, but this results in electron opening to a white screen with no error in the terminal, and no way to open the dev console to check for errors there.
I am still very confused about the intended way to pass control from main to preload to renderer or whatever is supposed to happen. With default security settings, is require basically only usable from main javascript code (not within preload.js)? I thought the whole point of preload is that it has access to all the APIs so that they can be exposed to renderer.
Could someone help by providing a minimum example of how I should ideally expose path.join ?