new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Electron · API · all subjects

context bridge & isolation

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

process.contextIsolated property

process.contextIsolated is a readonly boolean that indicates whether the current renderer context has contextIsolation enabled. It is undefined in the main process.

process.contextId property

process.contextId is a readonly optional string representing a globally unique ID of the current JavaScript context. Each frame has its own JavaScript context. When contextIsolation is enabled, the isolated world also has a separate JavaScript context. This property is only available in the renderer process.

WebPreferences preload property and preload script interface

The `preload` string property specifies a script that will be loaded before other scripts run in the page. The preload script will always have access to Node APIs regardless of whether node integration is turned on or off. The value should be the absolute file path to the script. When node integration is turned off, the preload script can reintroduce Node global symbols back to the global scope.

WebPreferences contextIsolation property

The `contextIsolation` boolean property determines whether to run Electron APIs and the specified `preload` script in a separate JavaScript context. Defaults to `true`. The context that the `preload` script runs in will only have access to its own dedicated `document` and `window` globals, as well as its own set of JavaScript builtins (`Array`, `Object`, `JSON`, etc.), which are all invisible to the loaded content. The Electron API will only be available in the `preload` script and not the loaded page. This option uses the same technique used by Chrome Content Scripts and can be inspected in the dev tools by selecting the 'Electron Isolated Context' entry in the combo box at the top of the Console tab.

contents.executeJavaScriptInIsolatedWorld() method

The contents.executeJavaScriptInIsolatedWorld(worldId, scripts[, userGesture]) method takes worldId (Integer, 0 is default, 999 is for contextIsolation), scripts (WebSource[]), and optional userGesture (boolean, default false). Returns Promise<any> that resolves with result or rejects if rejected promise.

Give your agent this brain