Skip to content

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

hot-fix/scroll

Magnus Müllere15a8a216e8e
diff --git a/browser_use/dom/serializer/serializer.py b/browser_use/dom/serializer/serializer.py
index ccfc5dd89..7fefdc5d9 100644
--- a/browser_use/dom/serializer/serializer.py
+++ b/browser_use/dom/serializer/serializer.py
@@ -433,7 +433,8 @@ class DOMTreeSerializer:
return '\n'.join(formatted_text)
# Add element with interactive_index if clickable, scrollable, or iframe
- is_any_scrollable = node.original_node.is_actually_scrollable
+ is_any_scrollable = node.original_node.is_actually_scrollable or node.original_node.is_scrollable
+ should_show_scroll = node.original_node.should_show_scroll_info
if node.interactive_index is not None or is_any_scrollable or node.original_node.tag_name.upper() == 'IFRAME':
next_depth += 1
@@ -441,13 +442,13 @@ class DOMTreeSerializer:
attributes_html_str = DOMTreeSerializer._build_attributes_string(node.original_node, include_attributes, '')
# Build the line
- if is_any_scrollable and node.interactive_index is None:
- # Scrollable but not clickable
+ if should_show_scroll and node.interactive_index is None:
+ # Scrollable container but not clickable
line = f'{depth_str}|SCROLL|<{node.original_node.tag_name}'
elif node.interactive_index is not None:
# Clickable (and possibly scrollable)
new_prefix = '*' if node.is_new else ''
- scroll_prefix = '|SCROLL+' if is_any_scrollable else '['
+ scroll_prefix = '|SCROLL+' if should_show_scroll else '['
line = f'{depth_str}{new_prefix}{scroll_prefix}{node.interactive_index}]<{node.original_node.tag_name}'
elif node.original_node.tag_name.upper() == 'IFRAME':
# Iframe element (not interactive)
@@ -460,8 +461,8 @@ class DOMTreeSerializer:
line += ' />'
- # Add scroll information for scrollable elements
- if is_any_scrollable:
+ # Add scroll information only when we should show it
+ if should_show_scroll:
scroll_info_text = node.original_node.get_scroll_info_text()
if scroll_info_text:
line += f' ({scroll_info_text})'
@@ -518,6 +519,12 @@ class DOMTreeSerializer:
except (AttributeError, ValueError):
continue
+ # Include accessibility name (contains StaticText content)
+ if node.ax_node and node.ax_node.name and 'ax_name' in include_attributes:
+ ax_name_str = str(node.ax_node.name).strip()
+ if ax_name_str:
+ attributes_to_include['ax_name'] = ax_name_str
+
if not attributes_to_include:
return ''
diff --git a/browser_use/dom/views.py b/browser_use/dom/views.py
index 864cc5f76..14d9e7a5f 100644
--- a/browser_use/dom/views.py
+++ b/browser_use/dom/views.py
@@ -46,6 +46,8 @@ DEFAULT_INCLUDE_ATTRIBUTES = [
'level',
'busy',
'live',
+ # Accessibility name (contains text content for StaticText elements)
+ 'ax_name',
]
@@ -444,21 +446,68 @@ class EnhancedDOMTreeNode:
overflow_x = styles.get('overflow-x', overflow).lower()
overflow_y = styles.get('overflow-y', overflow).lower()
- # Allow scrolling if overflow is not explicitly hidden
+ # Only allow scrolling if overflow is explicitly set to auto, scroll, or overlay
+ # Do NOT consider 'visible' overflow as scrollable - this was causing the issue
allows_scroll = (
overflow in ['auto', 'scroll', 'overlay']
or overflow_x in ['auto', 'scroll', 'overlay']
or overflow_y in ['auto', 'scroll', 'overlay']
- or (overflow == 'visible' and (overflow_x != 'hidden' or overflow_y != 'hidden'))
)
return allows_scroll
else:
- # No CSS info, but content overflows - likely scrollable
- return True
+ # No CSS info, but content overflows - be more conservative
+ # Only consider it scrollable if it's a common scrollable container element
+ scrollable_tags = {'div', 'main', 'section', 'article', 'aside', 'body', 'html'}
+ return self.tag_name.lower() in scrollable_tags
return False
+ @property
+ def should_show_scroll_info(self) -> bool:
+ """
+ Simple check: show scroll info only if this element is scrollable
+ and doesn't have a scrollable parent (to avoid nested scroll spam).
+
+ Special case for iframes: Always show scroll info since Chrome might not
+ always detect iframe scrollability correctly (scrollHeight: 0 issue).
+ """
+ # Special case: Always show scroll info for iframe elements
+ # Even if not detected as scrollable, they might have scrollable content
+ if self.tag_name.lower() == 'iframe':
+ return True
+
+ # Must be scrollable first for non-iframe elements
+ if not (self.is_scrollable or self.is_actually_scrollable):
+ return False
+
+ # Always show for iframe content documents (body/html)
+ if self.tag_name.lower() in {'body', 'html'}:
+ return True
+
+ # Don't show if parent is already scrollable (avoid nested spam)
+ if self.parent_node and (self.parent_node.is_scrollable or self.parent_node.is_actually_scrollable):
+ return False
+
+ return True
+
+ def _find_html_in_content_document(self) -> 'EnhancedDOMTreeNode | None':
+ """Find HTML element in iframe content document."""
+ if not self.content_document:
+ return None
+
+ # Check if content document itself is HTML
+ if self.content_document.tag_name.lower() == 'html':
+ return self.content_document
+
+ # Look through children for HTML element
+ if self.content_document.children_nodes:
+ for child in self.content_document.children_nodes:
+ if child.tag_name.lower() == 'html':
+ return child
+
+ return None
+
@property
def scroll_info(self) -> dict[str, Any] | None:
"""Calculate scroll information for this element if it's scrollable."""
@@ -532,39 +581,39 @@ class EnhancedDOMTreeNode:
def get_scroll_info_text(self) -> str:
"""Get human-readable scroll information text for this element."""
+ # Special case for iframes: check content document for scroll info
+ if self.tag_name.lower() == 'iframe':
+ # Try to get scroll info from the HTML document inside the iframe
+ if self.content_document:
+ # Look for HTML element in content document
+ html_element = self._find_html_in_content_document()
+ if html_element and html_element.scroll_info:
+ info = html_element.scroll_info
+ # Provide minimal but useful scroll info
+ pages_below = info.get('pages_below', 0)
+ pages_above = info.get('pages_above', 0)
+ v_pct = int(info.get('vertical_scroll_percentage', 0))
+
+ if pages_below > 0 or pages_above > 0:
+ return f'scroll: {pages_above:.1f}↑ {pages_below:.1f}↓ {v_pct}%'
+
+ return 'scroll'
+
scroll_info = self.scroll_info
if not scroll_info:
return ''
parts = []
- # Vertical scroll info
+ # Vertical scroll info (concise format)
if scroll_info['scrollable_height'] > scroll_info['visible_height']:
- parts.append(
- f'scroll: {scroll_info["pages_above"]:.1f} pages above, '
- f'{scroll_info["pages_below"]:.1f} pages below, '
- f'at {scroll_info["vertical_scroll_percentage"]:.0f}% vertically'
- )
+ parts.append(f'{scroll_info["pages_above"]:.1f} pages above, {scroll_info["pages_below"]:.1f} pages below')
- # Horizontal scroll info (if significant)
+ # Horizontal scroll info (concise format)
if scroll_info['scrollable_width'] > scroll_info['visible_width']:
- parts.append(f'horizontal scroll: at {scroll_info["horizontal_scroll_percentage"]:.0f}%')
-
- # Can scroll directions
- scroll_directions = []
- if scroll_info['can_scroll_up']:
- scroll_directions.append('↑up')
- if scroll_info['can_scroll_down']:
- scroll_directions.append('↓down')
- if scroll_info['can_scroll_left']:
- scroll_directions.append('←left')
- if scroll_info['can_scroll_right']:
- scroll_directions.append('→right')
-
- if scroll_directions:
- parts.append(f'can scroll: {", ".join(scroll_directions)}')
-
- return ' | '.join(parts)
+ parts.append(f'horizontal {scroll_info["horizontal_scroll_percentage"]:.0f}%')
+
+ return ' '.join(parts)
@property
def element_hash(self) -> int: