Use this file to discover all available pages before exploring further.
Custom protocols let you handle URL schemes such as app:// or api:// directly inside your Node.js process without binding to a network port or running an HTTP server. When the webview navigates to a custom-protocol URL, WebviewJS calls your handler with a standard Fetch API Request object and expects a standard Response in return. Because the interface matches the Web Fetch API, any Fetch-compatible router — including Hono, itty-router, or plain handler functions — works without an adapter. Custom protocols are also the correct approach on Windows, where file: URLs do not support the IPC channel.
Call win.registerProtocol(name, handler) on a BrowserWindowbefore calling win.createWebview(). Registrations are locked in at webview creation time; adding a scheme after that point has no effect on an existing webview.
Always normalize and verify the resolved file path before passing it to the file system. Without the relative(root, filePath).startsWith('..') check, a crafted URL like app://localhost/../../etc/passwd could read arbitrary files from the host machine.
Because the handler receives a standard Request and returns a standard Response, you can pass router.fetch directly as the protocol handler. No adapter or HTTP server is needed.
Hono’s middleware, validation, and routing all work exactly as they would in an edge-function deployment — c.req.path, c.req.query(), c.req.json(), etc. are all available.
The modern Response-based style is recommended for new code because it is compatible with Fetch-API routers and easier to test in isolation. The legacy object form remains for backward compatibility.
Protocol registrations are fixed at createWebview() time
Once win.createWebview() has been called, the set of registered protocol handlers for that webview is frozen. Calling win.registerProtocol() after createWebview() will not affect the already-created webview instance. Always register all schemes before creating the webview.
// ✅ Correct orderwin.registerProtocol('app', handler);win.registerProtocol('api', apiHandler);const webview = win.createWebview({ url: 'app://localhost/' });// ❌ Too late — this registration is ignored by the webview abovewin.registerProtocol('assets', assetsHandler);