Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Fix _hasVisibleBox shadow host aria-hidden traversal

Emre Sokullua11c27a74129
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index bdfe76cb5..7008d5bb5 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -456,8 +456,16 @@
function _hasVisibleBox(el, minWidth = 1, minHeight = 1) {
if (!el || typeof el.getBoundingClientRect !== 'function') return false;
try {
- for (let ancestor = el; ancestor; ancestor = ancestor.parentElement) {
+ let ancestor = el;
+ while (ancestor) {
if (ancestor.getAttribute?.('aria-hidden') === 'true') return false;
+ const parent = ancestor.parentElement;
+ if (parent) {
+ ancestor = parent;
+ continue;
+ }
+ const root = ancestor.getRootNode?.();
+ ancestor = root && typeof ShadowRoot !== 'undefined' && root instanceof ShadowRoot ? root.host : null;
}
const r = el.getBoundingClientRect();
if (r.width < minWidth || r.height < minHeight) return false;
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 00c9645db..244a2549e 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -667,8 +667,16 @@
function _hasVisibleBox(el, minWidth = 1, minHeight = 1) {
if (!el || typeof el.getBoundingClientRect !== 'function') return false;
try {
- for (let ancestor = el; ancestor; ancestor = ancestor.parentElement) {
+ let ancestor = el;
+ while (ancestor) {
if (ancestor.getAttribute?.('aria-hidden') === 'true') return false;
+ const parent = ancestor.parentElement;
+ if (parent) {
+ ancestor = parent;
+ continue;
+ }
+ const root = ancestor.getRootNode?.();
+ ancestor = root && typeof ShadowRoot !== 'undefined' && root instanceof ShadowRoot ? root.host : null;
}
const r = el.getBoundingClientRect();
if (r.width < minWidth || r.height < minHeight) return false;