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
fix docstring incorrectly referencing y_position instead of pages + show generic hint
Laith Weinbergerf3f82689dd1e
diff --git a/browser_use/dom/serializer/serializer.py b/browser_use/dom/serializer/serializer.pyindex 716a0094d..0b1b7f314 100644--- a/browser_use/dom/serializer/serializer.py+++ b/browser_use/dom/serializer/serializer.py@@ -1043,18 +1043,22 @@ class DOMTreeSerializer:if child_text:formatted_text.append(child_text)- # Add hidden content hint for iframes with element details+ # Add hidden content hint for iframesif (node.original_node.node_type == NodeType.ELEMENT_NODEand node.original_node.tag_nameand node.original_node.tag_name.upper() in ('IFRAME', 'FRAME')- and node.original_node.hidden_elements_info):- hidden = node.original_node.hidden_elements_info- hint_lines = [f'{depth_str}... ({len(hidden)} more elements below - scroll to reveal):']- for elem in hidden:- hint_lines.append(f'{depth_str} <{elem["tag"]}> "{elem["text"]}" ~{elem["pages"]} pages down')- formatted_text.extend(hint_lines)+ if node.original_node.hidden_elements_info:+ # Show specific interactive elements with scroll distances+ hidden = node.original_node.hidden_elements_info+ hint_lines = [f'{depth_str}... ({len(hidden)} more elements below - scroll to reveal):']+ for elem in hidden:+ hint_lines.append(f'{depth_str} <{elem["tag"]}> "{elem["text"]}" ~{elem["pages"]} pages down')+ formatted_text.extend(hint_lines)+ elif node.original_node.has_hidden_content:+ # Generic hint for non-interactive hidden content+ formatted_text.append(f'{depth_str}... (more content below viewport - scroll to reveal)')return '\n'.join(formatted_text)diff --git a/browser_use/dom/service.py b/browser_use/dom/service.pyindex 06ef3e82c..c2a82d51a 100644--- a/browser_use/dom/service.py+++ b/browser_use/dom/service.py@@ -105,9 +105,7 @@ class DomService:return not css_hidden- def collect_hidden_elements(- subtree_root: EnhancedDOMTreeNode, viewport_height: float- ) -> list[dict[str, Any]]:+ def collect_hidden_elements(subtree_root: EnhancedDOMTreeNode, viewport_height: float) -> list[dict[str, Any]]:"""Collect hidden interactive elements from subtree."""hidden: list[dict[str, Any]] = []@@ -129,14 +127,18 @@ class DomService:)[:40]# Get y position and convert to pages- y_pos = subtree_root.snapshot_node.bounds.y if subtree_root.snapshot_node.bounds else 0+ y_pos = 0.0+ if subtree_root.snapshot_node and subtree_root.snapshot_node.bounds:+ y_pos = subtree_root.snapshot_node.bounds.ypages_down = round(y_pos / viewport_height, 1) if viewport_height > 0 else 0- hidden.append({- 'tag': subtree_root.tag_name or '?',- 'text': text or '(no label)',- 'pages': pages_down,- })+ hidden.append(+ {+ 'tag': subtree_root.tag_name or '?',+ 'text': text or '(no label)',+ 'pages': pages_down,+ }+ )for child in subtree_root.children_nodes or []:hidden.extend(collect_hidden_elements(child, viewport_height))@@ -146,6 +148,21 @@ class DomService:return hidden+ def has_any_hidden_content(subtree_root: EnhancedDOMTreeNode) -> bool:+ """Check if there's any hidden content (interactive or not) in subtree."""+ if is_hidden_by_threshold(subtree_root):+ return True++ for child in subtree_root.children_nodes or []:+ if has_any_hidden_content(child):+ return True++ for shadow_root in subtree_root.shadow_roots or []:+ if has_any_hidden_content(shadow_root):+ return True++ return False+def process_node(current_node: EnhancedDOMTreeNode) -> None:"""Process node and descendants, collecting hidden elements for iframes."""if (@@ -164,6 +181,10 @@ class DomService:hidden.sort(key=lambda x: x['pages'])current_node.hidden_elements_info = hidden[:10] # Limit to 10+ # Check for hidden non-interactive content when no interactive elements found+ if not hidden and has_any_hidden_content(current_node.content_document):+ current_node.has_hidden_content = True+for child in current_node.children_nodes or []:process_node(child)diff --git a/browser_use/dom/views.py b/browser_use/dom/views.pyindex 3db61bb2b..f45d666dd 100644--- a/browser_use/dom/views.py+++ b/browser_use/dom/views.py@@ -447,9 +447,14 @@ class EnhancedDOMTreeNode:hidden_elements_info: list[dict[str, Any]] = field(default_factory=list)"""- Details of interactive elements hidden due to viewport threshold (for iframes)- Each dict contains: tag, text, y_position- Used to show specific element info in the LLM representation+ Details of interactive elements hidden due to viewport threshold (for iframes).+ Each dict contains: tag, text, pages (scroll distance in viewport pages).+ Used to show specific element info in the LLM representation.+ """++ has_hidden_content: bool = False+ """+ Whether this iframe has hidden non-interactive content below the viewport threshold."""uuid: str = field(default_factory=uuid7str)