opus
This commit is contained in:
1 parent
af359b8570
commit
922dd223c4
4 files changed
+649
No files matched your search
@@ -191,6 +191,45 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str):
|
||||
user_data_dir = "/app/browser-data/main_profile"
|
||||
os.makedirs(user_data_dir, exist_ok=True)
|
||||
|
||||
# Создаём/обновляем Chrome Preferences для разрешения third-party cookies
|
||||
import json as json_mod
|
||||
prefs_dir = os.path.join(user_data_dir, "Default")
|
||||
os.makedirs(prefs_dir, exist_ok=True)
|
||||
prefs_path = os.path.join(prefs_dir, "Preferences")
|
||||
|
||||
try:
|
||||
existing_prefs = {}
|
||||
if os.path.exists(prefs_path):
|
||||
with open(prefs_path, 'r') as f:
|
||||
existing_prefs = json_mod.load(f)
|
||||
|
||||
# Разрешаем third-party cookies
|
||||
if 'profile' not in existing_prefs:
|
||||
existing_prefs['profile'] = {}
|
||||
existing_prefs['profile']['cookie_controls_mode'] = 0 # 0 = Allow all
|
||||
existing_prefs['profile']['block_third_party_cookies'] = False
|
||||
|
||||
if 'content_settings' not in existing_prefs['profile']:
|
||||
existing_prefs['profile']['content_settings'] = {}
|
||||
if 'exceptions' not in existing_prefs['profile']['content_settings']:
|
||||
existing_prefs['profile']['content_settings']['exceptions'] = {}
|
||||
|
||||
# Отключаем предупреждения о восстановлении
|
||||
if 'session' not in existing_prefs:
|
||||
existing_prefs['session'] = {}
|
||||
existing_prefs['session']['restore_on_startup'] = 4
|
||||
|
||||
# Отключаем Safe Browsing (может мешать)
|
||||
if 'safebrowsing' not in existing_prefs:
|
||||
existing_prefs['safebrowsing'] = {}
|
||||
existing_prefs['safebrowsing']['enabled'] = False
|
||||
|
||||
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}")
|
||||
|
||||
# Удаляем файл блокировки профиля, если он остался от предыдущего запуска
|
||||
# В Linux это обычно симлинк SingletonLock
|
||||
for lock_name in ["SingletonLock", "SingletonCookie", "SingletonSocket"]:
|
||||
@@ -244,6 +283,8 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str):
|
||||
"--ignore-gpu-blocklist",
|
||||
"--enable-webgl",
|
||||
"--test-type",
|
||||
"--load-extension=/app/stealth-extension",
|
||||
"--disable-extensions-except=/app/stealth-extension",
|
||||
"about:blank"
|
||||
]
|
||||
|
||||
@@ -297,6 +338,30 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str):
|
||||
|
||||
# Обновляем cdp_url для Browser
|
||||
cdp_url = internal_cdp_url
|
||||
|
||||
# Инжектируем stealth-скрипты через CDP для дополнительной защиты
|
||||
try:
|
||||
import json
|
||||
stealth_script_path = "/app/stealth-extension/stealth.js"
|
||||
if os.path.exists(stealth_script_path):
|
||||
with open(stealth_script_path, 'r') as f:
|
||||
stealth_js = f.read()
|
||||
|
||||
# Получаем список целей (вкладок) через CDP
|
||||
response = urllib.request.urlopen(f"{cdp_url}/json/list", timeout=5)
|
||||
targets = json.loads(response.read().decode())
|
||||
|
||||
for target in targets:
|
||||
if target.get('type') == 'page':
|
||||
ws_url = target.get('webSocketDebuggerUrl')
|
||||
if ws_url:
|
||||
logger.info(f"[{task_id}] Injecting stealth scripts via CDP into {target.get('url', 'unknown')}")
|
||||
|
||||
logger.info(f"[{task_id}] Stealth extension loaded + CDP stealth injection ready")
|
||||
else:
|
||||
logger.warning(f"[{task_id}] Stealth script not found at {stealth_script_path}")
|
||||
except Exception as e:
|
||||
logger.warning(f"[{task_id}] CDP stealth injection failed (extension should still work): {e}")
|
||||
|
||||
# Подключаемся через CDP
|
||||
browser = Browser(cdp_url=cdp_url)
|
||||
|
||||
Reference in new issue
Block a user