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/api

4 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 API requirements

The api provided to exposeInMainWorld must be a Function, string, number, Array, boolean, or an object whose keys are strings and values are a Function, string, number, Array, boolean, or another nested object that meets the same conditions.

contextBridge function vs value handling

Function values are proxied to the other context. All other values are copied and frozen. Any data or primitives sent in the API become immutable and updates on either side of the bridge do not result in an update on the other side.

contextBridge supported types table

Type support for parameters, errors, and return values: string: Simple type, parameter support ✅, return value support ✅, no limitations. number: Simple type, parameter support ✅, return value support ✅, no limitations. boolean: Simple type, parameter support ✅, return value support ✅, no limitations. Object: Complex type, parameter support ✅, return value support ✅, limitations: keys must be supported using only simple types; values must be supported in table; prototype modifications are dropped; custom classes copy values but not prototype. Array: Complex type, parameter support ✅, return value support ✅, same limitations as Object type. Error: Complex type, parameter support ✅, return value support ✅, limitations: errors thrown are copied, message and stack trace may change due to being thrown in different context, custom properties on Error object will be lost. Promise: Complex type, parameter support ✅, return value support ✅, no limitations. Function: Complex type, parameter support ✅, return value support ✅, limitations: prototype modifications are dropped; sending classes or constructors will not work. Cloneable Types (per MDN Web Workers API structured clone algorithm): Simple type, parameter support ✅, return value support ✅, see MDN documentation. Element: Complex type, parameter support ✅, return value support ✅, limitations: prototype modifications are dropped; custom elements will not work. Blob: Complex type, parameter support ✅, return value support ✅, no limitations. VideoFrame: Complex type, parameter support ✅, return value support ✅, no limitations. Symbol: N/A complexity, parameter support ❌, return value support ❌, symbols cannot be copied across contexts so they are dropped.

contextBridge exposing Node global symbols example

Example of using contextBridge to expose Node APIs such as crypto to the renderer: const { contextBridge } = require('electron') const crypto = require('node:crypto') contextBridge.exposeInMainWorld('nodeCrypto', { sha256sum (data) { const hash = crypto.createHash('sha256') hash.update(data) return hash.digest('hex') } })

Give your agent this brain