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
Check is visible
Magnus Müllere0571b648dc5
diff --git a/browser_use/dom/serializer/clickable_elements.py b/browser_use/dom/serializer/clickable_elements.pyindex 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 attributesif node.attributes:diff --git a/browser_use/dom/serializer/serializer.py b/browser_use/dom/serializer/serializer.pyindex 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 nodesis_interactive_opt = self._is_interactive_cached(node.original_node)+ is_visible = node.original_node.snapshot_node and node.original_node.is_visibleif (- is_interactive_opt+ (is_interactive_opt and is_visible) # Only keep interactive nodes that are visibleor node.original_node.is_scrollableor node.original_node.node_type == NodeType.TEXT_NODEor node.children@@ -170,22 +171,28 @@ class DOMTreeSerializer:return Nonedef _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 visibleis_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_counternode.original_node.element_index = self._interactive_counterself._selector_map[self._interactive_counter] = node.original_node