Skip to content

feat(webview2): Serve virtual hosts on macOS and iOS - #25598

Draft
morning4coffe-dev wants to merge 1 commit into
dev/doti/webview2-bridge-corefrom
dev/doti/webview2-apple-scheme
Draft

morning4coffe-dev wants to merge 1 commit into
dev/doti/webview2-bridge-corefrom
dev/doti/webview2-apple-scheme

Conversation

@morning4coffe-dev

Copy link
Copy Markdown
Member

Part of #25395. Stacked on #25594 (and through it #25593 and #25592): the base branch is dev/doti/webview2-bridge-core, so only this PR's own commit is in the diff. This PR will be retargeted to master once those merge. Work in progress, opened as a draft to show the approach.

WKWebView cannot intercept https requests, so the virtual host (https://0.0.0.1/, what MAUI's BlazorWebView uses) is served through a custom scheme (uno-app) with a WKURLSchemeHandler, and URLs are translated back to https at the Uno boundary using the shared layer from #25594. Replaces the loopback HttpListener workaround.

What it does

  • A scheme handler registered on every WKWebViewConfiguration at creation (macOS: in UNOWebView.m, with callbacks into managed code; iOS: C#). startURLSchemeTask raises WebResourceRequested and completes only when the deferral completes, then answers from WebResourceResponseSnapshot (status, reason, headers, body); a stopped task is guarded.
  • ISupportsCustomSchemeVirtualHosts on both views, so Source, Navigate, NavigationStarting, NavigationCompleted, NewWindowRequested, the request URI, WebMessageReceived.Source and the WebResourceRequested filters show the https form.
  • Document-start scripts (WKUserScript), PostWebMessageAsString/Json, DOMContentLoaded and the chrome.webview page object through the shared bridge, so scripts and messages work on macOS and iOS.
  • Non-virtual https navigations keep the existing header-only WebResourceRequested behavior.

Verification

  • Runtime tests on the macOS Skia desktop head (real WKWebView): 12 of 12 passed in the first run and 21 passed (5 skipped, the existing Win32-only ones) in the second. The new Given_WebView2_VirtualHost tests cover a page and its subresources served with an async deferral, response status and headers, a stopped task while a deferral is pending, chrome.webview.postMessage with a Source under the virtual host, and PostWebMessage* reaching a page listener; the existing document-script and DOMContentLoaded ordering tests pass too.
  • Unit tests for CustomSchemeResourceHandler were added; the macOS ICU libraries must be on the library path to start the unit-test host (DYLD_LIBRARY_PATH=~/.nuget/packages/uno.icu-macos/<version>/runtimes/osx/native), independent of this change.
  • iOS: Uno.UI.Runtime.AppleUIKit builds for net10.0-ios26.0. Not run on a simulator or device.

Not done / open

@github-actions github-actions Bot added platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/documentation platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant