Repository navigation
feat(webview2): Add document scripts and messaging - #25592
Draft
morning4coffe-dev wants to merge 3 commits into
Draft
morning4coffe-dev wants to merge 3 commits into
morning4coffe-dev wants to merge 3 commits into
Conversation
Implement AddScriptToExecuteOnDocumentCreatedAsync, RemoveScriptToExecuteOnDocumentCreated, PostWebMessageAsString/Json, DOMContentLoaded and WebMessageReceivedEventArgs.Source on CoreWebView2 behind optional native capabilities. Scripts added before the native WebView exists are queued and registered ahead of its first navigation. Platforms without the capabilities keep the generated stub behavior.
Forward document-created scripts, PostWebMessage, DOMContentLoaded and the web message source to the WebView2 COM interfaces.
Add unit tests using a fake native WebView, Win32/WinUI runtime tests, and document the new members with a per-platform matrix.
This was referenced Oct 20, 2026
Contributor
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-25592/docs/index.html |
| [TestInitialize] | ||
| public void Initialize() | ||
| { | ||
| _contentFolder = Path.Combine(Path.GetTempPath(), "UnoWebView2DocumentScripts", Guid.NewGuid().ToString("N")); |
|
|
||
| private void Navigate(WebView2 webView, string fileName, string html) | ||
| { | ||
| File.WriteAllText(Path.Combine(_contentFolder, fileName), html); |
Comment on lines
+206
to
+209
| catch (Exception e) | ||
| { | ||
| pending.Completion.TrySetException(e); | ||
| } |
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Contributor
|
The build 240312 found UI Test snapshots differences: Details
|
This was referenced Oct 20, 2026
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
CoreWebView2members that were[NotImplemented]on every platform:AddScriptToExecuteOnDocumentCreatedAsync/RemoveScriptToExecuteOnDocumentCreatedPostWebMessageAsString/PostWebMessageAsJsonDOMContentLoadedevent (and its args class)CoreWebView2WebMessageReceivedEventArgs.Sourcethrough three new internal capability interfaces (
ISupportsDocumentCreatedScripts,ISupportsPostWebMessage,ISupportsDOMContentLoaded) next to the existing ones, soINativeWebViewdoes not change. A platform without a capability behaves as before (the generated stubs'NotImplementedExceptionor not-implemented report). Scripts added before the native view exists are queued and registered before its first navigation.Win32 implements all three by forwarding to the real WebView2 (
AddScriptToExecuteOnDocumentCreated,PostWebMessage*,add_DOMContentLoaded,get_Source). Other platforms are not changed here; a follow-up adds achrome.webviewbridge for the WebKit/Android/X11 hosts.Verification
DYLD_LIBRARY_PATH=~/.nuget/packages/uno.icu-macos/<version>/runtimes/osx/native), independent of this change.SamplesApp(desktop head, which builds the Win32, macOS and X11 runtimes and the runtime tests),Uno.UI.Runtime.AndroidandUno.UI.Runtime.AppleUIKitbuild.Given_WebView2_DocumentScripts, SkiaWin32 and NativeWinUI) compile but were not executed, and nothing ran on X11, macOS, Android or iOS. The Win32 behaviour relies on this PR's CI.Notes
DOMContentLoaded.NavigationIduses Uno's own navigation counter (the oneNavigationStarting/NavigationCompletedreport), not WebView2's native id.NotImplementedExceptiononce the view is created; previously it threw synchronously.