pub fn VscodeWebviewSchemeHandler<R: Runtime>(
AppHandle: &AppHandle<R>,
Request: &Request<Vec<u8>>,
) -> Response<Vec<u8>>Expand description
Custom URI scheme handler for vscode-webview:// requests.
VS Code’s WebviewElement (used by every extension webview - Roo
Code, Claude, GitLens, custom-editor providers) wraps the inner
extension HTML in an <iframe> whose src is
vscode-webview://<authority>/index.html?.... The <authority> is
a per-instance random base32 string. The authority is irrelevant to
the bytes served - all that matters is the path component, which
always resolves under
vs/workbench/contrib/webview/browser/pre/.
In stock Electron VS Code, app.protocol.registerStreamProtocol( 'vscode-webview', ...) serves this directory. Under Tauri 2.x +
WKWebView, register_asynchronous_uri_scheme_protocol("vscode-webview", ...) installs an equivalent WKURLSchemeHandler. Without this handler,
every extension that uses webviewView / WebviewPanel /
CustomEditor lands the inner iframe at a vscode-webview://...
URL the WKWebView can’t resolve, the iframe stays blank, and the
extension surface is dead.
Three resources live under pre/:
index.html- the webview shell that bridgespostMessagebetween workbench host and inner extension HTMLservice-worker.js- registered byindex.htmlto interceptvscode-webview-resourcerequests for extension-shipped assetsfake.html- sandbox stub used as a placeholder before extension HTML arrives via postMessage
Anything else (querystrings, extra path segments, GUID-like
authorities) is silently dropped; the extension’s actual content
gets piped in via the swMessage channel after index.html boots,
not through this scheme handler.
§Parameters
AppHandle: Tauri AppHandle for resolving the embedded asset resolver and the dev-modeStatic/Application/filesystem fallback (same chain asVscodeFileSchemeHandler).Request: The incoming request - typically aGETfor one of the three pre-baked files.
§Returns
A Response<Vec<u8>> carrying:
200 OKwith the file bytes + correct MIME (text/html/application/javascript) when found, or404 Not Foundwhen the resolved path falls outside thepre/directory or the asset isn’t shipped.
CORS headers are permissive (*) to match the workbench host’s
vscode-webview-resource: traffic, which round-trips through the
service worker registered by index.html.