fix: revert to URL-based auth detection; remove browser headers

Every JS/cookie-based detection approach failed. Reverting to the
simplest reliable mechanism: if the WebView navigates to any non-login,
non-auth URL, the server redirected us after sign-in — fire onAuthenticated.

Also removing the browser headers added in beta.6. The 1.1.4 version
worked without them and they may be triggering server-side bot detection.
All-cookies approach (beta.8) is kept.
This commit is contained in:
superdooper86
2026-05-11 10:35:30 +02:00
parent 1a9d9cd22a
commit ad2ff3a7b6
3 changed files with 10 additions and 29 deletions
+2 -2
View File
@@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1-beta.9</string>
<string>1.2.1-beta.10</string>
<key>CFBundleVersion</key>
<string>57</string>
<string>58</string>
<key>LSMinimumSystemVersion</key>
<string>13.0</string>
<key>LSUIElement</key>
+7 -20
View File
@@ -32,26 +32,13 @@ struct LoginWebView: NSViewRepresentable {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
guard !didAuthenticate else { return }
// Don't fire on the login/auth pages themselves
if let url = webView.url?.absoluteString,
url.contains("/login") || url.contains("/auth") { return }
// Ask the WebView itself whether we're authenticated it uses its own
// session (cookies, localStorage, etc.) so we don't need to know the
// cookie domain or name.
webView.callAsyncJavaScript(
"const r = await fetch('/api/bootstrap', {credentials: 'include'}); return r.status;",
arguments: [:], in: nil, in: .page
) { [weak self] result in
guard let self, !self.didAuthenticate else { return }
// JS numbers arrive as NSNumber (Double-backed), not Swift Int
if case .success(let val) = result,
let n = val as? NSNumber, n.intValue == 200 {
self.didAuthenticate = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.onAuthenticated()
}
}
guard let url = webView.url?.absoluteString else { return }
// Stay on login/auth pages user hasn't completed sign-in yet
if url.contains("/login") || url.contains("/auth") { return }
// Navigated away from login server redirected us, so sign-in completed
didAuthenticate = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.onAuthenticated()
}
}
}
+1 -7
View File
@@ -130,13 +130,7 @@ class UsageViewModel: ObservableObject {
private func claudeAPIRequest(for url: URL) async -> URLRequest {
var req = URLRequest(url: url)
req.setValue("application/json, text/plain, */*", forHTTPHeaderField: "accept")
req.setValue("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", forHTTPHeaderField: "User-Agent")
req.setValue("https://claude.ai", forHTTPHeaderField: "Origin")
req.setValue("https://claude.ai/", forHTTPHeaderField: "Referer")
req.setValue("same-origin", forHTTPHeaderField: "sec-fetch-site")
req.setValue("cors", forHTTPHeaderField: "sec-fetch-mode")
req.setValue("empty", forHTTPHeaderField: "sec-fetch-dest")
req.setValue("application/json", forHTTPHeaderField: "accept")
if let cookie = await claudeCookieHeader() {
req.setValue(cookie, forHTTPHeaderField: "Cookie")
}