MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Uncaught exceptions in WebView2 event handlers don't trigger Application.ThreadException
@champnic is already working on this.
Since Apr 21, 2021.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Description
When initialized with a Source, unhandled exceptions in WebView2 event handlers never trigger Application.ThreadException.
Tested using WebView2 specific NavigationStarting event, and WinForms Control specific KeyDown.
If Source is not set and the WebView2 is uninitialized, KeyDown events on the WebView properly triggers the ThreadException event.
Version
SDK: 1.0.774.44
Runtime: Evergreen 90.0.818.39
Framework: WinForms
OS: Win 10 Version 10.0.19041
Repro Steps
using System;
using System.Windows.Forms;
using Microsoft.Web.WebView2.WinForms;
namespace WinFormsApp1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += ExceptionHandler;
AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;
var form = new Form();
WebView2 webView = new WebView2();
webView.Source = new Uri("http://www.example.org"); // If not set, ExceptionHandler is fired on exception.
webView.Dock = DockStyle.Fill;
webView.KeyDown += ThrowingEventHandler;
//webView.NavigationStarting += ThrowingEventHandler;
form.Controls.Add(webView);
Application.Run(form);
}
static void ThrowingEventHandler(object sender, object eventArgs)
{
System.Diagnostics.Trace.WriteLine("Event fired from " + sender.GetType());
throw new Exception("Test");
}
static void ExceptionHandler(object sender, object args)
{
System.Diagnostics.Trace.WriteLine("Unhandled exception!");
Application.Exit();
}
}
}
Press some key to trigger, eg. F11:
Expected output:
Event fired from Microsoft.Web.WebView2.WinForms.WebView2
Unhandled exception!
Application exits
Actual output:
Event fired from Microsoft.Web.WebView2.WinForms.WebView2
Additional context
I don't know if this is expected behavior, or whether it relates to the interprocess communication more than the actual webview. I tried looking for some documentation regarding this behavior but without luck.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.