diff --git a/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs b/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs
index 9fecf9e86..42fc0ce36 100644
--- a/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs
+++ b/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs
@@ -670,6 +670,7 @@ namespace CefSharp.Wpf.HwndHost
PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler);
FocusHandler = new FocusHandler();
+ LifeSpanHandler = new NoCloseLifespanHandler();
UseLayoutRounding = true;
}
@@ -753,7 +754,6 @@ namespace CefSharp.Wpf.HwndHost
if (browserSettings.AutoDispose)
{
browserSettings.Dispose();
- browserSettings = null;
}
browserSettings = null;
diff --git a/CefSharp.Wpf.HwndHost/Internals/NoCloseLifespanHandler.cs b/CefSharp.Wpf.HwndHost/Internals/NoCloseLifespanHandler.cs
new file mode 100644
index 000000000..b2a9b7b50
--- /dev/null
+++ b/CefSharp.Wpf.HwndHost/Internals/NoCloseLifespanHandler.cs
@@ -0,0 +1,26 @@
+// Copyright © 2022 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Wpf.HwndHost.Internals
+{
+ ///
+ /// LifeSpanHandler used internally
+ /// - Cancels sending of WM_CLOSE message for main browser
+ /// - Allows popups to close
+ ///
+ public class NoCloseLifespanHandler
+ : CefSharp.Handler.LifeSpanHandler
+ {
+ ///
+ protected override bool DoClose(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ if(browser.IsPopup)
+ {
+ return false;
+ }
+
+ return true;
+ }
+ }
+}