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 · all subjects

api/main-process

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

LanguageModelCloneOptions signal property

LanguageModelCloneOptions object has a signal property of type AbortSignal from Node.js globals.

ClipboardItem cannot be subclassed

Electron's built-in ClipboardItem class cannot be subclassed in user code.

clipboardItem.types property

clipboardItem.types is a read-only string[] property containing the MIME types of the data carried by the clipboard entry. For a constructed ClipboardItem, these are the keys passed to the constructor. For an item returned by clipboard.read(), these are the MIME types the platform clipboard currently makes available.

clipboardItem.getType() method

clipboardItem.getType(type) takes a string MIME type and returns Promise<Blob> | Promise<ClipboardBookmark>. The promise resolves to a Blob for most MIME types. The exception is getType('electron application/bookmark'), which resolves to a ClipboardBookmark object. It rejects when the type is not present in clipboardItem.types.

ClipboardItem class overview

ClipboardItem is a class 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. ClipboardItem runs in the Main process.

ClipboardItem constructor signature

new ClipboardItem(items) takes a Record<string, string | ClipboardBookmark | Blob | Promise<Blob | string>> where keys are MIME types and values are payloads. A string is UTF-8 encoded into payload bytes. A Blob supplies raw payload bytes. The custom 'electron application/bookmark' format accepts a ClipboardBookmark object. Any non-bookmark value may also be a Promise that resolves to a Blob or string, which is awaited when clipboard.write() is called.

clipboard module process and W3C basis

The clipboard module runs only in the main process. It is modeled after the W3C Clipboard API. The clipboard.read() method returns a Promise that resolves with a list of ClipboardItem objects, and clipboard.write() accepts an array of ClipboardItem instances that map MIME types to Blob payloads.

clipboard.readText() method

clipboard.readText() returns Promise<string>. It resolves with the content of the clipboard as plain text. It is modeled after the W3C navigator.clipboard.readText API.

clipboard.writeText(text) method

clipboard.writeText(text) takes a string parameter. It returns Promise<void> that resolves once the text has been written to the clipboard. It is modeled after the W3C navigator.clipboard.writeText API.

clipboard.read() method

clipboard.read() returns Promise<ClipboardItem[]>. It resolves with an array of ClipboardItem objects containing the clipboard's contents.

clipboard.write(data) method

clipboard.write(data) takes a data parameter which is an array of ClipboardItem instances constructed via new ClipboardItem({ [mime]: payload }). It returns Promise<void> that resolves once the data has been written to the clipboard. All entries supplied in a single write() call are committed to the system clipboard atomically.

clipboard.has(mimetype) method

clipboard.has(mimetype) takes a string parameter for the MIME type to check. It returns Promise<boolean> that resolves with true if the clipboard contains data of the specified mimetype, otherwise false. To check for a raw format like public/utf8-plain-text, use the electron application/osclipboard custom format (electron application/osclipboard;format="public/utf8-plain-text").

clipboard.clear() method

clipboard.clear() clears the clipboard content.

received-apns-notification event

The 'received-apns-notification' event is emitted when the app receives a remote notification while running. The event listener receives two parameters: event (Event object) and userInfo (Record<String, any>). This event is macOS only.

pushNotifications.registerForAPNSNotifications() macOS

Registers the app with Apple Push Notification service (APNS) to receive Badge, Sound, and Alert notifications. Returns a Promise that resolves with the APNS device token string on successful registration, or rejects with an error message on failure. This method is macOS only.

pushNotifications.unregisterForAPNSNotifications() macOS

Unregisters the app from notifications received from APNS. Apps unregistered through this method can always reregister. This method is macOS only.

pushNotifications example usage

Example of registering for APNS notifications and handling received notifications: ```js const { pushNotifications, Notification } = require('electron') pushNotifications.registerForAPNSNotifications().then((token) => { // forward token to your remote notification server }) pushNotifications.on('received-apns-notification', (event, userInfo) => { // generate a new Notification object with the relevant userInfo fields }) ```

ses.setPreloads() is deprecated, use registerPreloadScript

The ses.setPreloads() method is deprecated. It accepts preloads as a string array of absolute paths to preload scripts and adds scripts that will be executed on all web contents associated with this session just before normal preload scripts run. Use the new ses.registerPreloadScript API instead.

ses.unregisterPreloadScript() removes preload script by ID

The ses.unregisterPreloadScript(id) method accepts an id string (preload script ID) and unregisters the script.

ses.getPreloadScripts() returns array of registered preload scripts

The ses.getPreloadScripts() method returns PreloadScript[] - an array of paths to preload scripts that have been registered.

ses.createInterruptedDownload() parameters and behavior

The ses.createInterruptedDownload() method accepts an options object with the following properties: path (string, required) - absolute path of the download; urlChain (string[], required) - complete URL chain for the download; mimeType (string, optional); offset (Integer, required) - start range for the download; length (Integer, required) - total length of the download; lastModified (string, optional) - Last-Modified header value; eTag (string, optional) - ETag header value; startTime (Double, optional) - time when download was started in number of seconds since UNIX epoch. This method allows resuming cancelled or interrupted downloads from a previous Session and generates a DownloadItem accessible via the will-download event. The DownloadItem will not have any WebContents associated with it and the initial state will be interrupted. The download starts only when the resume API is called on the DownloadItem.

ses.registerPreloadScript() registers preload scripts by context type

The ses.registerPreloadScript(script) method registers a preload script that will be executed in its associated context type in this session. For frame contexts, this will run prior to any preload defined in the web preferences of a WebContents. It accepts a PreloadScriptRegistration object and returns a string - the ID of the registered preload script.

Give your agent this brain