From 2e4c482c21ded83f1defee40aa9115d91bd9539a Mon Sep 17 00:00:00 2001 From: Austin Wang Date: Sun, 15 Mar 2026 18:48:23 -0700 Subject: [PATCH] Fix Google sign-in infinite loading in browser pane (#1493) * Add regression test for Google sign-in popup fallback (#1491) * Fix Google sign-in popup routing regression (#1491) --- Sources/Panels/BrowserPanel.swift | 18 ++++++++++++++---- cmuxTests/CmuxWebViewKeyEquivalentTests.swift | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Sources/Panels/BrowserPanel.swift b/Sources/Panels/BrowserPanel.swift index 833fe93c..73eda80a 100644 --- a/Sources/Panels/BrowserPanel.swift +++ b/Sources/Panels/BrowserPanel.swift @@ -4654,6 +4654,14 @@ func browserNavigationShouldCreatePopup( return navigationType == .other && !isUserNewTab } +func browserNavigationShouldFallbackNilTargetToNewTab( + navigationType: WKNavigationType +) -> Bool { + // Scripted popups rely on WKUIDelegate.createWebViewWith returning a live + // web view so window.opener/postMessage remain intact across OAuth flows. + navigationType != .other +} + private class BrowserNavigationDelegate: NSObject, WKNavigationDelegate { var didFinish: ((WKWebView) -> Void)? var didFailNavigation: ((WKWebView, String) -> Void)? @@ -4891,11 +4899,13 @@ private class BrowserNavigationDelegate: NSObject, WKNavigationDelegate { return } - // Catch-all for nil-target navigations where createWebViewWith - // returned nil: external URLs, user-initiated new-window actions - // (target=_blank, context menu) that fall through the classifier, - // or when popup creation is unavailable. + // target=_blank link navigations should open in a new tab. + // Scripted popups (navigationType == .other) are handled in + // WKUIDelegate.createWebViewWith so OAuth opener linkage survives. if navigationAction.targetFrame == nil, + browserNavigationShouldFallbackNilTargetToNewTab( + navigationType: navigationAction.navigationType + ), let url = navigationAction.request.url { #if DEBUG dlog("browser.nav.decidePolicy.action kind=openInNewTabFromNilTarget url=\(url.absoluteString)") diff --git a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift index b8f24566..3eb02816 100644 --- a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift +++ b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift @@ -2659,6 +2659,24 @@ final class BrowserPopupDecisionTests: XCTestCase { } } +final class BrowserNilTargetFallbackDecisionTests: XCTestCase { + func testOtherNavigationDoesNotFallbackToNewTab() { + XCTAssertFalse( + browserNavigationShouldFallbackNilTargetToNewTab( + navigationType: .other + ) + ) + } + + func testLinkActivatedNavigationFallsBackToNewTab() { + XCTAssertTrue( + browserNavigationShouldFallbackNilTargetToNewTab( + navigationType: .linkActivated + ) + ) + } +} + final class BrowserPopupContentRectTests: XCTestCase { func testExplicitTopOriginCoordinatesConvertToAppKitBottomOrigin() { let rect = browserPopupContentRect(