Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

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.py
index 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 BaseWatchdog
if 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 complete
ClickElementEvent.model_rebuild()
TypeTextEvent.model_rebuild()
@@ -146,7 +146,9 @@ class DefaultActionWatchdog(BaseWatchdog):
# Try to scroll the element's container
success = 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 scroll
diff --git a/browser_use/browser/events.py b/browser_use/browser/events.py
index 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."""
-
+
pass
class GoForwardEvent(BaseEvent):
"""Navigate forward in browser history."""
-
+
pass
class RefreshEvent(BaseEvent):
"""Refresh/reload the current page."""
-
+
pass
class WaitEvent(BaseEvent):
"""Wait for a specified number of seconds."""
-
+
seconds: float = 3.0
max_seconds: float = 10.0 # Safety cap
class 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: str
class ScrollToTextEvent(BaseEvent):
"""Scroll to specific text on the page."""
-
+
text: str
direction: 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.py
index 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_sync
logger = 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 complete
ClickElementEvent.model_rebuild()
TypeTextEvent.model_rebuild()