Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix: SIGTERM fallback for orphaned daemons in close command
ShawnPanaac48ebecafc2
diff --git a/browser_use/skill_cli/daemon.py b/browser_use/skill_cli/daemon.pyindex a8f578de5..c36afcdc9 100644--- a/browser_use/skill_cli/daemon.py+++ b/browser_use/skill_cli/daemon.py@@ -503,8 +503,8 @@ class Daemon:logger.warning(f'Error closing session: {e}')self._session = None- # Clean up PID file before exiting — the finally block in run() won't- # execute because os._exit() bypasses it.+ # Delete PID file last, right before exit. If browser cleanup hangs above,+ # the PID file still exists so `sessions` can discover the orphaned daemon.import osfrom browser_use.skill_cli.utils import get_pid_pathdiff --git a/browser_use/skill_cli/main.py b/browser_use/skill_cli/main.pyindex 2fd00552a..01f88bd5b 100755--- a/browser_use/skill_cli/main.py+++ b/browser_use/skill_cli/main.py@@ -11,6 +11,7 @@ import asyncioimport jsonimport osimport re+import signalimport socketimport subprocessimport sys@@ -1070,10 +1071,27 @@ def main() -> int:except Exception:print('Browser closed')else:+ # Socket unreachable — check if a PID file references a live process+ # (orphaned daemon that lost its socket). Kill it directly.+ pid_path = Path(_get_home_dir()) / f'{session}.pid'+ killed = False+ if pid_path.exists():+ try:+ pid = int(pid_path.read_text().strip())+ os.kill(pid, 0) # Check alive+ os.kill(pid, signal.SIGTERM)+ killed = True+ except (OSError, ProcessLookupError, ValueError):+ pass+ pid_path.unlink(missing_ok=True)+if args.json:print(json.dumps({'success': True, 'data': {'shutdown': True}}))else:- print('No active browser session')+ if killed:+ print('Browser closed')+ else:+ print('No active browser session')return 0# Resolve --connect to agent_id + CDP URL