feat: Centralize browser instance creation to eliminate duplication in Desktop and Mobile flows

fix: Update error message for HTTP 400 checks to English
refactor: Improve logging for network idle wait timeout in Workers
fix: Initialize lastError in Axios client to prevent undefined errors
chore: Update tsconfig to include path mappings for better module resolution
This commit is contained in:
2025-11-09 17:56:46 +01:00
parent 56aacd3667
commit 9fb5911fa2
10 changed files with 101 additions and 38 deletions

View File

@@ -87,7 +87,8 @@ class AxiosClient {
return bypassInstance.request(config)
}
let lastError: unknown
// FIXED: Initialize lastError to prevent throwing undefined
let lastError: unknown = new Error('Request failed with unknown error')
const maxAttempts = 2
for (let attempt = 1; attempt <= maxAttempts; attempt++) {

View File

@@ -0,0 +1,33 @@
/**
* Browser Factory Utility
* Eliminates code duplication between Desktop and Mobile flows
*
* Centralized browser instance creation logic
*/
import type { BrowserContext } from 'rebrowser-playwright'
import type { MicrosoftRewardsBot } from '../index'
import type { AccountProxy } from '../interface/Account'
/**
* Create a browser instance for the given account
* IMPROVEMENT: Extracted from DesktopFlow and MobileFlow to eliminate duplication
*
* @param bot Bot instance
* @param proxy Account proxy configuration
* @param email Account email for session naming
* @returns Browser context ready to use
*
* @example
* const browser = await createBrowserInstance(bot, account.proxy, account.email)
*/
export async function createBrowserInstance(
bot: MicrosoftRewardsBot,
proxy: AccountProxy,
email: string
): Promise<BrowserContext> {
const browserModule = await import('../browser/Browser')
const Browser = browserModule.default
const browserInstance = new Browser(bot)
return await browserInstance.createBrowser(proxy, email)
}