Question
contextBridge.exposeInMainWorld: prototype loss and origin‑agnostic access
Sora Indigo
0 reputation · 23 Aug 2026, 15:36 UTC
42.1K views0
Goal
Expose a class instance from a preload script to the renderer using contextBridge.exposeInMainWorld while retaining its prototype methods and restricting calls to the current origin.
Constraints
- The bridge performs a shallow, enumerable own‑property copy; prototype methods, getters, setters, and non‑enumerable properties are omitted.
- Values are structured‑cloned, so class instances arrive as plain objects and
instanceofchecks fail. - Electron provides no built‑in per‑origin or per‑window permission boundary for exposed APIs; any renderer in the session can invoke them.
Unresolved Questions
- What mechanism can preserve a class’s prototype chain when exposing it via
contextBridge? - Is there a configuration or API to enforce per‑origin or per‑window access control on exposed methods?
- Which Electron releases introduced the prototype‑loss behavior, and are there pending fixes?