From 64f79d4fa8e9cf4e36f44886a0030644a2a35697 Mon Sep 17 00:00:00 2001 From: David Piccinini Date: Sun, 17 May 2026 03:59:49 -0300 Subject: [PATCH] fix: use separate user-data-dir for CDP browser to avoid conflicts with existing instances When Edge/Chrome is already running, a new instance with --remote-debugging-port joins the existing process instead of starting CDP. Using a dedicated profile dir forces a separate process. Also retry CDP port check up to 6 seconds. Co-Authored-By: Claude Opus 4.6 --- easybot_windows_agent/main.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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: