Skip to content

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

Respect hidden assigned slots in click candidates

Emre Sokullu2b59784d54d5
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index 7008d5bb5..1a2b3d951 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -456,16 +456,8 @@
function _hasVisibleBox(el, minWidth = 1, minHeight = 1) {
if (!el || typeof el.getBoundingClientRect !== 'function') return false;
try {
- let ancestor = el;
- while (ancestor) {
+ for (let ancestor = el; ancestor; ancestor = _composedParent(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 244a2549e..1ef8a9633 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -667,16 +667,8 @@
function _hasVisibleBox(el, minWidth = 1, minHeight = 1) {
if (!el || typeof el.getBoundingClientRect !== 'function') return false;
try {
- let ancestor = el;
- while (ancestor) {
+ for (let ancestor = el; ancestor; ancestor = _composedParent(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/test/fixtures/message-recipient-navigation.mjs b/test/fixtures/message-recipient-navigation.mjs
index 59d97cb44..f0fa578d1 100644
--- a/test/fixtures/message-recipient-navigation.mjs
+++ b/test/fixtures/message-recipient-navigation.mjs
@@ -414,6 +414,26 @@ export function registerMessageRecipientNavigationFixtures({
assert.equal(await page.locator('textarea').inputValue(), 'Unsent draft');
});
+ register(`${kind}: an aria-hidden assigned slot cannot make Send ambiguous`, async (page) => {
+ await setup(page);
+ await page.evaluate(() => {
+ document.querySelector('#chat').hidden = false;
+ const host = document.createElement('div');
+ const duplicate = document.createElement('button');
+ duplicate.id = 'slotted-hidden-send';
+ duplicate.slot = 'hidden-send';
+ duplicate.type = 'button';
+ duplicate.textContent = 'Send';
+ host.append(duplicate);
+ document.body.append(host);
+ host.attachShadow({ mode: 'open' }).innerHTML = '<slot name="hidden-send" aria-hidden="true"></slot>';
+ });
+ const result = await call(page, 'click', { text: 'Send', textMatch: 'exact' });
+ assert.equal(result.success, true, JSON.stringify(result));
+ assert.deepEqual(await page.evaluate(() => window.fixtureClicks), ['send'],
+ 'the assigned hidden control must not be a click candidate');
+ });
+
const addPostEntry = async (page, shadow = false) => page.evaluate((shadow) => {
const host = document.createElement('section');
host.id = 'post-entry';
diff --git a/test/run.js b/test/run.js
index 6dedec4c6..6ac77d07c 100644
--- a/test/run.js
+++ b/test/run.js
@@ -6973,6 +6973,7 @@ test('direct-message recipient probe accepts only a unique active-thread header
innerText: text,
children: [],
parentElement: options.parentElement || null,
+ get parentNode() { return this.parentElement; },
clientHeight: options.clientHeight || rect.height || 0,
scrollHeight: options.scrollHeight || rect.height || 0,
getBoundingClientRect: () => rect,
@@ -7123,6 +7124,10 @@ test('direct-message recipient probe accepts only a unique active-thread header
return null;
},
};
+ const composedParentStart = source.indexOf(' function _composedParent(');
+ const composedParentEnd = source.indexOf('\n\n function ', composedParentStart + 1);
+ assert.ok(composedParentStart >= 0 && composedParentEnd > composedParentStart,
+ `${prefix}: composed-parent helper must be available to visibility checks`);
const candidatesStart = source.indexOf(' function _clickTextCandidates(');
const candidatesEnd = source.indexOf('\n\n let _lastClickIdent', candidatesStart);
Object.assign(context, {
@@ -7137,7 +7142,7 @@ test('direct-message recipient probe accepts only a unique active-thread header
const visibilityStart = source.indexOf(' function _hasVisibleBox(');
const visibilityEnd = source.indexOf('\n\n function ', visibilityStart + 1);
const probe = vm.runInNewContext(
- `${source.slice(visibilityStart, visibilityEnd)}; ${source.slice(candidatesStart, candidatesEnd)}; (${source.slice(start, end)})`, context,
+ `${source.slice(composedParentStart, composedParentEnd)}; ${source.slice(visibilityStart, visibilityEnd)}; ${source.slice(candidatesStart, candidatesEnd)}; (${source.slice(start, end)})`, context,
);
const observationResult = probe({ tool: 'observe_active_conversation', args: {} });
const enterResult = probe({ tool: 'press_keys', args: { key: 'Enter' } });