diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc index fd0f822..2e2fcf3 100644 Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ diff --git a/app.py b/app.py index 2ca43a5..88e2ed7 100644 --- a/app.py +++ b/app.py @@ -128,8 +128,22 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str): stderr=subprocess.DEVNULL ) - # Даем браузеру время запуститься - await asyncio.sleep(3) + # Даем браузеру время запуститься и проверяем CDP + import time + import urllib.request + cdp_ready = False + for i in range(15): # Ждем до 15 секунд + await asyncio.sleep(1) + try: + response = urllib.request.urlopen(f"http://localhost:{REMOTE_DEBUGGING_PORT}/json/version", timeout=1) + if response.status == 200: + cdp_ready = True + break + except: + pass + + if not cdp_ready: + raise RuntimeError(f"Chrome started but CDP not ready after 15s") # Подключаемся через CDP cdp_url = f"http://localhost:{REMOTE_DEBUGGING_PORT}"