Skip to content

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

Bigfix: in case if node element has a shadow dom, all other children nodes are not processed

alexdfd5b124f2e2
diff --git a/browser_use/dom/buildDomTree.js b/browser_use/dom/buildDomTree.js
index 539c76225..ddd6b70ee 100644
--- a/browser_use/dom/buildDomTree.js
+++ b/browser_use/dom/buildDomTree.js
@@ -955,16 +955,16 @@
if (domElement) nodeData.children.push(domElement);
}
}
- // Handle shadow DOM
- else if (node.shadowRoot) {
- nodeData.shadowRoot = true;
- for (const child of node.shadowRoot.childNodes) {
- const domElement = buildDomTree(child, parentIframe);
- if (domElement) nodeData.children.push(domElement);
- }
- }
- // Handle regular elements
else {
+ // Handle shadow DOM
+ if (node.shadowRoot) {
+ nodeData.shadowRoot = true;
+ for (const child of node.shadowRoot.childNodes) {
+ const domElement = buildDomTree(child, parentIframe);
+ if (domElement) nodeData.children.push(domElement);
+ }
+ }
+ // Handle regular elements
for (const child of node.childNodes) {
const domElement = buildDomTree(child, parentIframe);
if (domElement) nodeData.children.push(domElement);