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]: Certain actions in event handlers may crash the app hosting WebView2 #4573

Open
equin0x80 opened this issue May 20, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@equin0x80
Copy link

What happened?

Consider the following code (Windows Forms), handling WebView2's NavigationStarting event:

private void BrwDoc_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
{
e.Cancel = true;
MessageBox.Show("You cannot navigate to " + e.Uri);
}

The intent is to cancel the navigation and show a messsage box to the user.

If you run this code, the entire hosting application will often crash (suddenly closing itself silently, with no error displayed, nor any exception caught in the Visual Studio debugger). It seems more likely to happen if you wait a long time before clicking OK in the message box, or if you switch around between windows, "minimize all", etc., before clicking OK.

Presumably we are not supposed to do long-running work in this event handler, but I don't think it should crash the entire application; and any known crash situations should at least be in the documentation.

By the way, it seems possible to work around the issue by invoking another function in the event handler, like this:
Task.Delay(1).ContinueWith((_) => this.Invoke(() => MyMessageBoxRoutine(e.Uri)));

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

124.0.2478.97

SDK Version

1.0.2478.35

Framework

Winforms

Operating System

Windows 10

OS Version

19045.4412

Repro steps

as described in "What happened" section above.

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

@equin0x80 equin0x80 added the bug Something isn't working label May 20, 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