Skip to content

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

add timeout to sync auth setup

Nick Sweeting8af870664649
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index a924c923a..e066af322 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -1263,11 +1263,16 @@ class Agent(Generic[Context]):
output_event = await CreateAgentOutputFileEvent.from_agent_and_file(self, output_path)
self.eventbus.dispatch(output_event)
- # Don't block waiting for cloud auth - let it complete in background
- # The auth_task will continue running even after agent finishes
+ # 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.cloud_sync.auth_task and not self.cloud_sync.auth_task.done():
- logger.info('Cloud authentication still in progress - continuing in background')
+ try:
+ # Wait up to 1 second for auth to start and print URL
+ await asyncio.wait_for(self.cloud_sync.auth_task, timeout=1.0)
+ except TimeoutError:
+ logger.info('Cloud authentication started - continuing in background')
+ except Exception as e:
+ logger.debug(f'Cloud authentication error: {e}')
# Stop the event bus gracefully, waiting for all events to be processed
# Use longer timeout to avoid deadlocks in tests with multiple agents
diff --git a/browser_use/sync/auth.py b/browser_use/sync/auth.py
index 11d9cc7cb..1f2890e26 100644
--- a/browser_use/sync/auth.py
+++ b/browser_use/sync/auth.py
@@ -319,18 +319,20 @@ class DeviceAuthClient:
return True
- except Exception as e:
- # Log the error details for debugging
- if hasattr(e, 'response'):
- response = getattr(e, 'response')
- if hasattr(response, 'status_code') and hasattr(response, 'text'):
- logger.debug(
- f'Failed to get pre-auth token for cloud sync: HTTP {response.request.url} {response.status_code} - {response.text}'
- )
- else:
- logger.debug(f'Failed to get pre-auth token for cloud sync: {type(e).__name__}: {e}')
+ except httpx.HTTPStatusError as e:
+ # HTTP error with response
+ if e.response.status_code == 404:
+ logger.warning(
+ 'Cloud sync authentication endpoint not found (404). Check your BROWSER_USE_CLOUD_API_URL setting.'
+ )
else:
- logger.debug(f'Failed to get pre-auth token for cloud sync: {type(e).__name__}: {e}')
+ logger.warning(f'Failed to authenticate with cloud service: HTTP {e.response.status_code} - {e.response.text}')
+ except httpx.RequestError as e:
+ # Connection/network errors
+ logger.warning(f'Failed to connect to cloud service: {type(e).__name__}: {e}')
+ except Exception as e:
+ # Other unexpected errors
+ logger.warning(f'Unexpected error during cloud authentication: {type(e).__name__}: {e}')
if show_instructions:
logger.info('❌ Authentication failed or timed out')