Repository navigation
fix: detect login completion on SPA route changes, not just full page loads - #7
Open
weichenyeh wants to merge 1 commit into
Open
weichenyeh wants to merge 1 commit into
weichenyeh wants to merge 1 commit into
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LoginWindowControlleronly checks whether login succeeded insidewebView(_: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, sodidFinishnever fires again after the initial/loginpage — 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/usageview, but the window never auto-closed. Quitting and relaunching the app worked around it, since that forces a fresh full-pagewebView.load(...)call, which does triggerdidFinishcorrectly — that behavior is what pointed at the root cause.Fix
Extracted the existing login-state check into
checkLoginState(), and added a KVO observation onwebView.urlalongside the existingdidFinishcallback. WKWebView updates itsurlproperty (and fires KVO) on client-side route changes as well as full navigations, so this catches the casedidFinishmisses, without depending on any claude.ai-specific implementation detail.Verification
swiftcinvocationscripts/build.shuses — produces a working Mach-O binary.urlfor client-side navigation; a maintainer confirming against a live login before merging would be good.