Repository navigation
feat(webview2): Create detached CoreWebView2Environment - #25593
morning4coffe-dev wants to merge 3 commits into
Conversation
Implement CreateAsync/CreateWithOptionsAsync, CreateWebResourceResponse with a managed response, CoreWebView2EnvironmentOptions as stored data, EnsureCoreWebView2Async(environment) and stored settings flags. Win32 translates managed responses into native ones.
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-25593/docs/index.html |
| [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.Skia)] | ||
| public async Task When_CreateWithOptionsAsync_Records_User_Data_Folder() | ||
| { | ||
| var userDataFolder = Path.Combine(Path.GetTempPath(), "uno-webview2-data-" + Guid.NewGuid().ToString("N")); |
| [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.SkiaWin32)] | ||
| public async Task When_CreateWithOptionsAsync_Missing_Browser_Folder_Throws() | ||
| { | ||
| var missingFolder = Path.Combine(Path.GetTempPath(), "uno-webview2-missing-" + Guid.NewGuid().ToString("N")); |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 240314 found UI Test snapshots differences: Details
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-25593/docs/index.html |
|
The build 246704 found UI Test snapshots differences: Details
|
Part of #25395 (the WebView2 members that
BlazorWebViewdepends on). Carved out of the older draft #23754 as a small change on top of current master.What this adds
MAUI's
BlazorWebView(WinUI handler) starts withCoreWebView2Environment.CreateWithOptionsAsync(...), uses the resulting environment only to callCreateWebResourceResponse(...), and then calls the parameterlessEnsureCoreWebView2Async(). Both environment members threwNotImplementedExceptionon every platform, which faults the handler's start task silently.CoreWebView2Environment.CreateAsync()/CreateWithOptionsAsync(...): return a detached environment that records the browser folder, user data folder and options. Where the platform can answer (Win32), the browser is probed first so a missing WebView2 runtime fails withFileNotFoundException, as on Windows.UserDataFolder/BrowserVersionStringanswer from the recorded inputs; members that need a live WebView keep throwingNotImplementedException.CoreWebView2Environment.CreateWebResourceResponse(...): returns a platform-neutral managed response (ordered, case-insensitive header list, lenientName: Value\r\nparsing).CoreWebView2EnvironmentOptions: all members are stored as plain data (inert unless a platform reads them).WebView2.EnsureCoreWebView2Async(environment[, controllerOptions]): accepts the environment, soCoreWebView2.Environmentreturns it; the options are ignored by the platforms.CoreWebView2Settings:AreDevToolsEnabled,AreDefaultContextMenusEnabledandIsStatusBarEnabledare stored (platform behavior unchanged; Win32 still reads DevTools fromFeatureConfiguration).WebResourceRequestedaccepts a response that is not a native one by building it with the WebView'sICoreWebView2Environment.CreateWebResourceResponse.Android and Apple still drop managed responses; follow-up PRs add them.
Verification
WebView2can be constructed in the unit-test host) pass on macOS. The unit-test project needs the macOS ICU libraries on the library path to start (DYLD_LIBRARY_PATH=~/.nuget/packages/uno.icu-macos/<version>/runtimes/osx/native), independent of this change.Given_CoreWebView2Environment: 4 passed, 5 skipped (the Win32-only ones).SamplesAppdesktop head builds, which compiles the Win32, macOS and X11 runtimes.Notes
CoreWebView2EnvironmentOptionsfollow the WebView2 documentation from memory and should be double-checked:EnableTrackingPreventiontrue,ReleaseChannelsall four,ChannelSearchKindMostStable;TargetCompatibleBrowserVersiondefaults to an empty string (WebView2 defaults it to the SDK's version).GetHeaderon a response header that is not present throwsArgumentException(believed to match WebView2'sE_INVALIDARG).EnsureCoreWebView2Asyncis ignored (the first one wins).