MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Problem/Bug]: Web application frozen after closing container form while setting up a new window
@david-risney is already working on this.
Since Sep 26, 2024.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
Our WinForms WebView2 application can show a companion form that essentially functions as a simple web browser: it has tabs and toolbar controls docked at the top that manipulate one or more WebView2 controls in a lower content area. window.open calls in the main web application are redirected into new tabs in this form using a NewWindowRequested handler, which sets args.Handled = true, takes a deferral, creates another WebView2 control on the form, calls EnsureWebView2Async, awaits adding one or more preload scripts to the new CoreWebView2, and then passes it back via args.NewWindow.
While stress testing this behavior by quickly adding many tabs and then closing the form, we found it was possible for the main application's WebView2 control to end up completely unresponsive. The underlying problem seems to be that if the container form closes during the asynchronous execution of AddScriptToExecuteOnDocumentCreatedAsync, the Task returned by that call remains in a WaitingForActivation state indefinitely and the outer using statement holding the deferral never completes.
Obviously, we can easily work around this by blocking or delaying the form's closing during this critical period, but I wanted to post this to see if the behavior and workaround are expected.
Repro:
WebView2LostDeferral.zip
Importance
Low. My app is not very affected, or this only affects development.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
128.0.2739.79
SDK Version
1.0.2739.15
Framework
Winforms
Operating System
Windows 11
OS Version
10.0.22631
Repro steps
In the attached repro:
- Launch the main application and let bing.com load
- Click around Bing to confirm that you can interact with the web application
- Click the "Show Form" button to launch a new floating window to bing.com, which will immediately close
- Try clicking around the Bing site again; you can no longer interact with the main application's WebView2 control
- Click "Show Form" again and see that nothing happens - ExecuteScriptAsync is also blocked
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.