Secure Renderer‑Main Communication in Electron Using contextBridge
Learn how Electron’s context isolation and contextBridge let you expose safe, limited APIs from the preload script to the renderer, keeping Node access locked down.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn how Electron’s context isolation and contextBridge let you expose safe, limited APIs from the preload script to the renderer, keeping Node access locked down.
Learn how Electron’s context isolation feature prevents renderer code from accessing Node.js APIs directly and how to expose only the functions you need via contextBridge.
Learn how to lock down Electron renderer processes by enabling contextIsolation, disabling nodeIntegration, and exposing a minimal API via a preload script. This guide covers requirements, design, trust boundaries, operational checks, failure modes, and when the design must change.
Goal Developers migrating an Electron application to v15 or later face a choice: keep contextIsolation disabled to preserve legacy code that relies on nodeIntegration , or enable it for the security benefits it offers. The core question is how this decision affects existing renderer scripts that directly access Node.js APIs. Uncertainty Electron’s documentat
Electron version 12 and later default to contextIsolation: true to prevent renderer processes from accessing Node.js internals. This security boundary is designed to stop unauthorized public access to system APIs by separating the JavaScript contexts of the preload script and the renderer. While contextBridge allows the definition of a controlled gateway for
Electron's security model relies on the separation of the Main and Renderer processes. While contextIsolation is enabled by default in modern versions to prevent prototype pollution, there are scenarios where specific Node.js capabilities are required within the renderer's logic without exposing the entire Node.js API to the web content. The primary constrai
Electron's security model relies on contextIsolation to separate the renderer process from the main process. To facilitate communication, the contextBridge module allows developers to expose a limited API from a preload script to the renderer's global window object. A critical design concern arises when complex objects or entire Electron modules are passed t