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]: App hard-crashes if the requesting webview is disposed around the time we assign the new webview to NewWindow #4975

Open
pushkin- opened this issue Dec 6, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@pushkin-
Copy link

pushkin- commented Dec 6, 2024

What happened?

We intercept the NewWindowRequested event and show a window with tabs. If you open a new tab (by middle-clicking a link in the first tab, say), and then quickly close the tab you're on, the app hardcrashes.

It seems that assigning e.NewWindow = newWebView.CoreWebView2 when the requesting tab/webview2 is disposed of leads to this crash

If I dispose of the first webview2 immediately in the NewWindowRequestedHandler, I get this crash:
image

If I dispose of it in a Task (which is more like what's happening in my app), I get this crash:
image

Generally, in my app (though didn't repro in the minimal example yet), I'd get this crash:
image
(oh I think that's the same issue as above just hitting in WebView2 code this time)

It would be nice if WebView2 handled this case for us.
What I'm having to do is grab the sender passed to NewWindowRequestedHandler and right before assigning the new WebView2 that I created to NewWindow, I check if the sender webview2 is disposed. (and also having to close the new tab that was opened to avoid a blank new tab)

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

131.0.2903.70

SDK Version

1.0.2783-prerelease and 1.0.2535.41

Framework

Winforms

Operating System

Windows 11

OS Version

23H@ 22631.4460

Repro steps

  1. download WinForms sample app from webview2
  2. In WebView2Control_CoreWebView2InitializationCompleted, add this.webView2Control.CoreWebView2.NewWindowRequested += (sender, e) => CoreWebView2_NewWindowRequested(sender, e, false);

and below:

	WebView2 _primaryWebView = null;
	private async void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e, bool fromOtherWebView)
	{
		e.Handled = true;
		using (e.GetDeferral())
		{
			Form form = new Form();
			form.Size = new Size(800, 600);
			WebView2 webView = new WebView2();
			await webView.EnsureCoreWebView2Async();
			webView.CoreWebView2.NewWindowRequested += (sender, e) => CoreWebView2_NewWindowRequested(sender, e, true);
			form.Controls.Add(webView);
			form.Visible = true;
			webView.Dock = DockStyle.Fill;

			if (fromOtherWebView)
			{
				await Task.Run(() =>
				{
					_primaryWebView.Dispose(); // dispose requesting window
				});
			}
			else
			{
				// save off the first webview
				_primaryWebView = webView;
			}
			e.NewWindow = webView.CoreWebView2;
		}
	}

then

  1. start app
  2. open devtools and run window.open("https://google.com")
  3. in the Google window, middle click the About link to trigger a new window
  4. observe crash

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

@pushkin- pushkin- added the bug Something isn't working label Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

Hi, @pushkin-!

It seems that your issue contains the word "crash". If you have not already, could you attach a crash dump as a comment?

WV2 crash dumps are located in a subfolder of the app's user data folder (UDF): <UDF>\EBWebView\Crashpad\reports\. By default, the user data folder is created in the app's folder with a name like <App Exe Name>.exe.WebView2. Refer to Crash Diagnostics for more information.

Thank you for your cooperation!

@pushkin- pushkin- changed the title [Problem/Bug]: App hard-crashes if a webview opens another window and we assign NewWindow, but then the opening webview is disposed [Problem/Bug]: App hard-crashes if the requesting webview is disposed around the time we assign the new webview to NewWindow Dec 13, 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