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
Improve error handling during browser setup by checking for exceptions in parallel task results and providing clearer error messages.
Magnus Müller28c80a595a91
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 81743d1e9..3066d8b35 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -385,13 +385,19 @@ class BrowserSession(BaseModel):assert self.browser_context, f'Failed to create BrowserContext for browser={self.browser}'# Configure browser - run some setup tasks in parallel for speed- await asyncio.gather(+ setup_results = await asyncio.gather(self._setup_viewports(),self._setup_current_page_change_listeners(),self._start_context_tracing(),return_exceptions=True,)+ # Check for exceptions in setup results+ for i, result in enumerate(setup_results):+ if isinstance(result, Exception):+ setup_task_names = ['_setup_viewports', '_setup_current_page_change_listeners', '_start_context_tracing']+ raise Exception(f'Browser setup failed in {setup_task_names[i]}: {result}') from result+self.initialized = Truereturn self