Protocol

external interface Protocol(source)

Functions

Link copied to clipboard
abstract external fun getSource(scheme: String): ProtocolSource?

The source registered for scheme with protocol.registerSource, or null.

Link copied to clipboard
abstract external fun handle(scheme: String, handler: (GlobalRequest) -> Any)

Register a protocol handler for scheme. Requests made to URLs with this scheme will delegate to this handler to determine what response should be sent.

Link copied to clipboard
abstract external fun isProtocolHandled(scheme: String): Boolean

Whether scheme already has a handler or a source.

Link copied to clipboard
abstract external fun registerSchemesAsPrivileged(customSchemes: ReadonlyArray<CustomScheme>)

Registers the scheme as standard, secure, bypasses content security policy for resources, allows registering ServiceWorker, supports fetch API, streaming video/audio, and V8 code cache. Specify a privilege with the value of true to enable the capability.

Link copied to clipboard
abstract external fun registerSource(scheme: String, source: ProtocolSource)

Serves scheme from directories on disk without a JavaScript handler. Each request is matched against routes (a route with a host wins over one without, then the longest path prefix wins), the rest of the URL's path is resolved inside that route's root, and the file is streamed to the requester the way file: URLs are, including from asar archives, with Content-Type taken from the file extension. A path that resolves outside root, a missing file, a request that matches no route, or a method other than GET/HEAD fails with net::ERR_FILE_NOT_FOUND. A URL whose path ends in / serves the route's index file.

Link copied to clipboard
abstract external fun unhandle(scheme: String)

Removes a protocol handler registered with protocol.handle or a source registered with protocol.registerSource.