From 0afd1e990c3db188442b577e4f6ef9cd39f1224b Mon Sep 17 00:00:00 2001 From: LightZirconite Date: Tue, 4 Nov 2025 23:00:05 +0100 Subject: [PATCH] feat: Add error handling for navigation interruptions and HTTP 400 responses in login flow --- src/functions/Login.ts | 116 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 104 insertions(+), 12 deletions(-) diff --git a/src/functions/Login.ts b/src/functions/Login.ts index 11ea392..89bef8a 100644 --- a/src/functions/Login.ts +++ b/src/functions/Login.ts @@ -105,13 +105,51 @@ export class Login { const isLinux = process.platform === 'linux' const navigationTimeout = isLinux ? 60000 : 30000 - // Navigate to dashboard - await page.goto('https://www.bing.com/rewards/dashboard', { - waitUntil: 'domcontentloaded', - timeout: navigationTimeout - }) + // Try initial navigation with error handling for chrome-error interruption + let navigationSucceeded = false + try { + await page.goto('https://www.bing.com/rewards/dashboard', { + waitUntil: 'domcontentloaded', + timeout: navigationTimeout + }) + navigationSucceeded = true + } catch (error) { + const errorMsg = error instanceof Error ? error.message : String(error) + + // If interrupted by chrome-error, retry with reload approach + if (errorMsg.includes('chrome-error://chromewebdata/')) { + this.bot.log(this.bot.isMobile, 'LOGIN', 'Navigation interrupted by chrome-error, attempting recovery...', 'warn') + + // Wait a bit for page to settle + await this.bot.utils.wait(1000) + + // Try reload which usually fixes the issue + try { + await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout }) + navigationSucceeded = true + this.bot.log(this.bot.isMobile, 'LOGIN', 'Recovery successful via reload') + } catch (reloadError) { + // Last resort: try goto again + this.bot.log(this.bot.isMobile, 'LOGIN', 'Reload failed, trying fresh navigation...', 'warn') + await this.bot.utils.wait(1500) + await page.goto('https://www.bing.com/rewards/dashboard', { + waitUntil: 'domcontentloaded', + timeout: navigationTimeout + }) + navigationSucceeded = true + this.bot.log(this.bot.isMobile, 'LOGIN', 'Recovery successful via fresh navigation') + } + } else { + // Different error, rethrow + throw error + } + } - // PATCH: Check for HTTP 400 error and auto-reload (Linux first-load issue) + if (!navigationSucceeded) { + throw new Error('Failed to navigate to dashboard after multiple attempts') + } + + // Additional check for HTTP 400 in page content await this.bot.utils.wait(500) const content = await page.content().catch(() => '') const hasHttp400 = content.includes('HTTP ERROR 400') || @@ -119,7 +157,7 @@ export class Login { content.includes('Cette page ne fonctionne pas') if (hasHttp400) { - this.bot.log(this.bot.isMobile, 'LOGIN', 'HTTP 400 detected on first load, reloading page...', 'warn') + this.bot.log(this.bot.isMobile, 'LOGIN', 'HTTP 400 detected in content, reloading...', 'warn') await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout }) await this.bot.utils.wait(1000) } @@ -175,9 +213,37 @@ export class Login { const isLinux = process.platform === 'linux' const navigationTimeout = isLinux ? 60000 : 30000 - await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: navigationTimeout }) + // Try initial navigation with error handling + let navigationSucceeded = false + try { + await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: navigationTimeout }) + navigationSucceeded = true + } catch (error) { + const errorMsg = error instanceof Error ? error.message : String(error) + + if (errorMsg.includes('chrome-error://chromewebdata/')) { + this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'OAuth navigation interrupted, attempting recovery...', 'warn') + await this.bot.utils.wait(1000) + + try { + await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout }) + navigationSucceeded = true + this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'OAuth recovery successful') + } catch (reloadError) { + await this.bot.utils.wait(1500) + await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: navigationTimeout }) + navigationSucceeded = true + } + } else { + throw error + } + } - // PATCH: Check for HTTP 400 and auto-reload + if (!navigationSucceeded) { + throw new Error('Failed to navigate to OAuth page') + } + + // Check for HTTP 400 await this.bot.utils.wait(500) const content = await page.content().catch(() => '') const hasHttp400 = content.includes('HTTP ERROR 400') || @@ -185,7 +251,7 @@ export class Login { content.includes('Cette page ne fonctionne pas') if (hasHttp400) { - this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'HTTP 400 detected on OAuth page, reloading...', 'warn') + this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'HTTP 400 detected, reloading...', 'warn') await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout }) await this.bot.utils.wait(1000) } @@ -283,10 +349,36 @@ export class Login { const isLinux = process.platform === 'linux' const navigationTimeout = isLinux ? 60000 : 30000 - await page.goto(homeUrl, { timeout: navigationTimeout }) + // Try navigation with error recovery + let navigationSucceeded = false + try { + await page.goto(homeUrl, { timeout: navigationTimeout }) + navigationSucceeded = true + } catch (error) { + const errorMsg = error instanceof Error ? error.message : String(error) + + if (errorMsg.includes('chrome-error://chromewebdata/')) { + this.bot.log(this.bot.isMobile, 'LOGIN', 'Session check interrupted, recovering...', 'warn') + await this.bot.utils.wait(1000) + + try { + await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout }) + navigationSucceeded = true + } catch (reloadError) { + await this.bot.utils.wait(1500) + await page.goto(homeUrl, { timeout: navigationTimeout }) + navigationSucceeded = true + } + } else { + throw error + } + } + + if (!navigationSucceeded) return false + await page.waitForLoadState('domcontentloaded').catch(logError('LOGIN', 'DOMContentLoaded timeout', this.bot.isMobile)) - // PATCH: Check for HTTP 400 and auto-reload + // Check for HTTP 400 await this.bot.utils.wait(500) const content = await page.content().catch(() => '') const hasHttp400 = content.includes('HTTP ERROR 400') ||