Skip to content

Commit 1d21e72

Browse files
committed
fix: suppress cloud sync URLs when BROWSER_USE_CLOUD_SYNC=false
1 parent f4bbb9c commit 1d21e72

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

browser_use/agent/service.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ def __init__(
424424
self.cloud_sync = cloud_sync or CloudSync()
425425
# Register cloud sync handler
426426
self.eventbus.on('*', self.cloud_sync.handle_event)
427+
else:
428+
self.cloud_sync = None
427429

428430
if self.settings.save_conversation_path:
429431
self.settings.save_conversation_path = Path(self.settings.save_conversation_path).expanduser().resolve()
@@ -835,15 +837,16 @@ async def _finalize(self, browser_state_summary: BrowserStateSummary | None) ->
835837
action_dict = action.model_dump() if hasattr(action, 'model_dump') else {}
836838
actions_data.append(action_dict)
837839

838-
# Emit CreateAgentStepEvent
839-
step_event = CreateAgentStepEvent.from_agent_step(
840-
self,
841-
self.state.last_model_output,
842-
self.state.last_result,
843-
actions_data,
844-
browser_state_summary,
845-
)
846-
self.eventbus.dispatch(step_event)
840+
# Emit CreateAgentStepEvent only if cloud sync is enabled
841+
if self.enable_cloud_sync:
842+
step_event = CreateAgentStepEvent.from_agent_step(
843+
self,
844+
self.state.last_model_output,
845+
self.state.last_result,
846+
actions_data,
847+
browser_state_summary,
848+
)
849+
self.eventbus.dispatch(step_event)
847850

848851
# Increment step counter after step is fully completed
849852
self.state.n_steps += 1
@@ -1415,18 +1418,20 @@ def on_force_exit_log_telemetry():
14151418

14161419
# Only dispatch session events if this is the first run
14171420
if not self.state.session_initialized:
1418-
self.logger.debug('📡 Dispatching CreateAgentSessionEvent...')
1419-
# Emit CreateAgentSessionEvent at the START of run()
1420-
self.eventbus.dispatch(CreateAgentSessionEvent.from_agent(self))
1421+
if self.enable_cloud_sync:
1422+
self.logger.debug('📡 Dispatching CreateAgentSessionEvent...')
1423+
# Emit CreateAgentSessionEvent at the START of run()
1424+
self.eventbus.dispatch(CreateAgentSessionEvent.from_agent(self))
14211425

1422-
self.state.session_initialized = True
1426+
# Brief delay to ensure session is created in backend before sending task
1427+
await asyncio.sleep(0.2)
14231428

1424-
# Brief delay to ensure session is created in backend before sending task
1425-
await asyncio.sleep(0.2)
1429+
self.state.session_initialized = True
14261430

1427-
self.logger.debug('📡 Dispatching CreateAgentTaskEvent...')
1428-
# Emit CreateAgentTaskEvent at the START of run()
1429-
self.eventbus.dispatch(CreateAgentTaskEvent.from_agent(self))
1431+
if self.enable_cloud_sync:
1432+
self.logger.debug('📡 Dispatching CreateAgentTaskEvent...')
1433+
# Emit CreateAgentTaskEvent at the START of run()
1434+
self.eventbus.dispatch(CreateAgentTaskEvent.from_agent(self))
14301435

14311436
# Start browser session and attach watchdogs
14321437
assert self.browser_session is not None, 'Browser session must be initialized before starting'
@@ -1572,7 +1577,8 @@ def on_force_exit_log_telemetry():
15721577
# not when they are completed
15731578

15741579
# Emit UpdateAgentTaskEvent at the END of run() with final task state
1575-
self.eventbus.dispatch(UpdateAgentTaskEvent.from_agent(self))
1580+
if self.enable_cloud_sync:
1581+
self.eventbus.dispatch(UpdateAgentTaskEvent.from_agent(self))
15761582

15771583
# Generate GIF if needed before stopping event bus
15781584
if self.settings.generate_gif:
@@ -1591,7 +1597,7 @@ def on_force_exit_log_telemetry():
15911597
self.eventbus.dispatch(output_event)
15921598

15931599
# Wait briefly for cloud auth to start and print the URL, but don't block for completion
1594-
if self.enable_cloud_sync and hasattr(self, 'cloud_sync'):
1600+
if self.enable_cloud_sync and hasattr(self, 'cloud_sync') and self.cloud_sync is not None:
15951601
if self.cloud_sync.auth_task and not self.cloud_sync.auth_task.done():
15961602
try:
15971603
# Wait up to 1 second for auth to start and print URL

browser_use/sync/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async def authenticate(
297297
verification_uri_complete = device_auth['verification_uri_complete'].replace(self.base_url, frontend_url)
298298

299299
terminal_width, _terminal_height = shutil.get_terminal_size((80, 20))
300-
if show_instructions:
300+
if show_instructions and CONFIG.BROWSER_USE_CLOUD_SYNC:
301301
logger.info('─' * max(terminal_width - 40, 20))
302302
logger.info('🌐 View the details of this run in Browser Use Cloud:')
303303
logger.info(f' 👉 {verification_uri_complete}')

browser_use/sync/service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ def __init__(self, base_url: str | None = None, allow_session_events_for_auth: b
2626
self.session_id: str | None = None
2727
self.allow_session_events_for_auth = allow_session_events_for_auth
2828
self.auth_flow_active = False # Flag to indicate auth flow is running
29+
# Check if cloud sync is actually enabled - if not, we should remain silent
30+
self.enabled = CONFIG.BROWSER_USE_CLOUD_SYNC
2931

3032
async def handle_event(self, event: BaseEvent) -> None:
3133
"""Handle an event by sending it to the cloud"""
3234
try:
35+
# If cloud sync is disabled, don't handle any events
36+
if not self.enabled:
37+
return
38+
3339
# Extract session ID from CreateAgentSessionEvent
3440
if event.event_type == 'CreateAgentSessionEvent' and hasattr(event, 'id'):
3541
self.session_id = str(event.id) # type: ignore
@@ -121,6 +127,10 @@ async def _background_auth(self, agent_session_id: str) -> None:
121127
assert self.auth_client, 'auth_client must exist before calling CloudSync._background_auth()'
122128
assert self.session_id, 'session_id must be set before calling CloudSync._background_auth() can fire'
123129
try:
130+
# Only show cloud URLs if cloud sync is enabled
131+
if not self.enabled:
132+
return
133+
124134
# Always show the cloud URL (auth happens immediately when session starts now)
125135
frontend_url = CONFIG.BROWSER_USE_CLOUD_UI_URL or self.base_url.replace('//api.', '//cloud.')
126136
session_url = f'{frontend_url.rstrip("/")}/agent/{agent_session_id}'
@@ -188,6 +198,10 @@ def set_auth_flow_active(self) -> None:
188198

189199
async def authenticate(self, show_instructions: bool = True) -> bool:
190200
"""Authenticate with the cloud service"""
201+
# If cloud sync is disabled, don't authenticate
202+
if not self.enabled:
203+
return False
204+
191205
# Check if already authenticated first
192206
if self.auth_client.is_authenticated:
193207
import logging

0 commit comments

Comments
 (0)