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

missing: protocol apis

8 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.register*Protocol methods deprecated, use protocol.handle

The `protocol.register*Protocol` and `protocol.intercept*Protocol` methods (registerBufferProtocol, registerStringProtocol, registerStreamProtocol, registerFileProtocol, registerHttpProtocol, and their intercept variants) have been replaced with `protocol.handle(scheme, handler)`. The new method can either register a new protocol or intercept an existing protocol, and responses can be of any type (Buffer, string, ReadableStream, or Response from net.fetch).

protocol.handle example for Buffer response

Example of using protocol.handle to register a protocol that returns Buffer content: `protocol.handle('some-protocol', () => { return new Response(Buffer.from('<h5>Response</h5>'), { headers: { 'content-type': 'text/html' } }) })`.

protocol.handle example for HTTP redirect

Example of using protocol.handle to redirect to an HTTP URL: `protocol.handle('some-protocol', () => { return net.fetch('https://electronjs.org') })`.

protocol.handle example for file protocol

Example of using protocol.handle to serve a file: `protocol.handle('some-protocol', () => { return net.fetch('file:///path/to/my/file') })`.

protocol.uninterceptProtocol now synchronous

The `protocol.uninterceptProtocol(scheme)` API is now synchronous and no longer accepts an optional callback.

protocol.registerFileProtocol and related methods now synchronous

The following `protocol` APIs are now synchronous and no longer accept an optional callback: `registerFileProtocol`, `registerBufferProtocol`, `registerStringProtocol`, `registerHttpProtocol`, `registerStreamProtocol`, `interceptFileProtocol`, `interceptStringProtocol`, `interceptBufferProtocol`, `interceptHttpProtocol`, `interceptStreamProtocol`. The registered or intercepted protocol does not have effect until navigation happens.

protocol.isProtocolHandled deprecated, use isProtocolRegistered and isProtocolIntercepted

The `protocol.isProtocolHandled(scheme)` API is deprecated. Use `protocol.isProtocolRegistered(scheme)` and `protocol.isProtocolIntercepted(scheme)` instead.

Privileged schemes registration moved to before app ready

In Electron 5, the renderer process APIs `webFrame.registerURLSchemeAsPrivileged` and `webFrame.registerURLSchemeAsBypassingCSP`, as well as the browser process API `protocol.registerStandardSchemes` have been removed. A new API, `protocol.registerSchemesAsPrivileged`, has been added and should be used for registering custom schemes with the required privileges. Custom schemes must be registered before app ready.

Give your agent this brain