Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 36 ยท Main and Renderer Processes

The Renderer Process and Web APIs in Electron

Learn what the Electron renderer process is, which web APIs it can use, why it should not have Node.js access, and how renderers differ from the main process, with runnable demos.

Each window in an Electron app shows a web page, and that page runs in its own renderer process. A renderer is Chromium: it parses your HTML, applies CSS, runs your front-end JavaScript and paints pixels. If you can build something as a normal web page, you can build it as a renderer. Everything you know about the DOM, events, fetch, Canvas, Web Workers, CSS Grid and frameworks like React or Vue applies unchanged.

What makes the renderer special is not what it can do, but what it is deliberately not allowed to do. By default (and in every secure configuration), renderer code cannot touch Node.js, the file system or Electron's native modules. It must ask the main process through a controlled channel. This lesson explains the reasoning and shows what a renderer does have.

One window, one renderer (usually)

Every BrowserWindow creates a renderer process for the web content it loads. Chromium's multi-process design means a crash or hang in one renderer does not bring down the others or the main process. Think of each window as a browser tab with a native frame around it.

flowchart TB
  M["Main process (Node.js)"]
  subgraph W1["Window 1"]
    R1["Renderer: DOM, CSS, JS"]
  end
  subgraph W2["Window 2"]
    R2["Renderer: DOM, CSS, JS"]
  end
  M --- W1
  M --- W2
  R1 -. "no direct access" .- R2

Figure: renderers are isolated from each other and from the main process.

What the renderer has

Everything Chromium offers, for example:

  • The DOM and CSS, document, window, history and location.
  • fetch, WebSocket, Server-Sent Events and other network APIs (subject to CORS and your Content Security Policy).
  • Canvas, WebGL, WebGPU, Web Audio, getUserMedia (with permission) and the Notification API.
  • Web Workers, Service Workers, IndexedDB, localStorage, sessionStorage and Web Crypto.
  • Modern language features: your Electron version's Chromium defines the JavaScript you can use, so you never need a polyfill for a feature that version supports.

Here is a small renderer using only web platform features: a canvas animation driven by requestAnimationFrame and an Intl formatted clock. Nothing in it is Electron-specific, which is the point.

A renderer is a web page

What the renderer must not have

In old tutorials you may see windows created with nodeIntegration: true, which lets page code call require('fs') directly. That is convenient and dangerous. If your page ever shows content you do not fully control (a web article, a chat message with HTML, an ad, an injected script from a dependency), an attacker could read the user's files or run programs. Modern Electron defaults are safer:

Setting Secure default Meaning
nodeIntegration false No require, no Node.js globals in page code
contextIsolation true The page's JavaScript world is separate from the preload script's world
sandbox true The renderer runs in Chromium's OS-level sandbox with limited privileges

Leave all three at their defaults. When the page needs a native feature, you expose exactly that feature through a preload script and IPC. The BrowserWindow options lesson shows where these settings live.

Comparing the two worlds

The easiest way to internalize the difference is a side-by-side table of global names. The stand-in below defines "what exists" in each world and checks code against it, the way a mistaken require in a renderer would fail.

Node.js Stand-in: what exists where

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

electronAPI is a name you choose in the preload script. It is not built in; it appears only if you expose it.

Debugging a renderer

You debug a renderer exactly like a web page. Open DevTools with Ctrl+Shift+I (Cmd+Option+I on macOS) or call win.webContents.openDevTools(). The Console, Elements, Network and Performance panels all work. Errors thrown in renderer code appear in this console, not in the terminal. Use the Application panel to inspect IndexedDB and local storage, and the Network panel to see requests.

Tip: if you want renderer console.log output in your terminal too (useful in tests and CI), listen to the window's console-message event in the main process and print it there.

Frameworks and bundlers

You can use any front-end stack: plain HTML, React, Vue, Svelte or Angular. Build it with Vite or webpack and load the output with win.loadFile() in production, or win.loadURL('http://localhost:5173') during development when the dev server provides hot reload. The renderer stays free of Node.js code in either case.

Browser features and permissions

Some web APIs ask the user for permission (camera, microphone, geolocation, notifications). In a browser, Chromium shows a prompt. In Electron, your main process decides, via session.setPermissionRequestHandler. If you do nothing, many requests are granted automatically, which is rarely what you want. The security chapter covers hardening this.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a renderer process in Electron?

    Each window's web content runs in a renderer process, which is a Chromium process running your HTML, CSS and JavaScript.
  2. 2. Which settings are the secure defaults for web preferences?

    Modern Electron disables Node.js in the renderer and turns on context isolation and the sandbox by default.
  3. 3. Where do uncaught errors in renderer code show up?

    Renderer errors appear in the DevTools console of that window, like in a browser tab.
  4. 4. Why would a renderer use window.electronAPI?

    electronAPI is just a conventional name chosen in the preload script through contextBridge.

Summary

  • A renderer is a Chromium process that runs one window's page: DOM, CSS, web APIs and your front-end framework.
  • Renderers are isolated from each other and from the main process.
  • Keep nodeIntegration off and contextIsolation and sandbox on.
  • Native features reach the page only through what a preload script exposes.
  • Debug renderers with DevTools; main-process logs go to the terminal.

Next: BrowserWindow Options and WebPreferences