WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: Certain actions in event handlers may crash the app hosting WebView2

Open equin0x80 opened this issue 1 year ago • 1 comments

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 avatar May 20 '24 18:05 equin0x80

Any progress? The issue is still occurring since I reported this 10 months ago.

equin0x80 avatar Mar 18 '25 10:03 equin0x80

My year-old issue was assigned to somebody who is now "ghost" (GitHub deleted user). @victorhuangwq

equin0x80 avatar Jul 23 '25 23:07 equin0x80