Skip to content

feat(webview): Implement CoreWebView2Environment and CoreWebView2Profile on Skia Win32 (backport #24062) - #24249

Merged
kazo0 merged 10 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-24062
Aug 28, 2026
Merged

kazo0 merged 10 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-24062

Conversation

@mergify

@mergify mergify Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: tracked internally

PR Type:

✨ Feature

What changed? 🚀

CoreWebView2Environment and CoreWebView2Profile were whole-type [Uno.NotImplemented] stubs. They are now
implemented on the Skia Windows head:

Vertical Members
Environment statics GetAvailableBrowserVersionString(), GetAvailableBrowserVersionString(string), CompareBrowserVersionString(string, string)
Profile CoreWebView2.Profile; ClearBrowsingDataAsync() / (kinds) / (kinds, start, end), ProfileName, ProfilePath, IsInPrivateModeEnabled, DefaultDownloadFolderPath, PreferredColorScheme
Environment + diagnostics CoreWebView2.Environment; BrowserVersionString, UserDataFolder, FailureReportFolderPath, GetProcessInfos(); CoreWebView2.BrowserProcessId

Every other target keeps throwing exactly the NotImplementedException it threw before, with the same
type/member strings, so the aka.platform.uno/notimplemented#m= telemetry keys are unchanged.

Design

Two seams, because the members have two different lifetimes:

  • Statics must answer "is a browser installed?" before any WebView2 exists, so they cannot ride
    INativeWebView. They resolve through an owner-less ApiExtensibility extension
    (ICoreWebView2EnvironmentStaticsExtension). The existing WebView registration uses the typed-owner
    overload, which throws on a mismatched owner, so reusing it was not an option.
  • Instance members are bound to a live native view and resolve through three opt-in capability interfaces
    on INativeWebView, next to the existing ISupportsVirtualHostMapping / ISupportsWebResourceRequested.

The capabilities are split three ways rather than bundled because the split is the portability
documentation: data clearing has a real analogue on every head (WKWebsiteDataStore.removeData,
WebKitWebsiteDataManager, Android WebStorage), profile metadata maps partially, and multi-process
diagnostics is Chromium-only. A macOS implementer appends one interface to MacOSNativeWebView and writes one
method — nothing in Uno.UI changes.

The façades hold the owning CoreWebView2, never the native view, and re-resolve on every access:
_nativeWebView is assigned in OnOwnerApplyTemplate and reassigned on every re-template. The async path
re-resolves after its await too, because _nativeWebViewInitializedTcs is never reset, so
EnsureNativeWebViewAsync() stays completed even after re-templating into a template with no native view.

ClearBrowsingDataAsync throws when the native view is absent rather than following the graceful in-memory
fallback used three lines away by SetVirtualHostNameToFolderMapping. A host mapping that quietly buffers is
harmless; a data-clearing call that quietly resolves without clearing is a privacy defect.

Reviewer notes — things not visible in the diff

  • The sync generator could not be run locally. dotnet restore on
    build/filters/Uno.UI-top-projects-for-sync-gen.slnf fails with NETSDK1147, because the wasm-tools
    workload is not installed on the dev machine. The Generated/ edits were instead
    verified against the generator's own rules — type guard flipped to #if false || false || false || false || false || false, each removed member replaced in place by // Skipping already declared property {Name}
    or // Skipping already declared method {fully-qualified signature}, all // Forced skipping of method
    lines untouched — and cross-checked against CoreWebView2Settings.cs, which the generator authored in the
    same shape. The new comments sit alongside pre-existing generator-authored ones in the same files with
    identical formatting. winappsdk-sync-check is the real gate here.

  • Same cause: Uno.UI.netcoremobile was not compile-verified locally. Everything else was, on both
    TFM bands with analyzers enabled: Uno.UI.Skia, Uno.UI.Reference, Uno.UI.Wasm,
    Uno.UI.Runtime.Skia.Win32, Uno.UI.RuntimeTests and SamplesApp all build clean at net9.0 and net10.0.
    The new Uno.UI files are unguarded (matching CoreWebView2Settings.cs) and reference only generated enums
    that exist on all six platform slots, so the mobile variant should be safe too — but CI is the check.

    Note the net9.0 split: WebView2Aot is only referenced from net10.0, so the Win32 statics registration is
    behind #if NET10_0_OR_GREATER and the whole feature stays NotImplemented on net9.0. That guard becomes
    vacuously true once net9 is dropped (feature/breakingchanges already has NetPrevious=net10.0), and can
    be removed then.

  • ProfileName is always empty on Windows. Not a marshalling bug: ProfilePath correctly returns
    …\LocalState\WebView2\EBWebView\Default and DefaultDownloadFolderPath returns the user's Downloads
    folder. It is empty because the controller is created without ICoreWebView2ControllerOptions, so no profile
    name is ever requested. The test asserts the true contract and the doc explains it; making it non-empty means
    passing controller options, which changes on-disk profile layout and deserves its own decision.

  • CompareBrowserVersionString(null, …) throws ArgumentNullException where the WebView2 stack throws
    ArgumentException. ArgumentNullException derives from ArgumentException, so a catch (ArgumentException)
    written against Windows still works — the parity direction that matters holds. The explicit guard also avoids
    handing a null pointer to a native export whose null behaviour is unverified.

  • The type-level [Uno.NotImplemented] attribute is gone from CoreWebView2Environment,
    CoreWebView2Profile and CoreWebView2ProcessInfo, which changes IDE/analyzer surfacing for them. Members
    that remain unimplemented keep their per-member attributes. This is the correct outcome of the types no
    longer being wholly unimplemented, but it is a visible change.

  • When_ClearBrowsingDataAsync_Completes(1) destroys real state in the app's own WebView2 user-data
    folder. It is scoped to LocalState so it is acceptable, but unlike the PreferredColorScheme test there is
    no finally that can restore it.

  • Exception-type parity is derived, not observed end-to-end. Verified: Marshal.GetExceptionForHR(0x80070002)
    is FileNotFoundException; DirectN's ThrowOnError does not use the CLR mapping (it builds a
    Win32Exception); WebView2RuntimeNotFoundException exists only in the WebView2 .NET wrapper and has no
    WinAppSDK/WinRT counterpart, so it is not the parity target. What was not done is running a WinAppSDK app
    to observe it directly. Relatedly, the 0x80070002 observation comes from pointing at a folder with no
    browser; a machine with no runtime installed at all was not available to test.

  • Behaviour change worth noting: the loader probe moved out of Win32NativeAotWebView's static
    constructor into Win32WebView2Loader.Ensure(). The instance path is unchanged, but the new static path
    surfaces a direct DllNotFoundException rather than one wrapped in a TypeInitializationException.

Scope deliberately left out

  • GetAvailableBrowserVersionString(string, CoreWebView2EnvironmentOptions) — CoreWebView2EnvironmentOptions
    is an unbacked stub whose getters throw, so the options cannot be honoured and ignoring them would return a
    wrong answer. Unblocks once that type gets real backing fields, which is also the right time to retire the
    FeatureConfiguration.WebView2.* injection point.
  • CoreWebView2CookieManager / CoreWebView2Cookie. Verified independent of this work:
    ICoreWebView2Profile2.ClearBrowsingData takes only (kinds, handler) and does the work inside the browser
    process, so ClearBrowsingDataAsync(Cookies) never touches the cookie manager. What is therefore still not
    possible: reading cookies, and targeted delete by name/domain/path. Adding it later is one more capability
    interface — no reshaping.
  • CreateAsync / CreateWithOptionsAsync, Profile.CookieManager / .Delete() /
    .IsGeneralAutofillEnabled / .IsPasswordAutosaveEnabled / .PreferredTrackingPreventionLevel, and the
    BrowserProcessExited / ProcessInfosChanged / NewBrowserVersionAvailable / Deleted events.

Pre-existing issues found while working here (not fixed in this PR)

  • get_Source, get_DocumentTitle, get_Uri, get_WebMessageAsJson and the .Request.cs accessors in
    Win32NativeAotWebView all leak caller-owned PWSTRs via a bare .ToString().
  • ExecuteScriptAsync lacks RunContinuationsAsynchronously, the same hazard this PR guards against in
    ClearBrowsingDataAsync.
  • Given_WebView2's SkiaWin32 exclusion predates the WebView2Aot backend. This PR demonstrates a live
    WebView2 runs fine under the runtime-test harness on Skia Win32, so that exclusion now looks stale.

PR Checklist ✅

  • 🧪 Added Runtime tests and a manual test sample
  • 📚 Docs have been added/updated
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests

This is an automatic backport of pull request #24062 done by [Mergify](https://mergify.com).

Xiaoy312 and others added 10 commits August 27, 2026 19:04
…PI surface

Replaces the generated NotImplemented stubs for CoreWebView2Environment,
CoreWebView2Profile and CoreWebView2ProcessInfo with hand-written partials, and
adds CoreWebView2.Environment, .Profile and .BrowserProcessId.

The members split across two seams because they have different lifetimes. The
statics answer "which browser is installed" and must work before any WebView
exists, so they resolve through an owner-less ApiExtensibility extension. The
instance members describe a live WebView, so they resolve through opt-in
capability interfaces on INativeWebView, alongside the existing
ISupportsVirtualHostMapping / ISupportsWebResourceRequested.

The capabilities are split three ways rather than bundled, because that split is
the portability documentation: data clearing has a real analogue on every head
(WKWebsiteDataStore, WebKitWebsiteDataManager, Android WebStorage), profile
metadata maps partially, and multi-process diagnostics is Chromium-only. A
second head implements one interface without touching Uno.UI.

The facades hold the owning CoreWebView2 rather than the native view, and
re-resolve on every access: _nativeWebView is assigned in OnOwnerApplyTemplate
and reassigned on every re-template, so a captured reference would go stale.
For the same reason the async path re-resolves after its await, since
EnsureNativeWebViewAsync stays completed across re-templating.

Behavior on every platform is unchanged: with nothing registered, each member
throws the same NotImplementedException as the deleted stubs, with the same
type/member strings so the telemetry key is preserved. ClearBrowsingDataAsync
deliberately throws rather than following the graceful in-memory fallback used
by SetVirtualHostNameToFolderMapping - a host mapping that quietly buffers is
harmless, a data-clearing call that quietly does nothing is a privacy defect.

GetAvailableBrowserVersionString(string, CoreWebView2EnvironmentOptions) stays
NotImplemented: CoreWebView2EnvironmentOptions is itself an unbacked stub whose
getters throw, so the options could not be honored, and ignoring them would
return a confidently wrong answer.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 361a3c9)
… Win32

Backs the new API surface on the WebView2Aot backend: the statics through the
WebView2Loader.dll exports, and the instance members through ICoreWebView2Profile2
and ICoreWebView2Environment11.

The loader probe moves out of Win32NativeAotWebView's static constructor into
Win32WebView2Loader.Ensure(), because the statics must be able to load it with no
WebView ever created. It uses an explicit lock rather than a static constructor
or Lazy: a type initializer caches its failure, so the first DllNotFoundException
would be wrapped in a TypeInitializationException and replayed for the rest of
the process instead of reporting the real error on each attempt.

Win32CoreWebView2EnvironmentStaticsExtension deliberately holds no reference to
Win32NativeAotWebView, so a missing runtime stays a per-call failure rather than
becoming a startup crash for every Win32 app.

Failed HRESULTs from the two statics go through Marshal.ThrowExceptionForHR
rather than DirectN's ThrowOnError. The exception type is part of the contract
here, since these members are how an app detects a missing runtime: the CLR
mapping turns ERROR_FILE_NOT_FOUND into FileNotFoundException, which is what the
WinRT surface Uno mirrors produces. ThrowOnError raises a Win32Exception, which
would silently break a `catch (FileNotFoundException)` written against Windows.
(The WebView2 .NET wrapper used by WinForms/WPF instead raises its own
WebView2RuntimeNotFoundException, but that type is not part of the WinAppSDK
surface and has no Uno counterpart.)

The interfaces are hard-cast: the core WebView is already obtained as
ICoreWebView2_22, which is newer than every interface used here, so any runtime
able to create the WebView at all satisfies them and a version-fallback ladder
would be dead code.

ClearBrowsingDataAsync completes on a TaskCompletionSource created with
RunContinuationsAsynchronously, because the native handler runs while the
WebView2 message loop is being pumped and continuations after clearing routinely
call straight back into the WebView.

The registration is guarded to net10.0 and later: WebView2Aot is only referenced
from net10.0, and on net9.0 the WebView runs on the Microsoft.Web.WebView2
backend, where these members stay NotImplemented.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 53435cf)
…rofile

Given_WebView2 cannot host these: its class-level PlatformCondition excludes
SkiaWin32 and is evaluated in a separate IsIgnored call that is OR'd with the
method-level ones, so no method attribute can opt back in.

Given_CoreWebView2Environment needs no WebView in the tree, which is the point:
these members must answer before one exists. Given_CoreWebView2Profile loads a
real WebView2 and resets WindowContent in a finally.

Several assertions are deliberately weaker than they look:

- ClearBrowsingDataAsync has no cheap positive observable, so the honest ceiling
  is "completes without throwing, within a bounded time". The bound turns a
  native hang into one failed test rather than a stalled run. Note that the
  AllProfile case destroys state in the app's own WebView2 user-data folder and,
  unlike PreferredColorScheme, cannot be restored in a finally.
- GetProcessInfos asserts neither a count nor a set of kinds: renderer, GPU and
  utility processes appear asynchronously, and only the browser process is
  guaranteed once the controller exists.
- ProfileName is asserted non-null rather than non-empty. It is genuinely empty
  on Windows because the controller is created without ICoreWebView2ControllerOptions,
  so no profile name is requested even though ProfilePath resolves to "Default".
- PreferredColorScheme is persisted on-disk profile state shared across the run
  and across restarts, so the original is restored in a finally.

The missing-folder test pins FileNotFoundException, since that type is how an app
detects a missing runtime and is what the WinRT surface Uno mirrors produces.

Restricted to SkiaWin32 rather than also NativeWinUI: the Inconclusive guard
treats a null or empty version as "runtime not installed", so adding the WinAppSDK
head before its null-vs-throw behavior is confirmed would make the parity test
pass vacuously on exactly the head it was added for.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit acc6670)
Covers the statics, the environment and profile of a live WebView2, and the
three ClearBrowsingDataAsync overloads, in two sections so the static half is
usable with no WebView2 present.

Deliberately not gated to non-Windows, unlike WebView2_EnvironmentOptions: these
APIs do exist natively on WinAppSDK, and running the same page on both heads is
the whole parity value. It therefore has to survive targets where every call
throws, so nothing is called from the constructor - every call sits behind a
Click handler that reports the exception type and message.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 4402bef)
Lists the newly supported surface and what other targets do, including two
behaviors that are surprising without explanation: ProfileName is always empty
on Windows, and the support is specific to the default WebView2 backend on
net10.0 and later.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 86aba74)
The note added in 36869f446e conflated two independent things. The statics are
registered in Win32Host under a plain TFM guard, while the backend is chosen
per-control in Win32NativeWebViewProvider.CreateNativeWebView - nothing connects
them. So on net10.0 the statics work whatever UNO_WEBVIEW2_BACKEND says, and only
Environment, Profile and BrowserProcessId depend on the backend, because only
Win32NativeAotWebView carries the capability interfaces.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit d287809)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 6824a04)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit d65ae9c)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 2ea3c48)
The Win32 WebView2 constructor blocks the UI thread in a nested pump while
the environment and controller are created. On a cold CI agent that stall
consumes the whole 1s WaitForLoaded default, so the first tests of the class
timed out waiting on the Border before reaching any assertion.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit ce98cd2)
@github-actions github-actions Bot added area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Aug 27, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@kazo0

kazo0 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 230678 has failed on Uno.UI - CI.

@kazo0
kazo0 enabled auto-merge August 28, 2026 12:38
@kazo0
kazo0 disabled auto-merge August 28, 2026 13:33
@kazo0
kazo0 merged commit 1384289 into release/stable/6.7 Aug 28, 2026
50 checks passed
@kazo0
kazo0 deleted the mergify/bp/release/stable/6.7/pr-24062 branch August 28, 2026 13:33
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 kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants