new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

contextbridge/methods

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

contextBridge.exposeInMainWorld method

Method signature: contextBridge.exposeInMainWorld(apiKey, api). Parameters: apiKey (string) - the key to inject the API onto window; the API will be accessible on window[apiKey]. api (any) - the API object to expose.

contextBridge.exposeInIsolatedWorld method

Method signature: contextBridge.exposeInIsolatedWorld(worldId, apiKey, api). Parameters: worldId (Integer) - the ID of the world to inject the API into; 0 is the default world, 999 is the world used by Electron's contextIsolation feature, 1000+ is recommended for custom isolated worlds. apiKey (string) - the key to inject the API onto window; the API will be accessible on window[apiKey]. api (any) - the API object to expose.

contextBridge.executeInMainWorld method (experimental)

Method signature: contextBridge.executeInMainWorld(executionScript). Returns any - a copy of the resulting value from executing the function in the main world. Parameters: executionScript (Object) with func (...args: any[]) => any - a JavaScript function to execute; the function will be serialized and any bound parameters and execution context will be lost. args (any[], optional) - an array of arguments to pass to the function; these arguments will be copied between worlds according to the type support table.

contextBridge exposeInMainWorld example

Example of exposing an API to a renderer from an isolated preload script: // Preload (Isolated World) const { contextBridge, ipcRenderer } = require('electron') contextBridge.exposeInMainWorld( 'electron', { doThing: () => ipcRenderer.send('do-a-thing') } ) // Renderer (Main World) window.electron.doThing()

contextBridge complex API example

Example of exposing a complex API with nested objects, functions, and various data types: const { contextBridge, ipcRenderer } = require('electron') contextBridge.exposeInMainWorld( 'electron', { doThing: () => ipcRenderer.send('do-a-thing'), myPromises: [Promise.resolve(), Promise.reject(new Error('whoops'))], anAsyncFunction: async () => 123, data: { myFlags: ['a', 'b', 'c'], bootTime: 1234 }, nestedAPI: { evenDeeper: { youCanDoThisAsMuchAsYouWant: { fn: () => ({ returnData: 123 }) } } } } )

contextBridge exposeInIsolatedWorld example

Example of exposing an API to a specific isolated world using exposeInIsolatedWorld: const { contextBridge, ipcRenderer } = require('electron') contextBridge.exposeInIsolatedWorld( 1004, 'electron', { doThing: () => ipcRenderer.send('do-a-thing') } ) // Renderer (In isolated world id 1004) window.electron.doThing()

Give your agent this brain