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: suppress cloud sync URLs when BROWSER_USE_CLOUD_SYNC=false
Saurav Panda1d21e72d4ac7
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 2a46efc12..543119ec8 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -424,6 +424,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):self.cloud_sync = cloud_sync or CloudSync()# Register cloud sync handlerself.eventbus.on('*', self.cloud_sync.handle_event)+ else:+ self.cloud_sync = Noneif self.settings.save_conversation_path:self.settings.save_conversation_path = Path(self.settings.save_conversation_path).expanduser().resolve()@@ -835,15 +837,16 @@ class Agent(Generic[Context, AgentStructuredOutput]):action_dict = action.model_dump() if hasattr(action, 'model_dump') else {}actions_data.append(action_dict)- # Emit CreateAgentStepEvent- step_event = CreateAgentStepEvent.from_agent_step(- self,- self.state.last_model_output,- self.state.last_result,- actions_data,- browser_state_summary,- )- self.eventbus.dispatch(step_event)+ # Emit CreateAgentStepEvent only if cloud sync is enabled+ if self.enable_cloud_sync:+ step_event = CreateAgentStepEvent.from_agent_step(+ self,+ self.state.last_model_output,+ self.state.last_result,+ actions_data,+ browser_state_summary,+ )+ self.eventbus.dispatch(step_event)# Increment step counter after step is fully completedself.state.n_steps += 1@@ -1415,18 +1418,20 @@ class Agent(Generic[Context, AgentStructuredOutput]):# Only dispatch session events if this is the first runif not self.state.session_initialized:- self.logger.debug('π‘ Dispatching CreateAgentSessionEvent...')- # Emit CreateAgentSessionEvent at the START of run()- self.eventbus.dispatch(CreateAgentSessionEvent.from_agent(self))+ if self.enable_cloud_sync:+ self.logger.debug('π‘ Dispatching CreateAgentSessionEvent...')+ # Emit CreateAgentSessionEvent at the START of run()+ self.eventbus.dispatch(CreateAgentSessionEvent.from_agent(self))- self.state.session_initialized = True+ # Brief delay to ensure session is created in backend before sending task+ await asyncio.sleep(0.2)- # Brief delay to ensure session is created in backend before sending task- await asyncio.sleep(0.2)+ self.state.session_initialized = True- self.logger.debug('π‘ Dispatching CreateAgentTaskEvent...')- # Emit CreateAgentTaskEvent at the START of run()- self.eventbus.dispatch(CreateAgentTaskEvent.from_agent(self))+ if self.enable_cloud_sync:+ self.logger.debug('π‘ Dispatching CreateAgentTaskEvent...')+ # Emit CreateAgentTaskEvent at the START of run()+ self.eventbus.dispatch(CreateAgentTaskEvent.from_agent(self))# Start browser session and attach watchdogsassert self.browser_session is not None, 'Browser session must be initialized before starting'@@ -1572,7 +1577,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):# not when they are completed# Emit UpdateAgentTaskEvent at the END of run() with final task state- self.eventbus.dispatch(UpdateAgentTaskEvent.from_agent(self))+ if self.enable_cloud_sync:+ self.eventbus.dispatch(UpdateAgentTaskEvent.from_agent(self))# Generate GIF if needed before stopping event busif self.settings.generate_gif:@@ -1591,7 +1597,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):self.eventbus.dispatch(output_event)# Wait briefly for cloud auth to start and print the URL, but don't block for completion- if self.enable_cloud_sync and hasattr(self, 'cloud_sync'):+ if self.enable_cloud_sync and hasattr(self, 'cloud_sync') and self.cloud_sync is not None:if self.cloud_sync.auth_task and not self.cloud_sync.auth_task.done():try:# Wait up to 1 second for auth to start and print URLdiff --git a/browser_use/sync/auth.py b/browser_use/sync/auth.pyindex 70a790cde..96935c26c 100644--- a/browser_use/sync/auth.py+++ b/browser_use/sync/auth.py@@ -297,7 +297,7 @@ class DeviceAuthClient:verification_uri_complete = device_auth['verification_uri_complete'].replace(self.base_url, frontend_url)terminal_width, _terminal_height = shutil.get_terminal_size((80, 20))- if show_instructions:+ if show_instructions and CONFIG.BROWSER_USE_CLOUD_SYNC:logger.info('β' * max(terminal_width - 40, 20))logger.info('π View the details of this run in Browser Use Cloud:')logger.info(f' π {verification_uri_complete}')diff --git a/browser_use/sync/service.py b/browser_use/sync/service.pyindex 863042342..b4eb24872 100644--- a/browser_use/sync/service.py+++ b/browser_use/sync/service.py@@ -26,10 +26,16 @@ class CloudSync:self.session_id: str | None = Noneself.allow_session_events_for_auth = allow_session_events_for_authself.auth_flow_active = False # Flag to indicate auth flow is running+ # Check if cloud sync is actually enabled - if not, we should remain silent+ self.enabled = CONFIG.BROWSER_USE_CLOUD_SYNCasync def handle_event(self, event: BaseEvent) -> None:"""Handle an event by sending it to the cloud"""try:+ # If cloud sync is disabled, don't handle any events+ if not self.enabled:+ return+# Extract session ID from CreateAgentSessionEventif event.event_type == 'CreateAgentSessionEvent' and hasattr(event, 'id'):self.session_id = str(event.id) # type: ignore@@ -121,6 +127,10 @@ class CloudSync:assert self.auth_client, 'auth_client must exist before calling CloudSync._background_auth()'assert self.session_id, 'session_id must be set before calling CloudSync._background_auth() can fire'try:+ # Only show cloud URLs if cloud sync is enabled+ if not self.enabled:+ return+# Always show the cloud URL (auth happens immediately when session starts now)frontend_url = CONFIG.BROWSER_USE_CLOUD_UI_URL or self.base_url.replace('//api.', '//cloud.')session_url = f'{frontend_url.rstrip("/")}/agent/{agent_session_id}'@@ -188,6 +198,10 @@ class CloudSync:async def authenticate(self, show_instructions: bool = True) -> bool:"""Authenticate with the cloud service"""+ # If cloud sync is disabled, don't authenticate+ if not self.enabled:+ return False+# Check if already authenticated firstif self.auth_client.is_authenticated:import logging