You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
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
The text was updated successfully, but these errors were encountered: