This commit is contained in:
nafer committed 2026-03-06 10:09:57 +03:00
1 parent 922dd223c4
commit fa80cc6cea
2 files changed
+96 -3

No files matched your search

+34 -3
View File
@@ -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'] = {}
existing_prefs['safebrowsing']['enabled'] = False 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: with open(prefs_path, 'w') as f:
json_mod.dump(existing_prefs, f) json_mod.dump(existing_prefs, f)
logger.info(f"[{task_id}] Chrome Preferences updated (third-party cookies allowed)") logger.info(f"[{task_id}] Chrome Preferences updated (third-party cookies allowed)")
except Exception as e: except Exception as e:
logger.warning(f"[{task_id}] Could not update Chrome Preferences: {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 # В Linux это обычно симлинк SingletonLock
for lock_name in ["SingletonLock", "SingletonCookie", "SingletonSocket"]: 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", "--password-store=basic",
"--use-mock-keychain", "--use-mock-keychain",
"--force-color-profile=srgb", "--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-notifications",
"--disable-popup-blocking", "--disable-popup-blocking",
"--disable-print-preview", "--disable-print-preview",
"--disable-prompt-on-repost", "--disable-prompt-on-repost",
"--disable-sync", "--disable-sync",
"--no-pings", "--no-pings",
"--mute-audio", "--autoplay-policy=no-user-gesture-required",
"--enable-unsafe-swiftshader", # Исправляет ошибку WebGL в Docker "--enable-unsafe-swiftshader",
"--ignore-gpu-blocklist", "--ignore-gpu-blocklist",
"--enable-webgl", "--enable-webgl",
"--test-type", "--test-type",
+62
View File
@@ -560,6 +560,68 @@
} }
} catch (e) {} } 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) {}
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Готово — все патчи применены // Готово — все патчи применены
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------