From 3ca11a5e00862718e1e41e21d03b7e2e04f689cb Mon Sep 17 00:00:00 2001 From: Lawrence Chen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 10 Mar 2026 21:12:18 -0700 Subject: [PATCH] Keep off-window local hosts from stealing devtools view --- Sources/Panels/BrowserPanelView.swift | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sources/Panels/BrowserPanelView.swift b/Sources/Panels/BrowserPanelView.swift index 16aeed0f..1b962264 100644 --- a/Sources/Panels/BrowserPanelView.swift +++ b/Sources/Panels/BrowserPanelView.swift @@ -4486,6 +4486,34 @@ struct WebViewRepresentable: NSViewRepresentable { ) } + let shouldPreserveExistingExternalLocalHost = + host.window == nil && + webView.superview != nil && + webView.superview !== slotView + if shouldPreserveExistingExternalLocalHost { + // Split zoom can instantiate a replacement local host before it joins a window. + // Never let that off-window host steal the live page + inspector hierarchy away + // from the currently visible local host. + host.setLocalInlineSlotHidden(true) + coordinator.lastPortalHostId = nil + coordinator.lastSynchronizedHostGeometryRevision = 0 +#if DEBUG + dlog( + "browser.localHost.reparent.skip web=\(Self.objectID(webView)) " + + "reason=offWindowReplacementHost super=\(Self.objectID(webView.superview)) " + + "host=\(Self.objectID(host)) slot=\(Self.objectID(slotView))" + ) + Self.logDevToolsState( + panel, + event: "localHost.skip", + generation: coordinator.attachGeneration, + retryCount: 0, + details: Self.attachContext(webView: webView, host: host) + ) +#endif + return false + } + if webView.superview !== slotView { if let sourceSuperview = webView.superview { Self.moveWebKitRelatedSubviewsIntoHostIfNeeded(