diff --git a/easybot_windows_agent/main.py b/easybot_windows_agent/main.py index 11567c1..91f16bc 100644 --- a/easybot_windows_agent/main.py +++ b/easybot_windows_agent/main.py @@ -577,14 +577,29 @@ async def tool_open_browser(args: dict[str, Any]) -> dict[str, Any]: _browser_process.terminate() await asyncio.sleep(0.5) + # Use a separate user-data-dir to avoid conflicts with existing browser instances + import tempfile + cdp_profile = os.path.join(tempfile.gettempdir(), "easybot_cdp_profile") + os.makedirs(cdp_profile, exist_ok=True) + _browser_process = subprocess.Popen( [browser_exe, f"--remote-debugging-port={port}", - "--no-first-run", "--no-default-browser-check", url], + f"--user-data-dir={cdp_profile}", + "--no-first-run", "--no-default-browser-check", + "--disable-extensions", "--disable-popup-blocking", url], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0, ) - # Wait a bit for CDP to be ready - await asyncio.sleep(2) + # Wait for CDP to be ready (may take longer on first launch) + for _ in range(6): + await asyncio.sleep(1) + try: + reader, writer = await asyncio.open_connection("127.0.0.1", port) + writer.close() + await writer.wait_closed() + break + except OSError: + continue # Verify CDP is listening try: