Feature: Improved handling of wait times for page checks and reloads, using a 10s timeout for slower networks

This commit is contained in:
2025-11-13 14:37:17 +01:00
parent 9f56227608
commit 2959fc8c73
4 changed files with 20 additions and 11 deletions

View File

@@ -79,8 +79,9 @@ export default class BrowserFunc {
await page.goto(this.bot.config.baseURL) await page.goto(this.bot.config.baseURL)
// IMPROVED: Smart page readiness check after navigation // IMPROVED: Smart page readiness check after navigation
// FIXED: Use timeoutMs parameter with increased timeout for slower networks
const readyResult = await waitForPageReady(page, { 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') 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) await page.goto(this.bot.config.baseURL)
// IMPROVED: Wait for page ready after redirect // IMPROVED: Wait for page ready after redirect
// FIXED: Use timeoutMs parameter with increased timeout
await waitForPageReady(page, { 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') logFn: (msg) => this.bot.log(this.bot.isMobile, 'GO-HOME', msg, 'log')
}) })
} else { } else {
@@ -258,8 +260,9 @@ export default class BrowserFunc {
await this.goHome(target) await this.goHome(target)
// IMPROVED: Smart page readiness check instead of fixed wait // IMPROVED: Smart page readiness check instead of fixed wait
// FIXED: Use timeoutMs parameter with increased timeout
await waitForPageReady(target, { 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') logFn: (msg) => this.bot.log(this.bot.isMobile, 'BROWSER-FUNC', msg, 'log')
}).catch((error) => { }).catch((error) => {
const errorMsg = error instanceof Error ? error.message : String(error) const errorMsg = error instanceof Error ? error.message : String(error)

View File

@@ -209,6 +209,7 @@ export default class BrowserUtil {
this.bot.log(this.bot.isMobile, 'RELOAD-BAD-PAGE', `Bad page detected (${errorType}), reloading!`) this.bot.log(this.bot.isMobile, 'RELOAD-BAD-PAGE', `Bad page detected (${errorType}), reloading!`)
await page.reload({ waitUntil: 'domcontentloaded' }) await page.reload({ waitUntil: 'domcontentloaded' })
// IMPROVED: Use smart wait instead of fixed 1500ms delay // IMPROVED: Use smart wait instead of fixed 1500ms delay
// FIXED: Use default 10s timeout for page reload
await waitForPageReady(page) await waitForPageReady(page)
} }

View File

@@ -484,8 +484,9 @@ export class Login {
await this.inputEmail(page, email) await this.inputEmail(page, email)
// Step 2: Wait for transition to password page (silent - no spam) // Step 2: Wait for transition to password page (silent - no spam)
// FIXED: Use timeoutMs parameter with 10s timeout
await waitForPageReady(page, { await waitForPageReady(page, {
networkIdleMs: 500 timeoutMs: 10000
}) })
const passwordPageReached = await LoginStateDetector.waitForAnyState( const passwordPageReached = await LoginStateDetector.waitForAnyState(
@@ -544,6 +545,7 @@ export class Login {
// --------------- Input Steps --------------- // --------------- Input Steps ---------------
private async inputEmail(page: Page, email: string) { private async inputEmail(page: Page, email: string) {
// IMPROVED: Smart page readiness check (silent - no spam logs) // IMPROVED: Smart page readiness check (silent - no spam logs)
// Using default 10s timeout
const readyResult = await waitForPageReady(page) const readyResult = await waitForPageReady(page)
// Only log if REALLY slow (>5s indicates a problem) // Only log if REALLY slow (>5s indicates a problem)
@@ -586,7 +588,7 @@ export class Login {
if (content.length < 1000) { if (content.length < 1000) {
this.bot.log(this.bot.isMobile, 'LOGIN', 'Reloading page...', 'warn') this.bot.log(this.bot.isMobile, 'LOGIN', 'Reloading page...', 'warn')
await page.reload({ waitUntil: 'domcontentloaded', timeout: 10000 }).catch(() => { }) 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') const totpRetry = await this.tryAutoTotp(page, 'pre-email retry')

View File

@@ -52,21 +52,23 @@ export async function waitForNetworkIdle(
/** /**
* Wait for page to be truly ready (network idle + DOM ready) * Wait for page to be truly ready (network idle + DOM ready)
* Much faster than waitForLoadState with fixed timeouts * Much faster than waitForLoadState with fixed timeouts
*
* FIXED: Properly wait for network idle state with adequate timeout
*/ */
export async function waitForPageReady( export async function waitForPageReady(
page: Page, page: Page,
options: { options: {
networkIdleMs?: number timeoutMs?: number
logFn?: (msg: string) => void logFn?: (msg: string) => void
} = {} } = {}
): Promise<{ ready: boolean; timeMs: number }> { ): Promise<{ ready: boolean; timeMs: number }> {
const startTime = Date.now() 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 ?? (() => { }) const logFn = options.logFn ?? (() => { })
try { try {
// Step 1: Wait for DOM ready (fast) // 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...') logFn('DOM load timeout, continuing...')
}) })
@@ -82,9 +84,10 @@ export async function waitForPageReady(
return { ready: true, timeMs: elapsed } return { ready: true, timeMs: elapsed }
} }
// Step 3: Wait for network idle with adaptive polling // Step 3: Wait for network idle with proper timeout (not duration)
await page.waitForLoadState('networkidle', { timeout: networkIdleMs }).catch(() => { // FIXED: Use timeoutMs as the maximum wait time for networkidle state
logFn('Network idle timeout (expected), page may still be usable') 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 const elapsed = Date.now() - startTime