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

app/overview

128 notes in this subject, read out of this brain and free to use. This is page 1 of 3.

app module - main process control

The app module controls your application's event lifecycle. It is only available in the main process.

BrowserView usage example

Example of creating and using BrowserView in the main process: ```js const { app, BrowserView, BrowserWindow } = require('electron') app.whenReady().then(() => { const win = new BrowserWindow({ width: 800, height: 600 }) const view = new BrowserView() win.setBrowserView(view) view.setBounds({ x: 0, y: 0, width: 300, height: 300 }) view.webContents.loadURL('https://electronjs.org') }) ```

BrowserView module process and availability

The BrowserView module is part of the Main process. It cannot be used until the ready event of the app module is emitted. Electron's built-in classes cannot be subclassed in user code.

BrowserView webContents property

A BrowserView instance has a webContents property that is a WebContents object owned by the view.

BrowserView class deprecated, replaced by WebContentsView

The BrowserView class is deprecated and replaced by the new WebContentsView class. Developers should migrate to WebContentsView for embedding additional web content.

ClipboardItem class overview

ClipboardItem is a class available in the main process that represents a single clipboard entry pairing one or more MIME-typed payloads. It is modeled after the W3C ClipboardItem class. Each ClipboardItem carries one or more MIME-typed payloads that represent the same conceptual clipboard entry, such as both plain-text and HTML representations of a selection.

CommandLine class overview

The CommandLine class manipulates command line arguments for your app that Chromium reads. It is only available as a return value of other methods in the Electron API and is not directly exported from the 'electron' module. It is available in the Main process.

contentTracing module overview

The contentTracing module collects tracing data from Chromium to find performance bottlenecks and slow operations. It is a main-process module. It does not include a web interface; recorded traces are viewed using the trace viewer at chrome://tracing in Chrome. The module should not be used until the ready event of the app module is emitted.

Cookies class overview

The Cookies class is used to query and modify a session's cookies. It runs in the main process and is not exported directly from the 'electron' module. Instances are accessed via the cookies property of a Session.

Debugger basic usage example

const { BrowserWindow } = require('electron') const win = new BrowserWindow() try { win.webContents.debugger.attach('1.1') } catch (err) { console.log('Debugger attach failed : ', err) } win.webContents.debugger.on('detach', (event, reason) => { console.log('Debugger detached due to : ', reason) }) win.webContents.debugger.on('message', (event, method, params) => { if (method === 'Network.requestWillBeSent') { if (params.request.url === 'https://www.github.com') { win.webContents.debugger.detach() } } }) win.webContents.debugger.sendCommand('Network.enable') This example demonstrates attaching the debugger, listening for detach and message events, and sending a command to enable Network debugging.

Debugger accessed via webContents

The Debugger instance is accessed through the debugger property of webContents, as in win.webContents.debugger.

Debugger class overview

The Debugger class is an alternate transport for Chrome's remote debugging protocol. It is available in the main process only. It is not exported directly from the 'electron' module but is returned as a value from other methods in the Electron API.

crashReporter basic setup example

const { crashReporter } = require('electron') crashReporter.start({ submitURL: 'https://your-domain.com/url-to-submit' })

crashReporter module overview

The crashReporter module submits crash reports to a remote server. It is available in both main and renderer processes. When used in a renderer process with context isolation enabled, the API call must be placed in a preload script and exposed using the contextBridge API. Electron uses Crashpad to collect and upload crashes.

desktopCapturer module overview

The desktopCapturer module accesses information about media sources that can be used to capture audio and video from the desktop using the navigator.mediaDevices.getUserMedia API. It is available in the main process.

DownloadItem process type

DownloadItem operates in the Main process only.

DownloadItem class overview

DownloadItem is an EventEmitter that represents a download item in Electron. It is used in the 'will-download' event of the Session class and allows users to control the download item. The class is not exported from the 'electron' module; it is only available as a return value of other methods in the Electron API.

dialog module overview

The dialog module displays native system dialogs for opening and saving files, alerting, etc. It is a main process module.

globalShortcut requires app ready event

The globalShortcut module cannot be used before the ready event of the app module is emitted.

globalShortcut works without app focus

The globalShortcut module registers global keyboard shortcuts with the operating system that will work even if the application does not have keyboard focus.

globalShortcut module process type

The globalShortcut module is available in the main process only.

globalShortcut Wayland support via Chromium portal

It is possible to use Chromium's GlobalShortcutsPortal implementation, which allows apps to bind global shortcuts when running within a Wayland session. Enable this by using app.commandLine.appendSwitch('enable-features', 'GlobalShortcutsPortal').

inAppPurchase module process

The inAppPurchase module runs in the Main process only.

inAppPurchase overview

The inAppPurchase module provides in-app purchase functionality for Mac App Store.

LanguageModelUtility class overview

LanguageModelUtility is a class for implementing local AI language models. It runs in the Utility process. The class is marked as experimental.

nativeTheme module overview

The nativeTheme module allows you to read and respond to changes in Chromium's native color theme. It is available in the main process only.

netLog module overview

The netLog module is used for logging network events for a session in the main process. It allows applications to record and analyze network activity.

net module advantages over Node.js HTTP

The net module offers: automatic management of system proxy configuration and support for wpad protocol and proxy pac configuration files; automatic tunneling of HTTPS requests; support for authenticating proxies using basic, digest, NTLM, Kerberos or negotiate authentication schemes; and support for traffic monitoring proxies like Fiddler-like proxies used for access control and monitoring.

net module uses Chromium networking

The net module is a client-side API for issuing HTTP(S) requests using Chromium's native networking library instead of Node.js implementation.

net module available processes

The net module is available in the Main and Utility processes.

powerMonitor module overview

The powerMonitor module monitors power state changes. It is only available in the main process.

powerSaveBlocker module overview

The powerSaveBlocker module is available in the main process and blocks the system from entering low-power (sleep) mode. It allows applications to prevent sleep or display sleep for specific use cases like file downloads, audio playback, or video playback.

process object - main and renderer module

The process object is available in both main and renderer processes. It is an extension of the Node.js process object with additional Electron-specific events, properties, and methods.

ServiceWorkerMain class overview

ServiceWorkerMain is a class representing an instance of a Service Worker for a given scope and script version. It is only available as a return value from other Electron API methods and is not directly exported from the 'electron' module. It runs in the Main process.

screen module process

The screen module is a main-process module only. It cannot be used until the ready event of the app module is emitted.

Physical screen points vs Device-independent pixel points

Screen coordinates used by the screen module are Point structures. Physical screen points are raw hardware pixels on a display. Device-independent pixel (DIP) points are virtualized screen points scaled based on the DPI (dots per inch) of the display.

screen module in renderer process

In the renderer or DevTools, window.screen is a reserved DOM property, so writing let { screen } = require('electron') will not work.

screen module EventEmitter

The screen module is an EventEmitter.

ServiceWorkers class overview

ServiceWorkers is a class available on the Main process. It is not exported from the 'electron' module directly, but is accessed as the serviceWorkers property of a Session instance. It is used to query and receive events from a session's active service workers.

shell module overview

The shell module manages files and URLs using their default applications. It is available in the main process and the renderer process (non-sandboxed only). The shell module cannot function in a sandboxed renderer.

ActivationArguments object structure

The ActivationArguments object is used on Windows only. It contains the following properties: type (string, required) - the type of activation that launched the app, with values 'click', 'action', or 'reply'; arguments (string, required) - the raw activation arguments string from Windows; actionIndex (number, optional) - for 'action' type, the index of the button that was clicked; reply (string, optional) - for 'reply' type, the text the user entered in the reply field; userInputs (Record<string, string>, optional) - a dictionary of all user inputs from the notification.

BluetoothDevice object structure

The BluetoothDevice object contains the following properties: deviceName (string) and deviceId (string).

CPUUsage Object structure

The CPUUsage object contains three properties: percentCPUUsage (number), cumulativeCPUUsage (optional number), and idleWakeupsPerSecond (number). It is returned by the getCPUUsage method.

LanguageModelMessageContent structure

LanguageModelMessageContent object has two properties: type (string) which can be text, image, or audio; and value (ArrayBuffer | string) which holds the actual content.

LanguageModelMessageContent value property

The value property of LanguageModelMessageContent accepts either an ArrayBuffer or a string.

LanguageModelMessageContent type values

The type property of LanguageModelMessageContent can be one of three values: text, image, or audio.

LanguageModelPromptOptions object structure

The LanguageModelPromptOptions object contains the following properties: responseConstraint (Object or RegExp, optional) - a JSON schema object or a RegExp used to constrain the response to match specified constraints; signal (AbortSignal) - a signal for aborting the operation.

ProcessMetric object structure

The ProcessMetric object contains the following fields: pid (Integer, required), type (string, required, one of: Browser, Tab, Utility, Zygote, Sandbox helper, GPU, Pepper Plugin, Pepper Plugin Broker, Unknown), serviceName (string, optional, the non-localized name of the process), name (string, optional, the name of the process, with examples for utility including Audio Service, Content Decryption Module Service, Network Service, Video Capture), cpu (CPUUsage object, required), creationTime (number, required, represented as milliseconds since epoch), memory (MemoryInfo object, required), sandboxed (boolean, optional, macOS and Windows only, indicates whether the process is sandboxed at OS level), integrityLevel (string, optional, Windows only, one of: untrusted, low, medium, high, unknown).

TouchBarButton class overview

TouchBarButton is a class that creates a button in the touch bar for native macOS applications. It is only available as a return value of other methods in the Electron API and is not directly exported from the 'electron' module. It runs in the Main process.

TouchBarGroup class overview

TouchBarGroup is a class that creates a group in the touch bar for native macOS applications. It runs in the main process and is not exported directly from the 'electron' module. It is only available as a return value of other methods in the Electron API.

TouchBarLabel class overview

TouchBarLabel creates a label in the touch bar for native macOS applications. It runs in the main process and is not exported directly from the 'electron' module; it is only available as a return value of other methods in the Electron API.

TouchBarOtherItemsProxy class overview

TouchBarOtherItemsProxy is a class that instantiates a special 'other items proxy' which nests TouchBar elements inherited from Chromium at the space indicated by the proxy. By default, this proxy is added to each TouchBar at the end of the input. This class is only available as a return value of other methods in the Electron API and is not exported directly from the 'electron' module. It runs in the Main process.

TouchBarOtherItemsProxy AppKit reference

TouchBarOtherItemsProxy is based on the AppKit documentation for NSTouchBarItemIdentifierOtherItemsProxy.

TouchBarOtherItemsProxy single instance per TouchBar

Only one instance of TouchBarOtherItemsProxy can be added per TouchBar.

TouchBarPopover class overview

TouchBarPopover creates a popover in the touch bar for native macOS applications. It is available in the Main process only and is not exported directly from the 'electron' module; it is only available as a return value of other methods in the Electron API.

systemPreferences module overview

The systemPreferences module is available in the main and utility processes. It provides access to system preferences and settings. It can be accessed with const { systemPreferences } = require('electron').

TouchBarScrubber constructor options

TouchBarScrubber constructor accepts an options object with the following properties: items (required, ScrubberItem[] array of items to place in the scrubber), select (optional function called when user taps an item that was not the last tapped item, receives selectedIndex integer parameter), highlight (optional function called when user taps any item, receives highlightedIndex integer parameter), selectedStyle (optional string, can be 'background', 'outline', or 'none', defaults to 'none'), overlayStyle (optional string, can be 'background', 'outline', or 'none', defaults to 'none'), showArrowButtons (optional boolean, defaults to false and only shown if items is non-empty), mode (optional string, can be 'fixed' or 'free', defaults to 'free'), continuous (optional boolean, defaults to true).

TouchBarSlider class overview

TouchBarSlider is a class that creates a slider in the touch bar for native macOS applications. It runs in the main process and is not exported from the 'electron' module—it is only available as a return value of other methods in the Electron API.

TouchBarSpacer class overview

TouchBarSpacer is a class that creates a spacer between two items in the touch bar for native macOS applications. It runs in the Main process and is not exported from the 'electron' module; it is only available as a return value of other methods in the Electron API.

Tray class overview

Tray is a class in the main process that adds icons and context menus to the system's notification area. Tray is an EventEmitter. Electron's built-in classes cannot be subclassed in user code.

Give your agent this brain