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

protocol/overview

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.

protocol module overview

The protocol module is a main process module for registering custom protocols and intercepting existing protocol requests.

protocol methods available after app ready event

All protocol methods unless specified can only be used after the ready event of the app module is emitted.

protocol with custom partition or session

A protocol is registered to a specific Electron session object. If a partition or session is defined on a browserWindow's webPreferences, that window uses a different session and custom protocols must be registered to that session explicitly using ses.protocol.handle() instead of electron.protocol.XXX.

valid protocol names RFC 3986

According to RFC 3986 section 3.1, scheme names consist of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus (+), period (.), or hyphen (-). Although schemes are case-insensitive, the canonical form is lowercase.

protocol example with file-like protocol

Example implementing a protocol with the same effect as file://: const { app, protocol, net } = require('electron') const path = require('node:path') const url = require('node:url') app.whenReady().then(() => { protocol.handle('atom', (request) => { const filePath = request.url.slice('atom://'.length) return net.fetch(url.pathToFileURL(path.join(__dirname, filePath)).toString()) }) })

protocol with custom session example

Example of registering a protocol to a custom session: const { app, BrowserWindow, net, protocol, session } = require('electron') const path = require('node:path') const url = require('node:url') app.whenReady().then(() => { const partition = 'persist:example' const ses = session.fromPartition(partition) ses.protocol.handle('atom', (request) => { const filePath = request.url.slice('atom://'.length) return net.fetch(url.pathToFileURL(path.resolve(__dirname, filePath)).toString()) }) const mainWindow = new BrowserWindow({ webPreferences: { partition } }) })

Give your agent this brain