diff --git a/easybot_windows_agent/main.py b/easybot_windows_agent/main.py index 91f16bc..6ec45cb 100644 --- a/easybot_windows_agent/main.py +++ b/easybot_windows_agent/main.py @@ -623,11 +623,29 @@ async def tool_open_browser(args: dict[str, Any]) -> dict[str, Any]: async def tool_close_browser(args: dict[str, Any]) -> dict[str, Any]: """Close the CDP browser.""" global _browser_process + killed = False + # Try tracked process first if _browser_process and _browser_process.poll() is None: _browser_process.terminate() _browser_process = None - return {"success": True} - return {"success": True, "message": "No browser was running"} + killed = True + # Also kill any orphaned CDP browser by profile dir (survives agent restarts) + import tempfile + cdp_profile = os.path.join(tempfile.gettempdir(), "easybot_cdp_profile") + try: + import subprocess as _sp + result = _sp.run( + ["powershell", "-Command", + f"Get-Process msedge,chrome -ErrorAction SilentlyContinue | " + f"Where-Object {{$_.CommandLine -like '*easybot_cdp_profile*'}} | " + f"Stop-Process -Force"], + capture_output=True, timeout=5, + ) + if result.returncode == 0: + killed = True + except Exception: + pass + return {"success": True} if killed else {"success": True, "message": "No browser was running"} # ── Tool Registry ────────────────────────────────────────────────────────────