Repository navigation
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The cleanup lifecycle is correctly scoped and covered by targeted runtime tests.
Review effort: Balanced
Findings: None
What changed in this PR
Removes orphaned WebView2 iframes after garbage collection while preserving them across unload/reload cycles.
Changes:
- Adds opt-in DOM cleanup through a finalizer sentinel.
- Enables cleanup for WebView2-created iframes.
- Adds WebAssembly runtime coverage for collection and reload behavior.
Review: No issues identified.
| File | Description |
|---|---|
BrowserHtmlElement.cs |
Implements deferred DOM removal. |
Given_WebView2.uno.cs |
Tests collection and reload behavior. |
BrowserWebViewProvider.cs |
Enables collection cleanup for iframes. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24841/wasm-skia-net9/index.html |
|
The build 236600 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
|
@Mergifyio backport servicing/6.8 |
✅ Backports have been createdDetails
Cherry-pick of b17a85a has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
…r-24841 fix(wasm): Remove WebView2 iframe once it is collected (backport #24841)
GitHub Issue: related to unoplatform/kahua-private#547
PR Type:
🐞 Bugfix
What changed? 🚀
On Skia WebAssembly, every
WebView2leaves its<iframe>in the DOM for the rest of the session.BrowserWebViewProvidercreates the iframe withBrowserHtmlElement.CreateHtmlElement("iframe"), nothing ever disposes it, and native-element hosting only hides elements when they are detached. The hidden iframes keep their loaded documents alive. After a 700-page SamplesApp walk, 31 hidden iframes held about 510 MiB. Chrome keeps cross-site iframes in separate renderer processes; Safari keeps them in the tab's own process.This PR removes the iframe once its
WebView2is garbage collected, and keeps it across unload and reload while the control is still referenced. That matches WinUI (controls/dev/WebView2/WebView2.cpp):OnUnloadedonly hides and disconnects the browser, and onlyClose()or the destructor close it. It also follows the Skia macOS convention, where~MacOSNativeElementreleases the native peer.BrowserHtmlElementgets an internalRemoveFromDomWhenCollected(). A private sentinel, referenced only by the element, carries the finalizer; it removes the element on the UI thread at idle priority. An explicitDispose()cancels it.Dispose()contract.BrowserWebViewProvideropts in the iframe it creates.There are no public API changes.
Validation
Given_WebView2.When_Collected_Then_Native_Iframe_Is_RemovedandWhen_Unloaded_While_Referenced_Then_Native_Iframe_Is_Keptpass. With only the provider's opt-in line removed, the collection test fails at the DOM check while theWebView2itself is collected. The reload test passes either way; it guards against removing the iframe too early and checks that the navigated document survives.Uno.UI,Uno.UI.Runtime.Skia.WebAssembly.BrowserandUno.UI.RuntimeTests.Skiacompile fornet10.0with analyzers, code-style enforcement and warnings as errors.net11.0was not built locally.Not in this PR
WebView2.Close()is still a generated[NotImplemented]stub, so release depends on garbage collection. Implementing it would give apps a deterministic release.MediaPlayerElementreleases its<video>element from its own finalizer, directly instead of on the UI thread. It could move to the same mechanism.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code