Skip to content

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

fix-redundant-a-tag

paperboardofficial25a9aa6ca16a
diff --git a/browser_use/dom/buildDomTree.js b/browser_use/dom/buildDomTree.js
index a1943a90b..5e7e3a79c 100644
--- a/browser_use/dom/buildDomTree.js
+++ b/browser_use/dom/buildDomTree.js
@@ -538,9 +538,14 @@
console.warn('Unable to access iframe:', node);
}
} else {
- const children = Array.from(node.childNodes).map(child =>
- buildDomTree(child, parentIframe)
- );
+ const children = Array.from(node.childNodes)
+ .map(child => buildDomTree(child, parentIframe))
+ .filter(child => child !== null);
+ // If it's an <a> element and has no visible content, return null
+ if (nodeData.tagName === 'a' && children.length === 0) {
+ return null;
+ }
+
nodeData.children.push(...children);
}