MicrosoftEdge / MicrosoftEdge/WebView2Feedback

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

Open
#4,573 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Windows Forms NavigationStarting repro in the issue, including the synchronous MessageBox.Show call and the Task.Delay/Invoke workaround. Reproduce it on the listed WebView2 runtime and SDK versions, then investigate what happens when the dialog remains open or windows are switched. Done means the crash conditions and a safe handling approach are identified or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.