Preload Scripts

  • Electron has a main process that’s a Node.js environment (this has full OS access)
    • So you can access electron modules & node.js built-ins and other packages
    • You CANNOT access the HTML DOM though!
  • Rendering processes do NOT run Node.js by default (for security)
  • Preload scripts bridge these two processes together.
    • They have full access to the HTML DOM but not full access to a Node.js environment.
      • When i run console.log() the log is in the console within developer tools and not the terminal
    • These are injected (how?todo) before the web page loads in the renderer.
    • ”To add features to your renderer that require privileged access, you can define global objects through the contextBridge API.”

IPC

IPC: Inter-process communication For electron: ipcMain and ipcRenderer let you communicate between the two processes (accessing the DOM from the main process, or electron modules from the renderer)

“exposing something in the main world lets you access it in the renderer” vice versa is also true.