Repository navigation
feat: Implement WebView2 NewWindowRequested event - #21775
Conversation
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21775/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21775/docs/index.html |
|
The build 181838 found UI Test snapshots differences: Details
|
There was a problem hiding this comment.
Pull Request Overview
This pull request implements support for the NewWindowRequested event in WebView2 across all Uno Platform targets, enabling applications to intercept and handle requests to open new windows (e.g., links with target="_blank").
Key Changes
- Added
NewWindowRequestedevent handling across WebAssembly, Android, iOS/macOS, Win32, and Skia macOS platforms - Implemented a new
navigatemethod in WebAssembly to improve navigation handling - Added a sample app demonstrating the new window interception functionality
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.UI/ts/Windows/UI/Xaml/Controls/WebView.ts | Added navigate method and NewWindowRequested event handling via window.open override and target="_blank" link interception |
| src/Uno.UI/UI/Xaml/Controls/WebView/Native/iOSmacOS/UnoWKWebView.iOSmacOS.cs | Updated to use null-coalescing for safer URI handling in new window requests |
| src/Uno.UI/UI/Xaml/Controls/WebView/Native/Wasm/NativeWebView.wasm.cs | Added DispatchNewWindowRequested and DispatchWebMessage JSExport methods; updated navigation to use new navigate method |
| src/Uno.UI/UI/Xaml/Controls/WebView/Native/Wasm/NativeWebView.Interop.wasm.cs | Added JSImport for the new navigate method |
| src/Uno.UI/UI/Xaml/Controls/WebView/Native/Android/NativeWebViewWrapper.Android.cs | Enabled multiple windows support and updated WebChromeClient with CoreWebView2 dependency |
| src/Uno.UI/UI/Xaml/Controls/WebView/Native/Android/InternalWebChromeClient.Android.cs | Implemented OnCreateWindow to handle new window requests on Android |
| src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeWebView.cs | Wired up NewWindowRequested event handler for Win32 WebView |
| src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOWebView.m | Implemented native createWebViewWithConfiguration delegate method with C# callback |
| src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOWebView.h | Added function pointer typedef and declarations for new window requested callback |
| src/Uno.UI.Runtime.Skia.MacOS/UI/Xaml/Controls/WebView/MacOSNativeWebViewProvider.cs | Registered the new window requested callback on initialization |
| src/Uno.UI.Runtime.Skia.MacOS/UI/Xaml/Controls/WebView/MacOSNativeWebView.cs | Implemented NewWindowRequestedCallback to handle new window requests |
| src/Uno.UI.Runtime.Skia.MacOS/Native/NativeUno.cs | Added P/Invoke declaration for setting the new window requested callback |
| src/SamplesApp/UITests.Shared/UITests.Shared.projitems | Added WebView2_TargetBlank sample to the project |
| src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/WebView2Tests/WebView2_TargetBlank.xaml.cs | Sample implementation demonstrating new window request handling |
| src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/WebView2Tests/WebView2_TargetBlank.xaml | XAML layout for the new window request sample |
spouliot
left a comment
There was a problem hiding this comment.
Good job! Only a few minor things.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21775/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21775/docs/index.html |
|
The build 182609 found UI Test snapshots differences: Details
|
GitHub Issue: internal
PR Type:
What is the current behavior? 🤔
The
NewWindowRequestedis not supported, it is implemented, but not invoked on any platform.What is the new behavior? 🚀
Zaznam.obrazovky.2025-11-09.v.10.16.04.mov
Added support for Desktop - Windows, macOS, Mobile - iOS, Android and Wasm.
The iOS implementation is not tested, as the WebView2 didn't load at all: #21777
Wasm is limited by: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
Linux is not supported with this PR.
Runtime test is not included due to #20731.
PR Checklist ✅
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.