Header menu logo fable-electron-docs-api

contextBridge Type

⚠ Process Availability: Main ❌ | Renderer ✔ | Utility ❌ | Exported ✔

Create a safe, bi-directional, synchronous bridge across isolated contextsProcess: RendererAn example of exposing an API to a renderer from an isolated preload script is given below:// Preload (Isolated World)const { contextBridge, ipcRenderer } = require('electron')contextBridge.exposeInMainWorld( 'electron', { doThing: () => ipcRenderer.send('do-a-thing') })### Glossary### Main WorldThe "Main World" is the JavaScript context that your main renderer code runs in. By default, the page you load in your renderer executes code in this world.### Isolated WorldWhen contextIsolation is enabled in your webPreferences (this is the default behavior since Electron 12.0.0), your preload scripts run in an "Isolated World". You can read more about context isolation and what it affects in the security docs.

Static members

Static member Description

contextBridge.executeInMainWorld (func, ?args)

Full Usage: contextBridge.executeInMainWorld (func, ?args)

Parameters:
    func : 'a -> 'b
    ?args : obj[]

Returns: obj
Modifiers: inline
Type parameters: 'a, 'b

A copy of the resulting value from executing the function in the main world. Refer to the table on how values are copied between worlds.

func : 'a -> 'b
?args : obj[]
Returns: obj

contextBridge.exposeInIsolatedWorld (worldId, apiKey, api)

Full Usage: contextBridge.exposeInIsolatedWorld (worldId, apiKey, api)

Parameters:
    worldId : int
    apiKey : string
    api : obj

Modifiers: inline
worldId : int
apiKey : string
api : obj

contextBridge.exposeInMainWorld (apiKey, api)

Full Usage: contextBridge.exposeInMainWorld (apiKey, api)

Parameters:
    apiKey : string
    api : obj

Modifiers: inline
apiKey : string
api : obj

Type something to start searching.