Skip to content

fix: detect login completion on SPA route changes, not just full page loads - #7

Open
weichenyeh wants to merge 1 commit into
theDanButuc:v2.2.1from
weichenyeh:fix/login-spa-navigation
Open

weichenyeh wants to merge 1 commit into
theDanButuc:v2.2.1from
weichenyeh:fix/login-spa-navigation

Conversation

@weichenyeh

Copy link
Copy Markdown

Problem
LoginWindowController only checks whether login succeeded inside webView(_:didFinish:), which fires after a full page load. claude.ai's login flow can complete via client-side routing (history.pushState) without a full page reload, so didFinish never fires again after the initial /login page — the session cookie is set, but the app never notices, and the login window stays open indefinitely even though the user is visibly signed in.

Reproduced this on 2026-08-06: logged into claude.ai in the embedded window, the page showed the authenticated /settings/usage view, but the window never auto-closed. Quitting and relaunching the app worked around it, since that forces a fresh full-page webView.load(...) call, which does trigger didFinish correctly — that behavior is what pointed at the root cause.

Fix
Extracted the existing login-state check into checkLoginState(), and added a KVO observation on webView.url alongside the existing didFinish callback. WKWebView updates its url property (and fires KVO) on client-side route changes as well as full navigations, so this catches the case didFinish misses, without depending on any claude.ai-specific implementation detail.

Verification

  • Compiled clean with the same swiftc invocation scripts/build.sh uses — produces a working Mach-O binary.
  • Have not re-run the original live repro against this specific fix — I don't have a reliable way to force claude.ai back into the exact pushState-based flow on demand. The fix is based on WKWebView's documented KVO behavior on url for client-side navigation; a maintainer confirming against a live login before merging would be good.

… loads

LoginWindowController only checked login state inside didFinish(navigation:),
which fires on full page loads. claude.ai often completes login via
client-side routing (history.pushState) without a full reload, so didFinish
never re-fires and the login window stays open even though the session
cookie is already set.

Add a KVO observation on webView.url as a second trigger for the same
check, alongside the existing didFinish callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant