Remove BuyMode and fix

This commit is contained in:
2025-11-08 18:25:51 +01:00
parent 40dd9b9fd8
commit 6b687a1018
16 changed files with 24 additions and 997 deletions

View File

@@ -27,20 +27,10 @@ class Browser {
let browser: import('rebrowser-playwright').Browser
try {
const envForceHeadless = process.env.FORCE_HEADLESS === '1'
let headless = envForceHeadless ? true : (this.bot.config.browser?.headless ?? false)
// Buy/Interactive mode: always visible and with enhanced stealth
const isBuyMode = this.bot.isBuyModeEnabled()
if (isBuyMode && !envForceHeadless) {
if (headless !== false) {
const target = this.bot.getBuyModeTarget()
this.bot.log(this.bot.isMobile, 'BROWSER', `Interactive mode: forcing headless=false${target ? ` for ${target}` : ''}`, 'warn')
}
headless = false
}
const headless = envForceHeadless ? true : (this.bot.config.browser?.headless ?? false)
const engineName = 'chromium'
this.bot.log(this.bot.isMobile, 'BROWSER', `Launching ${engineName} (headless=${headless}${isBuyMode ? ', stealth-mode=ENHANCED' : ''})`)
this.bot.log(this.bot.isMobile, 'BROWSER', `Launching ${engineName} (headless=${headless})`)
const proxyConfig = this.buildPlaywrightProxy(proxy)
const isLinux = process.platform === 'linux'
@@ -63,26 +53,10 @@ class Browser {
'--disk-cache-size=1'
] : []
// ENHANCED STEALTH MODE for Buy/Interactive Mode
// These arguments help bypass CAPTCHA and automation detection
const stealthArgs = isBuyMode ? [
'--disable-blink-features=AutomationControlled', // Critical: Hide automation
'--disable-features=IsolateOrigins,site-per-process', // Reduce detection surface
'--disable-site-isolation-trials',
'--disable-web-security', // Allow cross-origin (may help with CAPTCHA)
'--disable-features=VizDisplayCompositor', // Reduce GPU fingerprinting
'--no-first-run',
'--no-default-browser-check',
'--disable-infobars',
'--window-position=0,0',
'--window-size=1920,1080', // Consistent window size
'--start-maximized'
] : []
browser = await playwright.chromium.launch({
headless,
...(proxyConfig && { proxy: proxyConfig }),
args: [...baseArgs, ...linuxStabilityArgs, ...stealthArgs],
args: [...baseArgs, ...linuxStabilityArgs],
timeout: isLinux ? 90000 : 60000
})
} catch (e: unknown) {
@@ -106,8 +80,6 @@ class Browser {
const globalTimeout = this.bot.config.browser?.globalTimeout ?? 30000
context.setDefaultTimeout(typeof globalTimeout === 'number' ? globalTimeout : this.bot.utils.stringToMs(globalTimeout))
const isBuyMode = this.bot.isBuyModeEnabled()
try {
context.on('page', async (page) => {
try {
@@ -131,65 +103,6 @@ class Browser {
document.documentElement.appendChild(style)
} catch {/* ignore */}
})
// ENHANCED ANTI-DETECTION for Buy/Interactive Mode
if (isBuyMode) {
await page.addInitScript(`
// Override navigator.webdriver (critical for CAPTCHA bypass)
Object.defineProperty(Object.getPrototypeOf(navigator), 'webdriver', {
get: () => false
});
// Add chrome runtime (looks more human)
Object.defineProperty(window, 'chrome', {
writable: true,
enumerable: true,
configurable: false,
value: { runtime: {} }
});
// Add plugins (looks more human)
Object.defineProperty(navigator, 'plugins', {
get: () => [
{ name: 'Chrome PDF Plugin' },
{ name: 'Chrome PDF Viewer' },
{ name: 'Native Client' }
]
});
// Languages
Object.defineProperty(navigator, 'languages', {
get: () => ['en-US', 'en', 'fr']
});
// Hide automation markers
['__nightmare', '__playwright', '__pw_manual', '__webdriver_script_fn', 'webdriver'].forEach(prop => {
try {
if (prop in window) delete (window as Record<string, unknown>)[prop];
} catch {
// Silently ignore: property deletion may be blocked by browser security
}
});
// Override permissions to avoid detection
const originalPermissionsQuery = window.navigator.permissions.query;
window.navigator.permissions.query = function(params) {
if (params.name === 'notifications') {
return Promise.resolve({
state: Notification.permission,
name: 'notifications',
onchange: null,
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => true
});
}
return originalPermissionsQuery.call(this, params);
};
`)
this.bot.log(this.bot.isMobile, 'BROWSER', '🛡️ Enhanced stealth mode activated (anti-CAPTCHA)', 'log', 'green')
}
} catch (e) {
this.bot.log(this.bot.isMobile, 'BROWSER', `Page setup warning: ${e instanceof Error ? e.message : String(e)}`, 'warn')
}