diff --git a/app.py b/app.py index df767ff..56bd803 100644 --- a/app.py +++ b/app.py @@ -465,7 +465,14 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str): raise RuntimeError(f"Failed to start Chrome at {internal_cdp_url}") # Обновляем cdp_url для Browser - cdp_url = internal_cdp_url + # Если Chrome уже был запущен - используем external port (через socat) + # Если Chrome был запущен нами - используем internal port + if chrome_already_running: + cdp_url = f"http://127.0.0.1:{REMOTE_DEBUGGING_PORT}" + logger.info(f"[{task_id}] Using existing Chrome on external port {REMOTE_DEBUGGING_PORT}") + else: + cdp_url = internal_cdp_url + logger.info(f"[{task_id}] Using new Chrome on internal port {CHROME_INTERNAL_PORT}") # Инжектируем stealth-скрипты через CDP для дополнительной защиты try: diff --git a/stealth-extension/stealth.js b/stealth-extension/stealth.js index e535e78..80131c4 100644 --- a/stealth-extension/stealth.js +++ b/stealth-extension/stealth.js @@ -565,63 +565,23 @@ // ------------------------------------------------------------------------- try { const OriginalAudioContext = window.AudioContext || window.webkitAudioContext; - if (OriginalAudioContext) { + if (OriginalAudioContext && OriginalAudioContext.prototype && OriginalAudioContext.prototype.resume) { 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) {} + // Патчим prototype resume + OriginalAudioContext.prototype.resume = function() { + try { + if (this.state === 'suspended') { + return originalResume.call(this).catch(function() {}); + } + return Promise.resolve(); + } catch(e) { + return Promise.resolve(); } - 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) {} - // ------------------------------------------------------------------------- // Готово — все патчи применены // -------------------------------------------------------------------------