mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-11 17:56:15 +00:00
feat: Improve error handling for HTTP 400 and network issues in browser navigation
This commit is contained in:
@@ -52,11 +52,12 @@ class Browser {
|
|||||||
'--ignore-ssl-errors'
|
'--ignore-ssl-errors'
|
||||||
]
|
]
|
||||||
|
|
||||||
// Minimal Linux fixes for DNS/network issues without detection risk
|
// Linux stability fixes without detection risk
|
||||||
// Only adds essential stability flags that don't trigger bot detection
|
|
||||||
const linuxStabilityArgs = isLinux ? [
|
const linuxStabilityArgs = isLinux ? [
|
||||||
'--disable-dev-shm-usage',
|
'--disable-dev-shm-usage',
|
||||||
'--disable-software-rasterizer'
|
'--disable-software-rasterizer',
|
||||||
|
'--disable-http-cache',
|
||||||
|
'--disk-cache-size=1'
|
||||||
] : []
|
] : []
|
||||||
|
|
||||||
browser = await playwright.chromium.launch({
|
browser = await playwright.chromium.launch({
|
||||||
|
|||||||
@@ -194,10 +194,15 @@ export default class BrowserUtil {
|
|||||||
const $ = load(html)
|
const $ = load(html)
|
||||||
|
|
||||||
const isNetworkError = $('body.neterror').length
|
const isNetworkError = $('body.neterror').length
|
||||||
|
const hasHttp400Error = html.includes('HTTP ERROR 400') ||
|
||||||
|
html.includes('This page isn\'t working') ||
|
||||||
|
html.includes('Cette page ne fonctionne pas')
|
||||||
|
|
||||||
if (isNetworkError) {
|
if (isNetworkError || hasHttp400Error) {
|
||||||
this.bot.log(this.bot.isMobile, 'RELOAD-BAD-PAGE', 'Bad page detected, reloading!')
|
const errorType = hasHttp400Error ? 'HTTP 400' : 'network error'
|
||||||
await page.reload()
|
this.bot.log(this.bot.isMobile, 'RELOAD-BAD-PAGE', `Bad page detected (${errorType}), reloading!`)
|
||||||
|
await page.reload({ waitUntil: 'domcontentloaded' })
|
||||||
|
await this.bot.utils.wait(1500)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -105,33 +105,25 @@ export class Login {
|
|||||||
const isLinux = process.platform === 'linux'
|
const isLinux = process.platform === 'linux'
|
||||||
const navigationTimeout = isLinux ? 60000 : 30000
|
const navigationTimeout = isLinux ? 60000 : 30000
|
||||||
|
|
||||||
// Retry mechanism for Linux DNS issues
|
// Navigate to dashboard
|
||||||
let lastError: Error | null = null
|
|
||||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
||||||
try {
|
|
||||||
await page.goto('https://www.bing.com/rewards/dashboard', {
|
await page.goto('https://www.bing.com/rewards/dashboard', {
|
||||||
waitUntil: 'domcontentloaded',
|
waitUntil: 'domcontentloaded',
|
||||||
timeout: navigationTimeout
|
timeout: navigationTimeout
|
||||||
})
|
})
|
||||||
lastError = null
|
|
||||||
break
|
|
||||||
} catch (e) {
|
|
||||||
lastError = e as Error
|
|
||||||
const errorMsg = e instanceof Error ? e.message : String(e)
|
|
||||||
|
|
||||||
// Only retry on chrome-error or timeout, not on HTTP errors (400, 403, etc.)
|
// PATCH: Check for HTTP 400 error and auto-reload (Linux first-load issue)
|
||||||
if (errorMsg.includes('chrome-error://chromewebdata/') || errorMsg.includes('Timeout')) {
|
await this.bot.utils.wait(500)
|
||||||
if (attempt < 3) {
|
const content = await page.content().catch(() => '')
|
||||||
this.bot.log(this.bot.isMobile, 'LOGIN', `Navigation failed (attempt ${attempt}/3), retrying...`, 'warn')
|
const hasHttp400 = content.includes('HTTP ERROR 400') ||
|
||||||
await this.bot.utils.wait(2000 * attempt)
|
content.includes('This page isn\'t working') ||
|
||||||
continue
|
content.includes('Cette page ne fonctionne pas')
|
||||||
}
|
|
||||||
}
|
if (hasHttp400) {
|
||||||
throw e
|
this.bot.log(this.bot.isMobile, 'LOGIN', 'HTTP 400 detected on first load, reloading page...', 'warn')
|
||||||
}
|
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||||
|
await this.bot.utils.wait(1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastError) throw lastError
|
|
||||||
await this.disableFido(page)
|
await this.disableFido(page)
|
||||||
|
|
||||||
const [, , portalCheck] = await Promise.allSettled([
|
const [, , portalCheck] = await Promise.allSettled([
|
||||||
@@ -183,20 +175,19 @@ export class Login {
|
|||||||
const isLinux = process.platform === 'linux'
|
const isLinux = process.platform === 'linux'
|
||||||
const navigationTimeout = isLinux ? 60000 : 30000
|
const navigationTimeout = isLinux ? 60000 : 30000
|
||||||
|
|
||||||
// Retry for Linux DNS issues
|
|
||||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
||||||
try {
|
|
||||||
await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||||
break
|
|
||||||
} catch (e) {
|
// PATCH: Check for HTTP 400 and auto-reload
|
||||||
const errorMsg = e instanceof Error ? e.message : String(e)
|
await this.bot.utils.wait(500)
|
||||||
if ((errorMsg.includes('chrome-error://chromewebdata/') || errorMsg.includes('Timeout')) && attempt < 3) {
|
const content = await page.content().catch(() => '')
|
||||||
this.bot.log(this.bot.isMobile, 'LOGIN-APP', `OAuth navigation failed (attempt ${attempt}/3), retrying...`, 'warn')
|
const hasHttp400 = content.includes('HTTP ERROR 400') ||
|
||||||
await this.bot.utils.wait(2000 * attempt)
|
content.includes('This page isn\'t working') ||
|
||||||
continue
|
content.includes('Cette page ne fonctionne pas')
|
||||||
}
|
|
||||||
throw e
|
if (hasHttp400) {
|
||||||
}
|
this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'HTTP 400 detected on OAuth page, reloading...', 'warn')
|
||||||
|
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||||
|
await this.bot.utils.wait(1000)
|
||||||
}
|
}
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'Authorizing mobile scope...')
|
this.bot.log(this.bot.isMobile, 'LOGIN-APP', 'Authorizing mobile scope...')
|
||||||
@@ -292,23 +283,21 @@ export class Login {
|
|||||||
const isLinux = process.platform === 'linux'
|
const isLinux = process.platform === 'linux'
|
||||||
const navigationTimeout = isLinux ? 60000 : 30000
|
const navigationTimeout = isLinux ? 60000 : 30000
|
||||||
|
|
||||||
// Retry for Linux DNS issues
|
|
||||||
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
||||||
try {
|
|
||||||
await page.goto(homeUrl, { timeout: navigationTimeout })
|
await page.goto(homeUrl, { timeout: navigationTimeout })
|
||||||
break
|
|
||||||
} catch (e) {
|
|
||||||
const errorMsg = e instanceof Error ? e.message : String(e)
|
|
||||||
if ((errorMsg.includes('chrome-error://chromewebdata/') || errorMsg.includes('Timeout')) && attempt < 2) {
|
|
||||||
this.bot.log(this.bot.isMobile, 'LOGIN', 'Session check navigation failed, retrying...', 'warn')
|
|
||||||
await this.bot.utils.wait(2000)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await page.waitForLoadState('domcontentloaded').catch(logError('LOGIN', 'DOMContentLoaded timeout', this.bot.isMobile))
|
await page.waitForLoadState('domcontentloaded').catch(logError('LOGIN', 'DOMContentLoaded timeout', this.bot.isMobile))
|
||||||
|
|
||||||
|
// PATCH: Check for HTTP 400 and auto-reload
|
||||||
|
await this.bot.utils.wait(500)
|
||||||
|
const content = await page.content().catch(() => '')
|
||||||
|
const hasHttp400 = content.includes('HTTP ERROR 400') ||
|
||||||
|
content.includes('This page isn\'t working') ||
|
||||||
|
content.includes('Cette page ne fonctionne pas')
|
||||||
|
|
||||||
|
if (hasHttp400) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'LOGIN', 'HTTP 400 on session check, reloading...', 'warn')
|
||||||
|
await page.reload({ waitUntil: 'domcontentloaded', timeout: navigationTimeout })
|
||||||
|
await this.bot.utils.wait(1000)
|
||||||
|
}
|
||||||
await this.bot.browser.utils.reloadBadPage(page)
|
await this.bot.browser.utils.reloadBadPage(page)
|
||||||
await this.bot.utils.wait(250)
|
await this.bot.utils.wait(250)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user