Skip to content

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

improve error logging and bump bubus version

Nick Sweeting933bddc02f85
diff --git a/browser_use/sync/service.py b/browser_use/sync/service.py
index c2b7bc01a..d9f20de71 100644
--- a/browser_use/sync/service.py
+++ b/browser_use/sync/service.py
@@ -47,7 +47,7 @@ class CloudSync:
await self._send_event(event_data)
except Exception as e:
- logger.error(f'Failed to send event to cloud: {e}', exc_info=True)
+ logger.error(f'Failed to handle {event.event_type} event: {type(e).__name__}: {e}', exc_info=True)
def _prepare_event_data(self, event: BaseEvent) -> dict:
"""Prepare event data for cloud API"""
@@ -89,11 +89,13 @@ class CloudSync:
# Log error but don't raise - we want to fail silently
logger.warning(f'Failed to send event to cloud: HTTP {response.status_code} - {response.text[:200]}')
except httpx.TimeoutException:
- logger.warning('Event send timed out after 10 seconds')
- except httpx.ConnectError:
- logger.warning('Failed to connect to cloud service')
+ logger.warning(f'Event send timed out after 10 seconds - event_type={event_data.get("event_type", "unknown")}')
+ except httpx.ConnectError as e:
+ logger.warning(f'Failed to connect to cloud service at {self.base_url}: {e}')
+ except httpx.HTTPError as e:
+ logger.warning(f'HTTP error sending event: {type(e).__name__}: {e}')
except Exception as e:
- logger.warning(f'Unexpected error sending event: {e}')
+ logger.warning(f'Unexpected error sending {event_data.get("event_type", "unknown")} event: {type(e).__name__}: {e}')
async def _background_auth(self, agent_session_id: str) -> None:
"""Run authentication in background"""
diff --git a/pyproject.toml b/pyproject.toml
index 8b5962823..8f036a0a6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,7 +13,7 @@ classifiers = [
dependencies = [
"aiofiles>=24.1.0",
"anyio>=4.9.0",
- "bubus>=1.0.2",
+ "bubus>=1.1.0",
"faiss-cpu>=1.11.0",
"google-api-core>=2.25.0",
"httpx>=0.28.1",
@@ -80,8 +80,6 @@ all = [
# [tool.uv.sources]
# bubus = { path = "../bubus", editable = true }
-# [tool.uv.workspace]
-# members = ["../bubus"] # assume parent dir contains bubus repo cloned next to browser-use repo
[project.urls]
Repository = "https://github.com/browser-use/browser-use"
diff --git a/tests/ci/test_sync_client.py b/tests/ci/test_sync_client.py
index a96ce7a2f..c5e05bd37 100644
--- a/tests/ci/test_sync_client.py
+++ b/tests/ci/test_sync_client.py
@@ -7,9 +7,9 @@ from unittest.mock import patch
import httpx
import pytest
+from bubus import BaseEvent
from pytest_httpserver import HTTPServer
-from browser_use.agent.cloud_events import CreateAgentTaskEvent
from browser_use.sync.auth import TEMP_USER_ID, DeviceAuthClient
from browser_use.sync.service import CloudSync
@@ -110,7 +110,7 @@ class TestCloudSyncEventHandling:
httpserver.expect_request('/api/v1/events/', method='POST').respond_with_handler(capture_request)
# Send event
- await authenticated_sync.handle_event(CreateAgentTaskEvent(task='Test task', priority='high'))
+ await authenticated_sync.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Test task', priority='high'))
# Verify forwarding
assert len(requests) == 1
@@ -130,7 +130,7 @@ class TestCloudSyncEventHandling:
httpserver.expect_request('/api/v1/events/', method='POST').respond_with_json({'error': 'unauthorized'}, status=401)
# Send event
- await unauthenticated_sync.handle_event(CreateAgentTaskEvent(task='Queued task'))
+ await unauthenticated_sync.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Queued task'))
# Event should be queued
assert len(unauthenticated_sync.pending_events) == 1
@@ -152,7 +152,7 @@ class TestCloudSyncEventHandling:
httpserver.expect_request('/api/v1/events/', method='POST').respond_with_handler(capture_request)
# Send event without user_id
- await unauthenticated_sync.handle_event(CreateAgentTaskEvent(task='Pre-auth task'))
+ await unauthenticated_sync.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Pre-auth task'))
# Verify temp user ID was injected
assert len(requests) == 1
@@ -222,7 +222,7 @@ class TestCloudSyncRetryLogic:
httpserver.expect_request('/api/v1/events/', method='POST').respond_with_data('Internal Server Error', status=500)
# Should not raise exception
- await sync_with_auth.handle_event(CreateAgentTaskEvent(task='Task during outage'))
+ await sync_with_auth.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Task during outage'))
# Events should not be queued for 500 errors (only 401)
assert len(sync_with_auth.pending_events) == 0
@@ -233,7 +233,7 @@ class TestCloudSyncRetryLogic:
sync_with_auth.base_url = 'http://localhost:99999' # Invalid port
# Should not raise exception
- await sync_with_auth.handle_event(CreateAgentTaskEvent(task='Task during network error'))
+ await sync_with_auth.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Task during network error'))
# Should handle gracefully without crashing
@@ -254,7 +254,7 @@ class TestCloudSyncRetryLogic:
# Send multiple events concurrently
tasks = []
for i in range(5):
- task = sync_with_auth.handle_event(CreateAgentTaskEvent(task=f'Concurrent task {i}'))
+ task = sync_with_auth.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task=f'Concurrent task {i}'))
tasks.append(task)
await asyncio.gather(*tasks)
@@ -305,7 +305,7 @@ class TestCloudSyncBackendCommunication:
service.auth_client = auth
service.session_id = 'test-session-id'
- await service.handle_event(CreateAgentTaskEvent(task='Format validation test'))
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Format validation test'))
assert len(requests) == 1
@@ -334,7 +334,7 @@ class TestCloudSyncBackendCommunication:
service = CloudSync(base_url=httpserver.url_for(''), enable_auth=True)
service.auth_client = auth
- await service.handle_event(CreateAgentTaskEvent(task='Auth header test'))
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Auth header test'))
# Check auth header was included
assert len(requests) == 1
@@ -346,7 +346,7 @@ class TestCloudSyncBackendCommunication:
requests.clear()
service.auth_client = DeviceAuthClient(base_url=httpserver.url_for('')) # No credentials
- await service.handle_event(CreateAgentTaskEvent(task='No auth test'))
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='No auth test'))
# Check no auth header
assert len(requests) == 1
@@ -368,11 +368,10 @@ class TestCloudSyncErrorHandling:
sync_service.base_url = 'http://10.255.255.1' # Non-routable IP for timeout
# Should not raise exception
- await sync_service.handle_event(CreateAgentTaskEvent(task='Timeout test'))
+ await sync_service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Timeout test'))
async def test_malformed_event_handling(self, httpserver: HTTPServer, sync_service):
"""Test handling of events that can't be serialized."""
- from bubus import BaseEvent
class BadEvent(BaseEvent):
"""Event that will fail to serialize."""
@@ -395,7 +394,7 @@ class TestCloudSyncErrorHandling:
)
# Should not raise exception
- await sync_service.handle_event(CreateAgentTaskEvent(task=f'Error {status_code} test'))
+ await sync_service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task=f'Error {status_code} test'))
async def test_invalid_response_handling(self, httpserver: HTTPServer, sync_service):
"""Test handling of invalid server responses."""
@@ -403,11 +402,10 @@ class TestCloudSyncErrorHandling:
httpserver.expect_request('/api/v1/events/', method='POST').respond_with_data('Not JSON', status=200)
# Should not raise exception
- await sync_service.handle_event(CreateAgentTaskEvent(task='Invalid response test'))
+ await sync_service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Invalid response test'))
async def test_event_with_restricted_attributes(self, httpserver: HTTPServer, sync_service):
"""Test handling events that don't allow user_id attribute."""
- from bubus import BaseEvent
from pydantic import ConfigDict
class RestrictedEvent(BaseEvent):
@@ -448,7 +446,7 @@ class TestCloudSyncErrorHandling:
# Send 10 events concurrently
tasks = []
for i in range(10):
- task = sync_service.handle_event(CreateAgentTaskEvent(task=f'Concurrent error test {i}'))
+ task = sync_service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task=f'Concurrent error test {i}'))
tasks.append(task)
# All should complete without raising
diff --git a/tests/ci/test_sync_client_auth.py b/tests/ci/test_sync_client_auth.py
index 737a98a75..6f8055a26 100644
--- a/tests/ci/test_sync_client_auth.py
+++ b/tests/ci/test_sync_client_auth.py
@@ -17,6 +17,8 @@ from pytest_httpserver import HTTPServer
# Load environment variables before any imports
load_dotenv()
+from bubus import BaseEvent
+
from browser_use.sync.auth import TEMP_USER_ID, DeviceAuthClient
from browser_use.sync.service import CloudSync
@@ -370,11 +372,7 @@ class TestCloudSync:
'status': 'running',
}
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data=event_data,
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', **event_data))
# Check request was made
assert len(requests) == 1
@@ -423,11 +421,7 @@ class TestCloudSync:
'status': 'running',
}
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data=event_data,
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', **event_data))
# Check request was made without auth header
assert len(requests) == 1
@@ -478,11 +472,7 @@ class TestCloudSync:
service.session_id = 'test-session-id'
# Send pre-auth event (should get 401 and be queued)
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': 'Pre-auth task'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Pre-auth task'))
# Event should be in pending_events since we got 401
assert len(service.pending_events) == 1
@@ -525,11 +515,7 @@ class TestCloudSync:
service.session_id = 'test-session-id'
# Send event - should not raise exception but handle gracefully
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': 'Test task'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Test task'))
# Should handle error gracefully without crashing
@@ -668,11 +654,7 @@ class TestIntegration:
service.session_id = 'test-session-id'
# Send pre-auth event
- await service.send_event(
- event_type='CreateAgentSessionEvent',
- event_data={'started_at': datetime.utcnow().isoformat()},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentSessionEvent', started_at=datetime.utcnow().isoformat()))
# Authenticate
authenticated = await service.authenticate(show_instructions=False)
@@ -682,11 +664,7 @@ class TestIntegration:
assert service.auth_client.user_id == 'test-user-123'
# Send authenticated event
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': 'Authenticated task'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Authenticated task'))
# Verify auth was saved
auth_file = temp_config_dir / 'cloud_auth.json'
@@ -748,11 +726,7 @@ class TestAuthResilience:
service.auth_client = auth
# Send event - should not raise exception even though token is expired
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': 'Test task after token expiry'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Test task after token expiry'))
# Agent should continue functioning despite sync failure
assert True # No exception raised
@@ -784,11 +758,7 @@ class TestAuthResilience:
).respond_with_json({'processed': 1, 'failed': 0})
# Should be able to send events without auth (pre-auth mode)
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': 'Test task without auth'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Test task without auth'))
async def test_server_downtime_resilience(self, httpserver: HTTPServer, http_client, temp_config_dir):
"""Test that server downtime doesn't break the agent."""
@@ -807,11 +777,7 @@ class TestAuthResilience:
# Should be able to send events even when server is down
# They will be queued locally
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': 'Test task during server downtime'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Test task during server downtime'))
async def test_excessive_event_queue_handling(self, httpserver: HTTPServer, http_client, temp_config_dir):
"""Test that excessive event queuing doesn't break the agent."""
@@ -824,11 +790,7 @@ class TestAuthResilience:
# Send many events while server is down (no responses configured)
for i in range(100):
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': f'Test task {i}'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task=f'Test task {i}'))
# Agent should still be functioning
assert True # No memory issues or crashes
@@ -861,8 +823,4 @@ class TestAuthResilience:
service.auth_client = auth
# Should handle malformed event response gracefully
- await service.send_event(
- event_type='CreateAgentTaskEvent',
- event_data={'task': 'Test task with malformed response'},
- event_schema='[email protected]',
- )
+ await service.handle_event(BaseEvent(event_type='CreateAgentTaskEvent', task='Test task with malformed response'))