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
|
Full Usage:
contextBridge.executeInMainWorld (func, ?args)
Parameters:
'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.
|
Full Usage:
contextBridge.exposeInIsolatedWorld (worldId, apiKey, api)
Parameters:
int
apiKey : string
api : obj
Modifiers: inline |
|
Full Usage:
contextBridge.exposeInMainWorld (apiKey, api)
Parameters:
string
api : obj
Modifiers: inline |
|
fable-electron-docs-api