mirror of
https://github.com/browser-use/browser-use
synced 2026-05-13 17:56:35 +02:00
working nav and screenshots and highlighting
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user