Skip to content

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

Update buildDomTree.js

Matic Zavadlal81056a2f3765
diff --git a/browser_use/dom/buildDomTree.js b/browser_use/dom/buildDomTree.js
index bcfcfe7ec..313a10a9e 100644
--- a/browser_use/dom/buildDomTree.js
+++ b/browser_use/dom/buildDomTree.js
@@ -658,10 +658,12 @@
// Handle shadow DOM
if (node.shadowRoot) {
- const shadowChildren = Array.from(node.shadowRoot.childNodes).map(
- (child) => buildDomTree(child, parentIframe)
- );
- nodeData.children.push(...shadowChildren);
+ for (const child of node.shadowRoot.childNodes) {
+ const domElement = buildDomTree(child, parentIframe);
+ if (domElement) {
+ nodeData.children.push(domElement);
+ }
+ }
}
// Handle iframes