Skip to content

Commit cac2e0a

Browse files
authored
Merge pull request #2969 from cwensley/curtis/webview2-initialization-exception
Wpf/WinForms: Don't throw an exception in WebView2 when it was aborted
2 parents 9be0b5b + b6ff286 commit cac2e0a

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/Eto.Wpf/Forms/Controls/WebView2Handler.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,23 @@ protected override void OnInitializeComplete()
473473
InitializeAsync();
474474
}
475475

476+
// E_ABORT - reported when initialization is aborted because the control was
477+
// torn down before EnsureCoreWebView2Async completed.
478+
const int E_ABORT = unchecked((int)0x80004004);
479+
476480
void Control_CoreWebView2Ready(object sender, CoreWebView2InitializationCompletedEventArgs e)
477481
{
478482
if (!e.IsSuccess)
479483
{
484+
// When the control is disposed/unloaded before WebView2 finishes initializing
485+
// (e.g. closing a panel or switching the window/viewport layout) the
486+
// initialization is aborted with E_ABORT. This is benign and must not be
487+
// allowed to escape this native callback, since it would surface as an
488+
// unhandled exception on the dispatcher and crash the application.
489+
// https://github.com/MicrosoftEdge/WebView2Feedback/issues/2410
490+
if (Widget.IsDisposed || e.InitializationException?.HResult == E_ABORT)
491+
return;
492+
480493
throw new WebView2InitializationException("Failed to initialize WebView2", e.InitializationException);
481494
}
482495

0 commit comments

Comments
 (0)