Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Merge branch 'main' into feature/multi_thread_agent_execution

Nick Sweetinge481b3401b5e
diff --cc browser_use/agent/service.py
index 2352da219,b4c59166c..37770262b
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@@ -812,10 -853,20 +855,20 @@@ class Agent(Generic[Context])
"""Execute the task with maximum number of steps"""
loop = asyncio.get_event_loop()
+ agent_run_error: str | None = None # Initialize error tracking variable
+ self._force_exit_telemetry_logged = False # ADDED: Flag for custom telemetry on force exit
- # Set up the Ctrl+C signal handler with callbacks specific to this agent
+ # Set up the signal handler with callbacks specific to this agent
from browser_use.utils import SignalHandler
+ # Define the custom exit callback function for second CTRL+C
+ def on_force_exit_log_telemetry():
+ self._log_agent_event(max_steps=max_steps, agent_run_error='SIGINT: Cancelled by user')
+ # NEW: Call the flush method on the telemetry instance
+ if hasattr(self, 'telemetry') and self.telemetry:
+ self.telemetry.flush()
+ self._force_exit_telemetry_logged = True # Set the flag
+
signal_handler = SignalHandler(
loop=loop,
pause_callback=self.pause,