Skip to content

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

fix(dom): index compact cross-origin payment fields

MagMueller53c3317fe5b1
diff --git a/browser_use/dom/service.py b/browser_use/dom/service.py
index 9e2f70f83..f8858e669 100644
--- a/browser_use/dom/service.py
+++ b/browser_use/dom/service.py
@@ -34,6 +34,17 @@ if TYPE_CHECKING:
_MAX_JS_CLICK_LISTENER_ELEMENTS = 100
_DESCRIBE_NODE_BATCH_SIZE = 20
_JS_CLICK_LISTENER_OVERFLOW = '__browser_use_too_many_click_listeners__'
+_MIN_CROSS_ORIGIN_IFRAME_AREA = 50 * 50
+_MIN_CROSS_ORIGIN_IFRAME_EDGE = 10
+
+
+def _is_cross_origin_iframe_size_eligible(width: float, height: float) -> bool:
+ """Keep tiny tracking frames out while allowing input-shaped hosted fields."""
+ return (
+ width >= _MIN_CROSS_ORIGIN_IFRAME_EDGE
+ and height >= _MIN_CROSS_ORIGIN_IFRAME_EDGE
+ and width * height >= _MIN_CROSS_ORIGIN_IFRAME_AREA
+ )
class DomService:
@@ -958,7 +969,9 @@ class DomService:
f'Skipping iframe at depth {iframe_depth} to prevent infinite recursion (max depth: {self.max_iframe_depth})'
)
else:
- # Check if iframe is visible and large enough (>= 50px in both dimensions)
+ # Check if the iframe is visible and large enough to contain an interactive control.
+ # Use area rather than requiring both edges to be >= 50px: hosted payment fields
+ # are commonly wide but only ~40px tall.
should_process_iframe = False
# First check if the iframe element itself is visible
@@ -969,13 +982,14 @@ class DomService:
width = bounds.width
height = bounds.height
- # Only process if iframe is at least 50px in both dimensions
- if width >= 50 and height >= 50:
+ if _is_cross_origin_iframe_size_eligible(width, height):
should_process_iframe = True
self.logger.debug(f'Processing cross-origin iframe: visible=True, width={width}, height={height}')
else:
self.logger.debug(
- f'Skipping small cross-origin iframe: width={width}, height={height} (needs >= 50px)'
+ f'Skipping small cross-origin iframe: width={width}, height={height} '
+ f'(needs >= {_MIN_CROSS_ORIGIN_IFRAME_AREA}px² area and '
+ f'>= {_MIN_CROSS_ORIGIN_IFRAME_EDGE}px per edge)'
)
else:
self.logger.debug('Skipping cross-origin iframe: no bounds available')
diff --git a/tests/ci/test_dom_visibility.py b/tests/ci/test_dom_visibility.py
index 640a66f82..c7e3d48b1 100644
--- a/tests/ci/test_dom_visibility.py
+++ b/tests/ci/test_dom_visibility.py
@@ -6,7 +6,7 @@ node must not be transformed by its own bounds when it appears in its own
frame chain (as built by _construct_enhanced_node).
"""
-from browser_use.dom.service import DomService
+from browser_use.dom.service import DomService, _is_cross_origin_iframe_size_eligible
from browser_use.dom.views import DOMRect, EnhancedDOMTreeNode, EnhancedSnapshotNode, NodeType
@@ -101,3 +101,21 @@ class TestVisibilityDoesNotMutateBounds:
assert visible is True
assert iframe.snapshot_node is not None and iframe.snapshot_node.bounds is not None
assert iframe.snapshot_node.bounds.y == 1200
+
+
+class TestCrossOriginIframeSizeEligibility:
+ def test_accepts_wide_secure_card_field(self):
+ """Hosted card fields are often only 40px tall but have enough area to be interactive."""
+ assert _is_cross_origin_iframe_size_eligible(width=250, height=40) is True
+
+ def test_accepts_compact_secure_cvv_field(self):
+ """A compact CVV frame must not be dropped solely because both edges are below 50px."""
+ assert _is_cross_origin_iframe_size_eligible(width=90, height=40) is True
+
+ def test_rejects_tiny_tracking_frame(self):
+ """Area alone must not admit a one-pixel tracking iframe."""
+ assert _is_cross_origin_iframe_size_eligible(width=1, height=2500) is False
+
+ def test_preserves_previous_minimum_area(self):
+ assert _is_cross_origin_iframe_size_eligible(width=50, height=50) is True
+ assert _is_cross_origin_iframe_size_eligible(width=49, height=49) is False