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
added more snapshot data
Gregor Žuničca714709a16f
diff --git a/browser_use/dom/enhanced_snapshot.py b/browser_use/dom/enhanced_snapshot.pyindex fd1e2f60f..76d3f0fb4 100644--- a/browser_use/dom/enhanced_snapshot.py+++ b/browser_use/dom/enhanced_snapshot.py@@ -124,6 +124,9 @@ def build_snapshot_lookup(computed_styles = {}# Look for layout tree node that corresponds to this snapshot node+ paint_order = None+ client_rects = None+ stacking_contexts = Nonefor layout_idx, node_index in enumerate(layout.get('nodeIndex', [])):if node_index == snapshot_index and layout_idx < len(layout.get('bounds', [])):# Parse bounding box@@ -137,6 +140,26 @@ def build_snapshot_lookup(computed_styles = _parse_computed_styles(strings, style_indices)cursor_style = computed_styles.get('cursor')+ # Extract paint order if available+ if layout_idx < len(layout.get('paintOrders', [])):+ paint_order = layout.get('paintOrders', [])[layout_idx]++ # Extract client rects if available+ client_rects_data = layout.get('clientRects', [])+ if layout_idx < len(client_rects_data):+ client_rect_data = client_rects_data[layout_idx]+ if client_rect_data and len(client_rect_data) >= 4:+ client_rects = {+ 'x': client_rect_data[0],+ 'y': client_rect_data[1],+ 'width': client_rect_data[2],+ 'height': client_rect_data[3],+ }++ # Extract stacking contexts if available+ if layout_idx < len(layout.get('stackingContexts', [])):+ stacking_contexts = layout.get('stackingContexts', {}).get('index', [])[layout_idx]+# Calculate visibility immediately if we have bounding boxif bounding_box and computed_styles:is_visible = _is_element_visible(bounding_box, computed_styles, viewport_width, viewport_height)@@ -147,8 +170,11 @@ def build_snapshot_lookup(is_clickable=is_clickable,cursor_style=cursor_style,is_visible=is_visible,- bounding_box=bounding_box,+ bounds=bounding_box,+ clientRects=client_rects,computed_styles=computed_styles if computed_styles else None,+ paint_order=paint_order,+ stacking_contexts=stacking_contexts,)return snapshot_lookupdiff --git a/browser_use/dom/views.py b/browser_use/dom/views.pyindex b8ef942bf..22c6e3300 100644--- a/browser_use/dom/views.py+++ b/browser_use/dom/views.py@@ -86,10 +86,26 @@ class EnhancedSnapshotNode:is_clickable: bool | Noneis_visible: bool | Nonecursor_style: str | None- bounding_box: dict[str, float] | None- """Bounding box with x, y, width, height in viewport coordinates"""+ bounds: dict[str, float] | None+ """+ Document coordinates (origin = top-left of the page, ignores current scroll).+ Equivalent JS API: layoutNode.boundingBox in the older API.+ Typical use: Quick hit-test that doesn’t care about scroll position.+ """++ clientRects: dict[str, float] | None+ """+ Viewport coordinates (origin = top-left of the visible scrollport).+ Equivalent JS API: element.getClientRects() / getBoundingClientRect().+ Typical use: Pixel-perfect hit-testing on screen, taking current scroll into account.+ """+computed_styles: dict[str, str] | None"""Computed styles from the layout tree"""+ paint_order: int | None+ """Paint order from the layout tree"""+ stacking_contexts: int | None+ """Stacking contexts from the layout tree"""@dataclass(slots=True)