Skip to content

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

Enhance visibility check with robust edge case handling and input validation

Magnus Müller44b0e38ebf8c
diff --git a/browser_use/dom/enhanced_snapshot.py b/browser_use/dom/enhanced_snapshot.py
index 5919ae27a..28a3ceaa0 100644
--- a/browser_use/dom/enhanced_snapshot.py
+++ b/browser_use/dom/enhanced_snapshot.py
@@ -68,7 +68,11 @@ def _is_element_visible(
scroll_x: float = 0.0,
scroll_y: float = 0.0,
) -> bool:
- """Determine if an element is visible in the current scrolled viewport."""
+ """Determine if an element is visible in the current scrolled viewport with robust edge case handling."""
+
+ # Validate inputs - handle edge cases gracefully
+ if not bounding_box or viewport_width <= 0 or viewport_height <= 0:
+ return False
# Check CSS visibility properties
display = computed_styles.get('display', '').lower()