From 00934fecbb0179c919ca69fc854e4446f71b2f60 Mon Sep 17 00:00:00 2001 From: Jamie Brunton Date: Mon, 5 Jan 2026 15:13:59 +0000 Subject: [PATCH] Update --- src/browser/client.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/browser/client.ts b/src/browser/client.ts index a7c5cc1..7d645d9 100644 --- a/src/browser/client.ts +++ b/src/browser/client.ts @@ -176,6 +176,12 @@ export class BrowserClient { // Give cookies/time to settle await page.waitForTimeout(2000); + const isValid = await this.isSessionValid(); + if (isValid) { + this.logger.info('Login successful!'); + return true; + } + const obstacleInfo = await this.detectLoginObstacles(page); if (obstacleInfo.twoFactor) { this.logger.error('Login requires 2FA. Please run "npm run login" locally to complete it once.'); @@ -193,13 +199,6 @@ export class BrowserClient { return false; } - // Confirm auth via UI or API check - const isValid = await this.isSessionValid(); - if (isValid) { - this.logger.info('Login successful!'); - return true; - } - // Check for error messages const errorContent = obstacleInfo.errorText; @@ -231,13 +230,20 @@ export class BrowserClient { .map((el) => el.textContent?.trim()) .filter((text) => text && text.length > 0) as string[]; + const isLoginContext = + window.location.href.includes('/login') || + Boolean( + document.querySelector( + 'input[name="username"], input[name="password"], form[action*="login"], [data-testid="login-form"]' + ) + ); const otpInput = document.querySelector('input[name="otp"], input[autocomplete="one-time-code"], input[type="tel"][maxlength="6"]'); const captchaElement = document.querySelector('iframe[src*="captcha"], iframe[src*="recaptcha"], [data-sitekey], #captcha, .captcha'); return { errorText: errorCandidates[0] ?? null, - hasOtp: Boolean(otpInput), - hasCaptcha: Boolean(captchaElement), + hasOtp: Boolean(otpInput) && isLoginContext, + hasCaptcha: Boolean(captchaElement) && isLoginContext, }; });