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
less-timeouts
Magnus Müller33f69b152501
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex a015a381f..a6fb4eadf 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -1272,7 +1272,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):breakwhile self.state.paused:- await asyncio.sleep(0.2) # Small delay to prevent CPU spinning+ await asyncio.sleep(0.5) # Small delay to prevent CPU spinningif self.state.stopped: # Allow stopping while pausedagent_run_error = 'Agent stopped programmatically while paused'breakdiff --git a/browser_use/browser/python_highlights.py b/browser_use/browser/python_highlights.pyindex 1c3c354d6..69de393c9 100644--- a/browser_use/browser/python_highlights.py+++ b/browser_use/browser/python_highlights.py@@ -453,7 +453,6 @@ async def get_viewport_info_from_cdp(cdp_session) -> tuple[float, int, int]:return 1.0, 0, 0-@observe_debug(ignore_input=True, ignore_output=True, name='create_highlighted_screenshot_async')@time_execution_async('create_highlighted_screenshot_async')async def create_highlighted_screenshot_async(screenshot_b64: str, selector_map: DOMSelectorMap, cdp_session=None, filter_highlight_ids: bool = Truediff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex c85631b23..ead3a970b 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -40,7 +40,7 @@ from browser_use.browser.profile import BrowserProfile, ProxySettingsfrom browser_use.browser.views import BrowserStateSummary, TabInfofrom browser_use.dom.views import EnhancedDOMTreeNode, TargetInfofrom browser_use.observability import observe_debug-from browser_use.utils import _log_pretty_url, is_new_tab_page, time_execution_async+from browser_use.utils import _log_pretty_url, is_new_tab_pageDEFAULT_BROWSER_PROFILE = BrowserProfile()@@ -817,8 +817,6 @@ class BrowserSession(BaseModel):assert self._cdp_client_root is not None, 'CDP client not initialized - browser may not be connected yet'return self._cdp_client_root- @time_execution_async('get_or_create_cdp_session')- @observe_debug(ignore_input=True, ignore_output=True, name='get_or_create_cdp_session')async def get_or_create_cdp_session(self, target_id: TargetID | None = None, focus: bool = True, new_socket: bool | None = None) -> CDPSession:@@ -1138,7 +1136,7 @@ class BrowserSession(BaseModel):# Update the target's URL in our list for later usetarget['url'] = 'about:blank'# Small delay to ensure navigation completes- await asyncio.sleep(0.1)+ await asyncio.sleep(0.05)except Exception as e:self.logger.warning(f'Failed to redirect {target_url} to about:blank: {e}')@@ -1430,7 +1428,6 @@ class BrowserSession(BaseModel):return targetreturn None- @observe_debug(ignore_input=True, ignore_output=True, name='get_current_page_url')async def get_current_page_url(self) -> str:"""Get the URL of the current page using CDP."""target = await self.get_current_target_info()diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.pyindex 33bbb1756..d404223b0 100644--- a/browser_use/browser/watchdogs/default_action_watchdog.py+++ b/browser_use/browser/watchdogs/default_action_watchdog.py@@ -77,7 +77,7 @@ class DefaultActionWatchdog(BaseWatchdog):# Wait a bit for potential new tab to be created# This is necessary because tab creation is async and might not be immediate- await asyncio.sleep(0.25)+ await asyncio.sleep(0.1)# Note: We don't clear cached state here - let multi_act handle DOM change detection# by explicitly rebuilding and comparing when needed@@ -194,7 +194,7 @@ class DefaultActionWatchdog(BaseWatchdog):# by explicitly rebuilding and comparing when needed# Wait a bit for the scroll to settle and DOM to update- await asyncio.sleep(0.5)+ await asyncio.sleep(0.2)return None@@ -370,7 +370,7 @@ class DefaultActionWatchdog(BaseWatchdog):},session_id=session_id,)- await asyncio.sleep(0.5)+ await asyncio.sleep(0.05)# Navigation is handled by BrowserSession via eventsreturn Noneexcept Exception as js_e:@@ -427,7 +427,7 @@ class DefaultActionWatchdog(BaseWatchdog):await cdp_session.cdp_client.send.DOM.scrollIntoViewIfNeeded(params={'backendNodeId': backend_node_id}, session_id=session_id)- await asyncio.sleep(0.1) # Wait for scroll to complete+ await asyncio.sleep(0.05) # Wait for scroll to completeexcept Exception as e:self.logger.debug(f'Failed to scroll element into view: {e}')@@ -445,7 +445,7 @@ class DefaultActionWatchdog(BaseWatchdog):},session_id=session_id,)- await asyncio.sleep(0.123)+ await asyncio.sleep(0.05)# Calculate modifier bitmask for CDP# CDP Modifier bits: Alt=1, Control=2, Meta/Command=4, Shift=8@@ -476,7 +476,7 @@ class DefaultActionWatchdog(BaseWatchdog):),timeout=1.0, # 1 second timeout for mousePressed)- await asyncio.sleep(0.145)+ await asyncio.sleep(0.08)except TimeoutError:self.logger.debug('⏱️ Mouse down timed out (likely due to dialog), continuing...')# Don't sleep if we timed out@@ -524,7 +524,7 @@ class DefaultActionWatchdog(BaseWatchdog):},session_id=session_id,)- await asyncio.sleep(0.5)+ await asyncio.sleep(0.1)# Navigation is handled by BrowserSession via eventsreturn Noneexcept Exception as js_e:@@ -1471,7 +1471,7 @@ class DefaultActionWatchdog(BaseWatchdog):# Note: We don't clear cached state on Enter; multi_act will detect DOM changes# and rebuild explicitly. We still wait briefly for potential navigation.if 'enter' in event.keys.lower() or 'return' in event.keys.lower():- await asyncio.sleep(0.5)+ await asyncio.sleep(0.1)except Exception as e:raisediff --git a/browser_use/browser/watchdogs/downloads_watchdog.py b/browser_use/browser/watchdogs/downloads_watchdog.pyindex a5a5ba53c..4b27af9b0 100644--- a/browser_use/browser/watchdogs/downloads_watchdog.py+++ b/browser_use/browser/watchdogs/downloads_watchdog.py@@ -405,7 +405,7 @@ class DownloadsWatchdog(BaseWatchdog):start_time = asyncio.get_event_loop().time()while asyncio.get_event_loop().time() - start_time < max_wait:- await asyncio.sleep(2.0) # Check every 2 seconds+ await asyncio.sleep(5.0) # Check every 5 secondsif Path(downloads_dir).exists():for file_path in Path(downloads_dir).iterdir():