Skip to content

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

Refactor cross-origin iframe handling in tests and serializer

Magnus Müllerc3db6cff0233
diff --git a/browser_use/dom/serializer/serializer.py b/browser_use/dom/serializer/serializer.py
index a69c7701d..dfef67004 100644
--- a/browser_use/dom/serializer/serializer.py
+++ b/browser_use/dom/serializer/serializer.py
@@ -576,10 +576,6 @@ class DOMTreeSerializer:
def _collect_interactive_elements(self, node: SimplifiedNode, elements: list[SimplifiedNode]) -> None:
"""Recursively collect interactive elements that are also visible."""
- # Debug for cross-origin iframe elements
- if node.original_node.attributes and 'iana.org' in node.original_node.attributes.get('href', ''):
- target_short = node.original_node.target_id[-4:] if node.original_node.target_id else 'None'
-
is_interactive = self._is_interactive_cached(node.original_node)
is_visible = node.original_node.snapshot_node and node.original_node.is_visible
diff --git a/tests/ci/browser/test_cross_origin_click.py b/tests/ci/browser/test_cross_origin_click.py
index 90515cee0..116e08fad 100644
--- a/tests/ci/browser/test_cross_origin_click.py
+++ b/tests/ci/browser/test_cross_origin_click.py
@@ -6,7 +6,6 @@ import pytest
from browser_use.browser.profile import BrowserProfile, ViewportSize
from browser_use.browser.session import BrowserSession
-from browser_use.dom.service import DomService
from browser_use.tools.service import Tools
diff --git a/tests/ci/browser/test_dom_serializer.py b/tests/ci/browser/test_dom_serializer.py
index d8a738570..18b4262c2 100644
--- a/tests/ci/browser/test_dom_serializer.py
+++ b/tests/ci/browser/test_dom_serializer.py
@@ -84,9 +84,9 @@ class TestDOMSerializer:
- Regular DOM: 3 elements (button, input, link on main page)
- Shadow DOM: 3 elements (2 buttons, 1 input inside shadow root)
- Same-origin iframe: 2 elements (button, input inside iframe)
- - Cross-origin iframe: ~1 element (may extract some content from example.com)
+ - Cross-origin iframe placeholder: about:blank (no interactive elements)
- Iframe tags: 2 elements (the iframe elements themselves)
- Total: ~10-11 interactive elements
+ Total: ~10 interactive elements
"""
from browser_use.tools.service import Tools
@@ -351,7 +351,7 @@ class TestDOMSerializer:
1. Open shadow DOM element interaction
2. Closed shadow DOM element interaction (nested inside open shadow)
3. Same-origin iframe element interaction (inside closed shadow)
- 4. Cross-origin iframe extraction via CDP target switching (extracts text/structure from example.com)
+ 4. Cross-origin iframe placeholder with about:blank (no external dependencies)
5. Truly nested structure: Open Shadow → Closed Shadow → Iframe
"""
from browser_use.tools.service import Tools
@@ -473,8 +473,8 @@ class TestDOMSerializer:
print(f' Found elements from {len(all_targets)} different CDP targets in full DOM tree')
if len(all_targets) >= 2:
- print(' ✅ Cross-origin iframe extraction IS WORKING!')
- print(' ✓ Successfully extracted DOM from cross-origin iframe (example.com)')
+ print(' ✅ Multi-target iframe extraction IS WORKING!')
+ print(' ✓ Successfully extracted DOM from multiple CDP targets')
print(' ✓ CDP target switching feature is enabled and functional')
else:
print(' ⚠️ Only found elements from 1 target (cross-origin extraction may not be working)')
diff --git a/tests/ci/browser/test_page_stacked_template.html b/tests/ci/browser/test_page_stacked_template.html
index 81bd59e41..e7b1aeed8 100644
--- a/tests/ci/browser/test_page_stacked_template.html
+++ b/tests/ci/browser/test_page_stacked_template.html
@@ -116,7 +116,7 @@
</style>
<div class="shadow-content">
<button id="closed-shadow-btn">Closed Shadow Button</button>
- <iframe id="cross-origin-iframe" src="https://example.com"></iframe>
+ <iframe id="cross-origin-iframe" src="about:blank"></iframe>
<iframe id="nested-iframe" src="/iframe-same-origin"></iframe>
</div>
`;
diff --git a/tests/ci/browser/test_page_template.html b/tests/ci/browser/test_page_template.html
index d6e820310..cde8e161f 100644
--- a/tests/ci/browser/test_page_template.html
+++ b/tests/ci/browser/test_page_template.html
@@ -59,10 +59,10 @@
<iframe id="same-origin-iframe" src="/iframe-same-origin" style="width:100%; height:200px; border:1px solid #999;"></iframe>
</div>
- <!-- Cross-origin iframe (should NOT be accessible) -->
+ <!-- Cross-origin iframe placeholder (external domain removed for test isolation) -->
<div class="section">
- <h2>Cross-Origin Iframe</h2>
- <iframe id="cross-origin-iframe" src="https://example.com" style="width:100%; height:200px; border:1px solid #999;"></iframe>
+ <h2>Cross-Origin Iframe (Placeholder)</h2>
+ <iframe id="cross-origin-iframe" src="about:blank" style="width:100%; height:200px; border:1px solid #999;"></iframe>
</div>
<script>