app:// directly inside Node.js without starting an HTTP server. The webview loads content by scheme name — app://localhost/index.html, for example — and your handler resolves every request. This is the recommended approach for serving local assets, and it is required on Windows when the page needs to use window.ipc.postMessage(), because IPC does not fire on file: URLs on that platform.
Registering a protocol
Callwin.registerProtocol(scheme, handler) before win.createWebview(). The handler receives a standard Fetch Request and must return a Response (or a Promise<Response>).
Fetch API interface
The protocol handler receives a standard global Fetch APIRequest object and must return a standard Response. This means anything that works with the Fetch API — headers, status codes, streaming bodies — works here too.
Promise, WebviewJS delivers a 500 text/plain response to the webview.
Routing with Hono
Because the handler receives a standardRequest and must return a standard Response, you can pass the request directly to a Hono router. No HTTP server is required — Hono’s fetch method acts as the handler.
Multiple protocols
Register as many schemes as you need before callingcreateWebview(). Each scheme gets its own independent handler.
Protocol registrations are fixed at the moment the webview is created.
Calling
registerProtocol() after createWebview() does not change the
routing for an existing webview.CORS and cache headers
Set response headers when the page makes cross-protocol fetch calls or when you want to control caching behavior.Security
Userelative() to detect path traversal attempts and return a 403 before touching the file system:
Legacy response format
As an alternative to returning aResponse object, your handler can return a plain CustomProtocolResponse object. This format is supported for compatibility but the standard Response API is preferred.
Related pages
- IPC Messaging — send messages between the page and Node.js (requires custom protocol on Windows)
- Webview API reference —
WebviewOptions,registerProtocol, and webview creation