Skip to content

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

Check is visible

Magnus Müllere0571b648dc5
diff --git a/browser_use/dom/serializer/clickable_elements.py b/browser_use/dom/serializer/clickable_elements.py
index f139326fe..146651600 100644
--- a/browser_use/dom/serializer/clickable_elements.py
+++ b/browser_use/dom/serializer/clickable_elements.py
@@ -18,15 +18,9 @@ class ClickableElementDetector:
if node.tag_name in {'html', 'body'}:
return False
- # RELAXED SIZE CHECK: Allow small elements that might be icons
- # Only exclude truly invisible elements (width AND height both 0)
- if (
- node.snapshot_node
- and node.snapshot_node.bounds
- and node.snapshot_node.bounds.width == 0
- and node.snapshot_node.bounds.height == 0
- ):
- return False
+ # RELAXED SIZE CHECK: Allow all elements including size 0 (they might be interactive overlays, etc.)
+ # Note: Size 0 elements can still be interactive (e.g., invisible clickable overlays)
+ # Visibility is determined separately by CSS styles, not just bounding box size
# SEARCH ELEMENT DETECTION: Check for search-related classes and attributes
if node.attributes:
diff --git a/browser_use/dom/serializer/serializer.py b/browser_use/dom/serializer/serializer.py
index 9d3172cc5..9d9b87ee9 100644
--- a/browser_use/dom/serializer/serializer.py
+++ b/browser_use/dom/serializer/serializer.py
@@ -158,9 +158,10 @@ class DOMTreeSerializer:
# Keep meaningful nodes
is_interactive_opt = self._is_interactive_cached(node.original_node)
+ is_visible = node.original_node.snapshot_node and node.original_node.is_visible
if (
- is_interactive_opt
+ (is_interactive_opt and is_visible) # Only keep interactive nodes that are visible
or node.original_node.is_scrollable
or node.original_node.node_type == NodeType.TEXT_NODE
or node.children
@@ -170,22 +171,28 @@ class DOMTreeSerializer:
return None
def _collect_interactive_elements(self, node: SimplifiedNode, elements: list[SimplifiedNode]) -> None:
- """Recursively collect interactive elements."""
- if self._is_interactive_cached(node.original_node):
+ """Recursively collect interactive elements that are also visible."""
+ is_interactive = self._is_interactive_cached(node.original_node)
+ is_visible = node.original_node.snapshot_node and node.original_node.is_visible
+
+ # Only collect elements that are both interactive AND visible
+ if is_interactive and is_visible:
elements.append(node)
for child in node.children:
self._collect_interactive_elements(child, elements)
def _assign_interactive_indices_and_mark_new_nodes(self, node: SimplifiedNode | None) -> None:
- """Assign interactive indices to clickable elements."""
+ """Assign interactive indices to clickable elements that are also visible."""
if not node:
return
- # Assign index to clickable elements
+ # Assign index to clickable elements that are also visible
is_interactive_assign = self._is_interactive_cached(node.original_node)
+ is_visible = node.original_node.snapshot_node and node.original_node.is_visible
- if is_interactive_assign:
+ # Only add to selector map if element is both interactive AND visible
+ if is_interactive_assign and is_visible:
node.interactive_index = self._interactive_counter
node.original_node.element_index = self._interactive_counter
self._selector_map[self._interactive_counter] = node.original_node