Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: Web application frozen after closing container form while setting up a new window #4820

Open
awolbach opened this issue Sep 19, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@awolbach
Copy link

awolbach commented Sep 19, 2024

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:

  1. Launch the main application and let bing.com load
  2. Click around Bing to confirm that you can interact with the web application
  3. Click the "Show Form" button to launch a new floating window to bing.com, which will immediately close
  4. Try clicking around the Bing site again; you can no longer interact with the main application's WebView2 control
  5. 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

@awolbach awolbach added the bug Something isn't working label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants