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
start auth flow on first step
Nick Sweeting12583f917d71
diff --git a/browser_use/sync/service.py b/browser_use/sync/service.pyindex 9de8870ea..2d0b99a1f 100644--- a/browser_use/sync/service.py+++ b/browser_use/sync/service.py@@ -32,13 +32,21 @@ class CloudSync:"""Handle an event by sending it to the cloud"""try:# Extract session ID from CreateAgentSessionEvent- if event.event_type == 'CreateAgentSession' and hasattr(event, 'id'):+ if event.event_type == 'CreateAgentSessionEvent' and hasattr(event, 'id'):self.session_id = str(event.id) # type: ignore- # Start authentication flow if enabled and not authenticated- if self.enable_auth and self.auth_client and not self.auth_client.is_authenticated:- # Start auth in background- self.auth_task = asyncio.create_task(self._background_auth(agent_session_id=self.session_id))+ # Start authentication flow on first step (after first LLM response)+ if event.event_type == 'CreateAgentStepEvent' and hasattr(event, 'step'):+ logger.debug(f'Got CreateAgentStepEvent with step={event.step}')+ # Only trigger on the first step (step=2 because n_steps is incremented before actions)+ if event.step == 2 and self.enable_auth and self.auth_client and not self.auth_client.is_authenticated:+ if not hasattr(self, 'auth_task') or self.auth_task is None:+ # Start auth in background+ if self.session_id:+ logger.info('Triggering auth on first step event')+ self.auth_task = asyncio.create_task(self._background_auth(agent_session_id=self.session_id))+ else:+ logger.warning('Cannot start auth - session_id not set yet')# Send event to cloudawait self._send_event(event)