From b150993d672bb34a16deb244cdfa760f1bba99a3 Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Mon, 12 Sep 2022 11:03:09 +1000 Subject: [PATCH] CefSharp.Dom - Don't Dispose DevToolsContext Disposing of the DevToolsContext is causing problems currently as sending the DevTools protocol messages to the browser is happening after the CefBrowserHost instance has been Disposed. A separate method of disposing of the DevToolsContext will need to be added that does a cleanup without sending the commands. Issue https://github.com/cefsharp/CefSharp.Dom/issues/41 --- .../Partial/ChromiumWebBrowser.Partial.cs | 2 +- CefSharp/WebBrowserExtensions.cs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs index f98ce1bd1..555bb1d24 100644 --- a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs +++ b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs @@ -499,7 +499,7 @@ namespace CefSharp.WinForms ResourceRequestHandlerFactory = null; RenderProcessMessageHandler = null; - this.DisposeDevToolsContext(); + this.FreeDevToolsContext(); } /// diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index 18655551a..243ee88c4 100644 --- a/CefSharp/WebBrowserExtensions.cs +++ b/CefSharp/WebBrowserExtensions.cs @@ -1796,7 +1796,7 @@ namespace CefSharp } /// - /// Dispose of the DevTools Context (if any). Used in conjunction with CefSharp.Puppeteer + /// Dispose of the DevToolsContext (if any). Used in conjunction with CefSharp.Dom /// /// ChromiumWebBrowser instance public static void DisposeDevToolsContext(this IWebBrowserInternal webBrowserInternal) @@ -1810,6 +1810,20 @@ namespace CefSharp webBrowserInternal.DevToolsContext = null; } + /// + /// Set the property to null. Used in conjunction with CefSharp.Dom + /// + /// ChromiumWebBrowser instance + public static void FreeDevToolsContext(this IWebBrowserInternal webBrowserInternal) + { + if (webBrowserInternal == null) + { + return; + } + + webBrowserInternal.DevToolsContext = null; + } + /// /// Function used to encode the params passed to , /// and