From 2959fc8c73e0f4f04ae41d8d53dadf969b7fcd94 Mon Sep 17 00:00:00 2001 From: LightZirconite Date: Thu, 13 Nov 2025 14:37:17 +0100 Subject: [PATCH] Feature: Improved handling of wait times for page checks and reloads, using a 10s timeout for slower networks --- src/browser/BrowserFunc.ts | 9 ++++++--- src/browser/BrowserUtil.ts | 1 + src/functions/Login.ts | 6 ++++-- src/util/browser/SmartWait.ts | 15 +++++++++------ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/browser/BrowserFunc.ts b/src/browser/BrowserFunc.ts index 4b8e923..a9c5d80 100644 --- a/src/browser/BrowserFunc.ts +++ b/src/browser/BrowserFunc.ts @@ -79,8 +79,9 @@ export default class BrowserFunc { await page.goto(this.bot.config.baseURL) // IMPROVED: Smart page readiness check after navigation + // FIXED: Use timeoutMs parameter with increased timeout for slower networks const readyResult = await waitForPageReady(page, { - networkIdleMs: 1000, + timeoutMs: 15000, // FIXED: 15s timeout to handle slower network conditions logFn: (msg) => this.bot.log(this.bot.isMobile, 'GO-HOME', msg, 'log') }) @@ -199,8 +200,9 @@ export default class BrowserFunc { await page.goto(this.bot.config.baseURL) // IMPROVED: Wait for page ready after redirect + // FIXED: Use timeoutMs parameter with increased timeout await waitForPageReady(page, { - networkIdleMs: 1000, + timeoutMs: 15000, // FIXED: 15s timeout to handle slower network conditions logFn: (msg) => this.bot.log(this.bot.isMobile, 'GO-HOME', msg, 'log') }) } else { @@ -258,8 +260,9 @@ export default class BrowserFunc { await this.goHome(target) // IMPROVED: Smart page readiness check instead of fixed wait + // FIXED: Use timeoutMs parameter with increased timeout await waitForPageReady(target, { - networkIdleMs: 1000, + timeoutMs: 15000, // FIXED: 15s timeout for dashboard recovery logFn: (msg) => this.bot.log(this.bot.isMobile, 'BROWSER-FUNC', msg, 'log') }).catch((error) => { const errorMsg = error instanceof Error ? error.message : String(error) diff --git a/src/browser/BrowserUtil.ts b/src/browser/BrowserUtil.ts index 5824fc1..b33633b 100644 --- a/src/browser/BrowserUtil.ts +++ b/src/browser/BrowserUtil.ts @@ -209,6 +209,7 @@ export default class BrowserUtil { this.bot.log(this.bot.isMobile, 'RELOAD-BAD-PAGE', `Bad page detected (${errorType}), reloading!`) await page.reload({ waitUntil: 'domcontentloaded' }) // IMPROVED: Use smart wait instead of fixed 1500ms delay + // FIXED: Use default 10s timeout for page reload await waitForPageReady(page) } diff --git a/src/functions/Login.ts b/src/functions/Login.ts index bf8cdb9..816282b 100644 --- a/src/functions/Login.ts +++ b/src/functions/Login.ts @@ -484,8 +484,9 @@ export class Login { await this.inputEmail(page, email) // Step 2: Wait for transition to password page (silent - no spam) + // FIXED: Use timeoutMs parameter with 10s timeout await waitForPageReady(page, { - networkIdleMs: 500 + timeoutMs: 10000 }) const passwordPageReached = await LoginStateDetector.waitForAnyState( @@ -544,6 +545,7 @@ export class Login { // --------------- Input Steps --------------- private async inputEmail(page: Page, email: string) { // IMPROVED: Smart page readiness check (silent - no spam logs) + // Using default 10s timeout const readyResult = await waitForPageReady(page) // Only log if REALLY slow (>5s indicates a problem) @@ -586,7 +588,7 @@ export class Login { if (content.length < 1000) { this.bot.log(this.bot.isMobile, 'LOGIN', 'Reloading page...', 'warn') await page.reload({ waitUntil: 'domcontentloaded', timeout: 10000 }).catch(() => { }) - await waitForPageReady(page) // Silent + await waitForPageReady(page) // Silent - using default 10s timeout } const totpRetry = await this.tryAutoTotp(page, 'pre-email retry') diff --git a/src/util/browser/SmartWait.ts b/src/util/browser/SmartWait.ts index 7f7ede2..9557263 100644 --- a/src/util/browser/SmartWait.ts +++ b/src/util/browser/SmartWait.ts @@ -52,21 +52,23 @@ export async function waitForNetworkIdle( /** * Wait for page to be truly ready (network idle + DOM ready) * Much faster than waitForLoadState with fixed timeouts + * + * FIXED: Properly wait for network idle state with adequate timeout */ export async function waitForPageReady( page: Page, options: { - networkIdleMs?: number + timeoutMs?: number logFn?: (msg: string) => void } = {} ): Promise<{ ready: boolean; timeMs: number }> { const startTime = Date.now() - const networkIdleMs = options.networkIdleMs ?? 500 // Network quiet for 500ms + const timeoutMs = options.timeoutMs ?? 10000 // FIXED: 10s timeout for network idle const logFn = options.logFn ?? (() => { }) try { // Step 1: Wait for DOM ready (fast) - await page.waitForLoadState('domcontentloaded', { timeout: 3000 }).catch(() => { + await page.waitForLoadState('domcontentloaded', { timeout: 5000 }).catch(() => { logFn('DOM load timeout, continuing...') }) @@ -82,9 +84,10 @@ export async function waitForPageReady( return { ready: true, timeMs: elapsed } } - // Step 3: Wait for network idle with adaptive polling - await page.waitForLoadState('networkidle', { timeout: networkIdleMs }).catch(() => { - logFn('Network idle timeout (expected), page may still be usable') + // Step 3: Wait for network idle with proper timeout (not duration) + // FIXED: Use timeoutMs as the maximum wait time for networkidle state + await page.waitForLoadState('networkidle', { timeout: timeoutMs }).catch(() => { + logFn(`Network idle timeout after ${timeoutMs}ms (expected), page may still be usable`) }) const elapsed = Date.now() - startTime