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
working nav and screenshots and highlighting
Nick Sweetingdc80ea32f0e9
diff --git a/browser_use/browser/default_action_watchdog.py b/browser_use/browser/default_action_watchdog.pyindex f66e0f792..968469d9f 100644--- a/browser_use/browser/default_action_watchdog.py+++ b/browser_use/browser/default_action_watchdog.py@@ -24,7 +24,7 @@ from browser_use.browser.watchdog_base import BaseWatchdogif TYPE_CHECKING:pass-# Rebuild event models that have forward references to EnhancedDOMTreeNode+# Import EnhancedDOMTreeNode and rebuild event models that have forward references to it# This must be done after all imports are completeClickElementEvent.model_rebuild()TypeTextEvent.model_rebuild()@@ -146,7 +146,9 @@ class DefaultActionWatchdog(BaseWatchdog):# Try to scroll the element's containersuccess = await self._scroll_element_container(element_node, pixels)if success:- self.logger.info(f'📜 Scrolled element {index_for_logging} container {event.direction} by {event.amount} pixels')+ self.logger.info(+ f'📜 Scrolled element {index_for_logging} container {event.direction} by {event.amount} pixels'+ )return# Perform target-level scrolldiff --git a/browser_use/browser/events.py b/browser_use/browser/events.pyindex 66ad3d9f5..27c69170b 100644--- a/browser_use/browser/events.py+++ b/browser_use/browser/events.py@@ -86,45 +86,45 @@ class BrowserStateRequestEvent(BaseEvent):class GoBackEvent(BaseEvent):"""Navigate back in browser history."""-+passclass GoForwardEvent(BaseEvent):"""Navigate forward in browser history."""-+passclass RefreshEvent(BaseEvent):"""Refresh/reload the current page."""-+passclass WaitEvent(BaseEvent):"""Wait for a specified number of seconds."""-+seconds: float = 3.0max_seconds: float = 10.0 # Safety capclass SendKeysEvent(BaseEvent):"""Send keyboard keys/shortcuts."""-+keys: str # e.g., "ctrl+a", "cmd+c", "Enter"class UploadFileEvent(BaseEvent):"""Upload a file to an element."""-+node: 'EnhancedDOMTreeNode'file_path: strclass ScrollToTextEvent(BaseEvent):"""Scroll to specific text on the page."""-+text: strdirection: Literal['up', 'down'] = 'down'@@ -324,8 +324,9 @@ class AboutBlankDVDScreensaverShownEvent(BaseEvent):error: str | None = None-# Note: Model rebuilding for forward references is handled at the end of the module import chain-# The events with 'EnhancedDOMTreeNode' forward references will be rebuilt after all imports are complete+# Note: Model rebuilding for forward references is handled in the importing modules+# Events with 'EnhancedDOMTreeNode' forward references (ClickElementEvent, TypeTextEvent,+# ScrollEvent, UploadFileEvent) need model_rebuild() called after imports are complete# check that event names are valid and non-overlapping (naiively n^2 so it's pretty slow but ok for now, optimize when >20 events)event_names = {diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex d75f60ebb..d1488ddc2 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -40,7 +40,7 @@ from browser_use.utils import time_execution_synclogger = logging.getLogger(__name__)-# Rebuild event models that have forward references to EnhancedDOMTreeNode+# Import EnhancedDOMTreeNode and rebuild event models that have forward references to it# This must be done after all imports are completeClickElementEvent.model_rebuild()TypeTextEvent.model_rebuild()