From 5f630c7de7e3b1632f3f3716f1e609ef9e0703d7 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Sun, 18 Jan 2026 09:52:20 +0100 Subject: [PATCH] fix: try clearing `InspectableWebContents` delegate earlier (#49423) fix: try clearing InspectableWebContents delegate earlier Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- shell/browser/api/electron_api_web_contents.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index b9d97cfff3..08616fb7cf 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1037,6 +1037,9 @@ void WebContents::InitWithWebContents( } WebContents::~WebContents() { + if (inspectable_web_contents_) + inspectable_web_contents_->GetView()->SetDelegate(nullptr); + if (owner_window_) { owner_window_->RemoveBackgroundThrottlingSource(this); } @@ -1051,8 +1054,6 @@ WebContents::~WebContents() { return; } - inspectable_web_contents_->GetView()->SetDelegate(nullptr); - // This event is only for internal use, which is emitted when WebContents is // being destroyed. Emit("will-destroy"); @@ -2189,8 +2190,8 @@ void WebContents::DevToolsOpened() { // Inherit owner window in devtools when it doesn't have one. auto* devtools = inspectable_web_contents_->GetDevToolsWebContents(); bool has_window = devtools->GetUserData(NativeWindowRelay::UserDataKey()); - if (owner_window_ && !has_window) { - DCHECK(!owner_window_.WasInvalidated()); + if (owner_window() && !has_window) { + CHECK(!owner_window_.WasInvalidated()); DCHECK_EQ(handle->owner_window(), nullptr); handle->SetOwnerWindow(devtools, owner_window()); }