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
clearer exception handling
Nick Sweeting848fdf8aad3e
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex e284fe9c5..5ef626c90 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -3323,7 +3323,7 @@ class BrowserSession(BaseModel):# Clean uptry:await asyncio.wait_for(cdp_session.detach(), timeout=1.0)- except (TimeoutError, Exception):+ except Exception:passawait temp_page.close()@@ -3389,7 +3389,7 @@ class BrowserSession(BaseModel):# Close the unresponsive page before returning# This is critical to prevent the recovery flow from hangingtry:- closed = await self._force_close_page_via_cdp(new_page.url)+ await self._force_close_page_via_cdp(new_page.url)except Exception as e:self.logger.error(f'❌ Failed to close crashed page {_log_pretty_url(url)} via CDP: {type(e).__name__}: {e} (something is very wrong or system is extremely overloaded)'@@ -3539,7 +3539,7 @@ class BrowserSession(BaseModel):# Always bring page to front before rendering, otherwise it crashes in some cases, not sure whytry:await page.bring_to_front()- except (Exception, TimeoutError):+ except Exception:pass# Take screenshot using CDP to get around playwright's unnecessary slowness and weird behavior@@ -3580,7 +3580,7 @@ class BrowserSession(BaseModel):if cdp_session:try:await asyncio.wait_for(cdp_session.detach(), timeout=1.0)- except (TimeoutError, Exception):+ except Exception:pass# region - User Actionsdiff --git a/browser_use/controller/views.py b/browser_use/controller/views.pyindex e6e1e2702..cf3eadcdc 100644--- a/browser_use/controller/views.py+++ b/browser_use/controller/views.py@@ -10,7 +10,7 @@ class SearchGoogleAction(BaseModel):class GoToUrlAction(BaseModel):url: str- new_tab: bool # True to open in new tab, False to navigate in current tab+ new_tab: bool = False # True to open in new tab, False to navigate in current tabclass ClickElementAction(BaseModel):diff --git a/tests/ci/test_mcp_client.py b/tests/ci/test_mcp_client.pyindex ec484acf0..7631cc548 100644--- a/tests/ci/test_mcp_client.py+++ b/tests/ci/test_mcp_client.py@@ -204,7 +204,7 @@ async def test_mcp_tools_with_agent(test_mcp_server_script, httpserver: HTTPServ# Create mock LLM with specific actionsactions = [- f'{{"thinking": null, "evaluation_previous_goal": "Starting", "memory": "Starting task", "next_goal": "Navigate to test page", "action": [{{"go_to_url": {{"url": "{httpserver.url_for("/")}"}}}}]}}',+ f'{{"thinking": null, "evaluation_previous_goal": "Starting", "memory": "Starting task", "next_goal": "Navigate to test page", "action": [{{"go_to_url": {{"url": "{httpserver.url_for("/")}", "new_tab": false}}}}]}}','{"thinking": null, "evaluation_previous_goal": "Navigated", "memory": "On test page", "next_goal": "Count to 3", "action": [{"count_to_n": {"n": 3}}]}','{"thinking": null, "evaluation_previous_goal": "Counted", "memory": "Counted to 3", "next_goal": "Echo message", "action": [{"echo_message": {"message": "MCP works!"}}]}','{"thinking": null, "evaluation_previous_goal": "Echoed", "memory": "Message echoed", "next_goal": "Complete", "action": [{"done": {"text": "Completed MCP test", "success": true}}]}',