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
Increase timeouts
Magnus Müller6f446b8a0305
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex b3d3b9637..3a49bbd5e 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -1319,7 +1319,11 @@ class Agent(Generic[Context, AgentStructuredOutput]):cached_selector_map = await self.browser_session.get_selector_map()cached_path_hashes = {e.hash.branch_path_hash for e in cached_selector_map.values()}- await self.browser_session.remove_highlights()+ try:+ await self.browser_session.remove_highlights()+ except asyncio.TimeoutError:+ # we don't care if this times out+ self.logger.debug('Timeout to remove highlights')for i, action in enumerate(actions):# DO NOT ALLOW TO CALL `done` AS A SINGLE ACTIONdiff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex e602cfa77..203cdb586 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -1965,7 +1965,7 @@ class BrowserSession(BaseModel):@observe_debug(name='remove_highlights', ignore_output=True, ignore_input=True)@require_initialization@time_execution_async('--remove_highlights')- @retry(timeout=10, retries=0)+ @retry(timeout=2, retries=0)async def remove_highlights(self):"""Removes all highlight overlays and labels created by the highlightElement function.@@ -2989,7 +2989,10 @@ class BrowserSession(BaseModel):try:self.logger.debug('🧹 Removing highlights...')- await self.remove_highlights()+ try:+ await self.remove_highlights()+ except asyncio.TimeoutError:+ self.logger.debug('Timeout to remove highlights')# Check for PDF and auto-download if neededtry:diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex ebc0f3c1a..b3aeed480 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -375,9 +375,10 @@ Only use this for specific queries for information retrieval from the page. Don'# replace multiple sequential \n with a single \ncontent = re.sub(r'\n+', '\n', content)- # limit to 40000 characters - remove text in the middle this is approx 20000 tokens- max_chars = 40000+ # limit to 000 characters - remove text in the middle this is approx 20000 tokens+ max_chars = 30000if len(content) > max_chars:+ logger.info(f'Content is too long, removing middle {len(content) - max_chars} characters')content = (content[: max_chars // 2]+ '\n... left out the middle because it was too long ...\n'@@ -395,7 +396,7 @@ Explain the content of the page and that the requested information is not availa# Aggressive timeout for LLM callresponse = await asyncio.wait_for(page_extraction_llm.ainvoke([UserMessage(content=formatted_prompt)]),- timeout=60.0, # 30 second aggressive timeout for LLM call+ timeout=120.0, # 120 second aggressive timeout for LLM call)extracted_content = f'Page Link: {page.url}\nQuery: {query}\nExtracted Content:\n{response.completion}'