mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-11 17:56:15 +00:00
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:
@@ -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++) {
|
||||
|
||||
33
src/util/BrowserFactory.ts
Normal file
33
src/util/BrowserFactory.ts
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user