Is your feature request related to a problem? Please describe.
NativeWebView can embed the engine, navigate, run JS, exchange messages, and it raises WebResourceRequested on every platform (including GTK/WPE) — but there's no way to fulfill an intercepted request with app-local bytes, and no custom URI-scheme registration. That makes it impossible to serve a local app bundle offline (an SPA, or a Blazor-/Hybrid-style app). On WKWebView/WebKitGTK/WPE this specifically requires a custom scheme, because those engines can't intercept http:// (as noted in Microsoft's own PhotinoWebViewManager).
Concretely, on GTK the current WebResourceRequested is wired to WebKit's resource-load-started signal, which is observational (can't supply a response body), so it can't serve local content.
Describe the solution you'd like
A small primitive on NativeWebView, mirroring approaches already present in this repo and in Microsoft's shipping stack:
- Register an app origin scheme (default
app://), via the existing *EnvironmentRequested seam (WebKitGTK/WKWebView must register scheme handlers at context/config creation time).
- Respond to an intercepted request with a stream — e.g.
SetResponse(Stream content, int statusCode, string reason, string mimeType, headers) (+ a deferral for async/large assets).
The machinery already exists on two backends — AndroidWebViewAdapter.ShouldInterceptRequest returns a WebResourceResponse, and ICoreWebView2Environment.CreateWebResourceResponse is bound for WebView2 — so this is essentially surfacing that through the unified API and implementing it on GTK (webkit_web_context_register_uri_scheme + webkit_uri_scheme_request_finish) and WPE. Structurally it's a near-1:1 of MAUI's WKWebView IWKUrlSchemeHandler.
Describe alternatives you've considered
NavigateToString + a file:// base URI works for the top document but inherits file:// origin/security limits (fetch/XHR, ES-module CORS, service workers, and the virtual origin SPAs expect).
- Header-only mutation on the current
WebResourceRequested event isn't enough — there's no response body.
- A localhost HTTP server defeats the offline/no-server goal.
Additional context
I put together a design write-up and drafted a potential approach (an illustrative spike — not yet build-wired) that mirrors your existing patterns and Microsoft's shipping code:
Main questions before I take it further:
- Is local-content serving intended / on the roadmap for
NativeWebView?
- Preferred shape — response synthesis on the interception surface, a scheme/virtual-host registration API, or both?
- WebKitGTK vs. WPE as the primary Linux target?
Glad to shape a PR to your preferences.
Is your feature request related to a problem? Please describe.
NativeWebViewcan embed the engine, navigate, run JS, exchange messages, and it raisesWebResourceRequestedon every platform (including GTK/WPE) — but there's no way to fulfill an intercepted request with app-local bytes, and no custom URI-scheme registration. That makes it impossible to serve a local app bundle offline (an SPA, or a Blazor-/Hybrid-style app). On WKWebView/WebKitGTK/WPE this specifically requires a custom scheme, because those engines can't intercepthttp://(as noted in Microsoft's ownPhotinoWebViewManager).Concretely, on GTK the current
WebResourceRequestedis wired to WebKit'sresource-load-startedsignal, which is observational (can't supply a response body), so it can't serve local content.Describe the solution you'd like
A small primitive on
NativeWebView, mirroring approaches already present in this repo and in Microsoft's shipping stack:app://), via the existing*EnvironmentRequestedseam (WebKitGTK/WKWebView must register scheme handlers at context/config creation time).SetResponse(Stream content, int statusCode, string reason, string mimeType, headers)(+ a deferral for async/large assets).The machinery already exists on two backends —
AndroidWebViewAdapter.ShouldInterceptRequestreturns aWebResourceResponse, andICoreWebView2Environment.CreateWebResourceResponseis bound for WebView2 — so this is essentially surfacing that through the unified API and implementing it on GTK (webkit_web_context_register_uri_scheme+webkit_uri_scheme_request_finish) and WPE. Structurally it's a near-1:1 of MAUI's WKWebViewIWKUrlSchemeHandler.Describe alternatives you've considered
NavigateToString+ afile://base URI works for the top document but inheritsfile://origin/security limits (fetch/XHR, ES-module CORS, service workers, and the virtual origin SPAs expect).WebResourceRequestedevent isn't enough — there's no response body.Additional context
I put together a design write-up and drafted a potential approach (an illustrative spike — not yet build-wired) that mirrors your existing patterns and Microsoft's shipping code:
WebViewManager/StaticContentProviderreuse, per-platform interception table, downstream MAUIHybridWebViewHandler/BlazorWebViewHandlerstory): Design: Port Microsoft's BlazorWebView/HybridWebView content-serving model to NativeWebView (enable offline hybrid apps incl. Linux) dcuccia/Avalonia.Controls.WebView#1GtkUriSchemeHandlercallback in yourGtkSignal.TryGetStatestyle, and the one-line wiring intoGtkWebViewAdapter's context-creation path): https://github.com/dcuccia/Avalonia.Controls.WebView/blob/spike/webkitgtk-uri-scheme-serving/docs/design/webkitgtk-uri-scheme-spike.mdMain questions before I take it further:
NativeWebView?Glad to shape a PR to your preferences.