Skip to content

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

tweak BrowserSession failure message details

Nick Sweetingd8c6876e0852
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index e64179203..14b0fdb79 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -739,10 +739,18 @@ class BrowserSession(BaseModel):
assert chrome_process.is_running(), 'Chrome process is not running'
args = chrome_process.cmdline()
debug_port = next((arg for arg in args if arg.startswith('--remote-debugging-port=')), '').split('=')[-1].strip()
- assert debug_port, (
- f'Could not find --remote-debugging-port=... to connect to in browser launch args: browser_pid={self.browser_pid} {args}'
- )
- # we could automatically relaunch the browser process with that arg added here, but they may have tabs open they dont want to lose
+ if not debug_port:
+ # provided pid is unusable, it's either not running or doesnt have an open debug port we can connect to
+ if '--remote-debugging-pipe' in args:
+ self.logger.error(
+ f'❌ Found --remote-debugging-pipe in browser launch args for browser_pid={self.browser_pid} but it was started by a different BrowserSession, cannot connect to it'
+ )
+ else:
+ self.logger.error(
+ f'❌ Could not find --remote-debugging-port=... to connect to in browser launch args for browser_pid={self.browser_pid}: {" ".join(args)}'
+ )
+ return
+
self.cdp_url = self.cdp_url or f'http://localhost:{debug_port}/'
self.logger.info(f'🌎 Connecting to existing local browser process: browser_pid={self.browser_pid} on {self.cdp_url}')
assert self.playwright is not None, 'playwright instance is None'
diff --git a/browser_use/sync/service.py b/browser_use/sync/service.py
index d9f20de71..571332d56 100644
--- a/browser_use/sync/service.py
+++ b/browser_use/sync/service.py
@@ -76,7 +76,7 @@ class CloudSync:
# Send event (batch format with direct BaseEvent serialization)
async with httpx.AsyncClient() as client:
response = await client.post(
- f'{self.base_url.rstrip("/")}/api/v1/events/',
+ f'{self.base_url.rstrip("/")}/api/v1/events',
json={'events': [event_data]},
headers=headers,
timeout=10.0,
diff --git a/eval/service.py b/eval/service.py
index b56416d74..0e6fcc8c9 100644
--- a/eval/service.py
+++ b/eval/service.py
@@ -1362,7 +1362,7 @@ async def cleanup_browser_safe(browser_session: BrowserSession):
"""Safe browser cleanup with timeout"""
try:
logger.debug('Browser cleanup: Starting close operation for session')
- await asyncio.wait_for(browser_session.close(), timeout=30)
+ await asyncio.wait_for(browser_session.kill(), timeout=30)
logger.debug('Browser cleanup: Close operation completed successfully')
except TimeoutError:
logger.warning('Browser cleanup: Timed out after 30 seconds')