ContextBridge
It is dangerous if the browser can have free access to all nodejs’s functions. Therefore, it need to be specified which functions can renderer.js use, like the functions for OS interactions.
- e.g. You cannot
import path from node:pathin renderer.js
Context bridges needs to be created in preload.js
- contextBridge and ipcRenderer
contextBridge.exposeInMainWorld- expose the function in nodejs to
renderer.js,
- expose the function in nodejs to
- Use ipcMain to connect with the database
main.js, preload.js renderer.js
renderer.jshandles HTML rendering,main.jshandles all other app logic.main.jsinjects thepreload.jsto therenderer.js,sorenderer.jscan use the exposed functions- add
renderer.jsas script insideindex.html.
Electron Forge
The building process requires dpkg and fakeroot.