From fa80cc6ceaa6d4d6d7dfa285737fff50ec666d86 Mon Sep 17 00:00:00 2001 From: nafer Date: Fri, 6 Mar 2026 10:09:57 +0300 Subject: [PATCH] opus_new --- app.py | 37 +++++++++++++++++++-- stealth-extension/stealth.js | 62 ++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index d27551e..09fcbc1 100644 --- a/app.py +++ b/app.py @@ -224,12 +224,41 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str): existing_prefs['safebrowsing'] = {} existing_prefs['safebrowsing']['enabled'] = False + # Разрешаем cookies для всех сайтов + existing_prefs['profile']['default_content_setting_values'] = existing_prefs.get('profile', {}).get('default_content_setting_values', {}) + existing_prefs['profile']['default_content_setting_values']['cookies'] = 1 # 1 = Allow + + # Отключаем Tracking Protection + if 'tracking_protection' not in existing_prefs: + existing_prefs['tracking_protection'] = {} + existing_prefs['tracking_protection']['block_all_3pc_toggle_enabled'] = False + existing_prefs['tracking_protection']['tracking_protection_3pcd_enabled'] = False + existing_prefs['tracking_protection']['tracking_protection_level'] = 0 + with open(prefs_path, 'w') as f: json_mod.dump(existing_prefs, f) logger.info(f"[{task_id}] Chrome Preferences updated (third-party cookies allowed)") except Exception as e: logger.warning(f"[{task_id}] Could not update Chrome Preferences: {e}") + # Обновляем Local State для глобальных настроек cookies + try: + local_state_path = os.path.join(user_data_dir, "Local State") + local_state = {} + if os.path.exists(local_state_path): + with open(local_state_path, 'r') as f: + local_state = json_mod.load(f) + + if 'browser' not in local_state: + local_state['browser'] = {} + local_state['browser']['enabled_labs_experiments'] = local_state.get('browser', {}).get('enabled_labs_experiments', []) + + with open(local_state_path, 'w') as f: + json_mod.dump(local_state, f) + logger.info(f"[{task_id}] Local State updated") + except Exception as e: + logger.warning(f"[{task_id}] Could not update Local State: {e}") + # Удаляем файл блокировки профиля, если он остался от предыдущего запуска # В Linux это обычно симлинк SingletonLock for lock_name in ["SingletonLock", "SingletonCookie", "SingletonSocket"]: @@ -271,15 +300,17 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str): "--password-store=basic", "--use-mock-keychain", "--force-color-profile=srgb", - "--disable-features=IsolateOrigins,site-per-process,ThirdPartyStoragePartitioning,BlockThirdPartyCookies", + "--disable-features=IsolateOrigins,site-per-process,ThirdPartyStoragePartitioning,BlockThirdPartyCookies,SameSiteByDefaultCookies,CookiesWithoutSameSiteMustBeSecure,ThirdPartyPhaseout,TrackingProtection3pcd", + "--disable-site-isolation-trials", + "--disable-web-security", "--disable-notifications", "--disable-popup-blocking", "--disable-print-preview", "--disable-prompt-on-repost", "--disable-sync", "--no-pings", - "--mute-audio", - "--enable-unsafe-swiftshader", # Исправляет ошибку WebGL в Docker + "--autoplay-policy=no-user-gesture-required", + "--enable-unsafe-swiftshader", "--ignore-gpu-blocklist", "--enable-webgl", "--test-type", diff --git a/stealth-extension/stealth.js b/stealth-extension/stealth.js index afcbd4b..e535e78 100644 --- a/stealth-extension/stealth.js +++ b/stealth-extension/stealth.js @@ -560,6 +560,68 @@ } } catch (e) {} + // ------------------------------------------------------------------------- + // 26. AudioContext — автоматический resume для обхода autoplay policy + // ------------------------------------------------------------------------- + try { + const OriginalAudioContext = window.AudioContext || window.webkitAudioContext; + if (OriginalAudioContext) { + const originalResume = OriginalAudioContext.prototype.resume; + const originalConstructor = OriginalAudioContext; + + // Патчим конструктор чтобы автоматически resume + window.AudioContext = function(...args) { + const ctx = new originalConstructor(...args); + // Автоматически resume если suspended + if (ctx.state === 'suspended') { + try { ctx.resume(); } catch(e) {} + } + return ctx; + }; + window.AudioContext.prototype = originalConstructor.prototype; + + if (window.webkitAudioContext) { + window.webkitAudioContext = window.AudioContext; + } + } + } catch (e) {} + + // ------------------------------------------------------------------------- + // 27. Скрываем факт использования расширений от content scripts detection + // ------------------------------------------------------------------------- + try { + // Некоторые антифроды проверяют chrome.runtime.id — если он есть, значит расширение + // Мы уже определили chrome.runtime выше, но убедимся что id = undefined + if (window.chrome && window.chrome.runtime) { + Object.defineProperty(window.chrome.runtime, 'id', { + get: () => undefined, + configurable: true, + }); + } + } catch (e) {} + + // ------------------------------------------------------------------------- + // 28. Скрываем sourceURL в стеке вызовов (anti-extension detection) + // ------------------------------------------------------------------------- + try { + const originalError = Error; + const originalPrepareStackTrace = Error.prepareStackTrace; + + Error.prepareStackTrace = function(error, stack) { + // Фильтруем фреймы, содержащие chrome-extension:// + const filteredStack = stack.filter(frame => { + const fileName = frame.getFileName(); + return !fileName || !fileName.startsWith('chrome-extension://'); + }); + + if (originalPrepareStackTrace) { + return originalPrepareStackTrace(error, filteredStack); + } + + return filteredStack.map(frame => ` at ${frame}`).join('\n'); + }; + } catch (e) {} + // ------------------------------------------------------------------------- // Готово — все патчи применены // -------------------------------------------------------------------------