Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Address review on multi-item delete: escape backslashes, keep inline menu context
Claude4b3a1c210e75
diff --git a/src/chrome/src/content/accessibility-tree.js b/src/chrome/src/content/accessibility-tree.jsindex d3e8a5235..c5eed6949 100644--- a/src/chrome/src/content/accessibility-tree.js+++ b/src/chrome/src/content/accessibility-tree.js@@ -1373,7 +1373,7 @@const launcher = popupLauncher(popup);if (!launcher) return '';const label = el => {- const name = String(modelAccessibleName(el) || '').replace(/\s+/g, ' ').substring(0, MAX_NAME_LEN).replace(/"/g, '\\"');+ const name = String(modelAccessibleName(el) || '').replace(/\s+/g, ' ').substring(0, MAX_NAME_LEN).replace(/\\/g, '\\\\').replace(/"/g, '\\"');return getRole(el) + (name ? ' "' + name + '"' : '') + ' [' + getOrMintRef(el) + ']';};const record = launcher.closest(POPUP_RECORD_SELECTOR);diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 82d3a2b50..1298092ce 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -9358,10 +9358,18 @@const popup = el.closest?.('.dropdown-menu,[role="menu"],[role="listbox"],[popover],[role="dialog"],[role="alertdialog"],dialog');const launcher = popup && typeof window.__wb_ax_popup_launcher === 'function'? window.__wb_ax_popup_launcher(popup) : null;+ // No launcher: a popup mounted inside its own record or card keeps+ // trustworthy DOM ancestry, so only a detached one (a portal under+ // the body) is kept from borrowing the page around it.+ const detachedPopup = !!popup && !launcher && !popup.parentElement?.closest([+ 'article,[role="article"],li,[role="listitem"],tr,[role="row"]',+ '[data-product-id],[data-product],[data-testid*="product" i]',+ '[class*="product" i],[class*="card" i],[class*="tile" i]',+ ].join(','));let fallback = null;let node = launcher || el.parentElement;for (let depth = 0; node && depth < 6; depth++, node = node.parentElement) {- if (popup && !launcher && !popup.contains(node)) break;+ if (detachedPopup && !popup.contains(node)) break;const text = String(node.innerText || '').replace(/\s+/g, ' ').trim();if (!text || text === ownText) continue;const headingEl = node.querySelector?.('h1,h2,h3,h4,[role="heading"]');diff --git a/src/firefox/src/content/accessibility-tree.js b/src/firefox/src/content/accessibility-tree.jsindex d3e8a5235..c5eed6949 100644--- a/src/firefox/src/content/accessibility-tree.js+++ b/src/firefox/src/content/accessibility-tree.js@@ -1373,7 +1373,7 @@const launcher = popupLauncher(popup);if (!launcher) return '';const label = el => {- const name = String(modelAccessibleName(el) || '').replace(/\s+/g, ' ').substring(0, MAX_NAME_LEN).replace(/"/g, '\\"');+ const name = String(modelAccessibleName(el) || '').replace(/\s+/g, ' ').substring(0, MAX_NAME_LEN).replace(/\\/g, '\\\\').replace(/"/g, '\\"');return getRole(el) + (name ? ' "' + name + '"' : '') + ' [' + getOrMintRef(el) + ']';};const record = launcher.closest(POPUP_RECORD_SELECTOR);diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex 884ddd3e9..5173687dc 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -8532,10 +8532,18 @@const popup = el.closest?.('.dropdown-menu,[role="menu"],[role="listbox"],[popover],[role="dialog"],[role="alertdialog"],dialog');const launcher = popup && typeof window.__wb_ax_popup_launcher === 'function'? window.__wb_ax_popup_launcher(popup) : null;+ // No launcher: a popup mounted inside its own record or card keeps+ // trustworthy DOM ancestry, so only a detached one (a portal under+ // the body) is kept from borrowing the page around it.+ const detachedPopup = !!popup && !launcher && !popup.parentElement?.closest([+ 'article,[role="article"],li,[role="listitem"],tr,[role="row"]',+ '[data-product-id],[data-product],[data-testid*="product" i]',+ '[class*="product" i],[class*="card" i],[class*="tile" i]',+ ].join(','));let fallback = null;let node = launcher || el.parentElement;for (let depth = 0; node && depth < 6; depth++, node = node.parentElement) {- if (popup && !launcher && !popup.contains(node)) break;+ if (detachedPopup && !popup.contains(node)) break;const text = String(node.innerText || '').replace(/\s+/g, ' ').trim();if (!text || text === ownText) continue;const headingEl = node.querySelector?.('h1,h2,h3,h4,[role="heading"]');diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjsindex 2347eb3c6..1689a96ca 100644--- a/test/fixtures/run.mjs+++ b/test/fixtures/run.mjs@@ -5417,6 +5417,22 @@ for (const browserKind of ['chrome', 'firefox']) {}});+ test(`click_ax (${browserKind}): an inline menu without a launcher keeps its post as context`, async (page) => {+ await setupContentHtml(page, `+ <header><h1>Profile header</h1><a href="/settings/profile">Edit profile</a></header>+ <article><a href="/@qa/7">2d</a><p>Seventh test toot</p>+ <div class="dropdown-menu"><ul><li><button>Delete</button></li></ul></div>+ </article>`, browserKind);+ const tree = await call(page, 'get_accessibility_tree', { filter: 'all', maxDepth: 12, maxChars: 20000 });+ const ref = String(tree?.pageContent || '').match(/button "Delete" \[(ref_\d+)\]/)?.[1];+ const result = await call(page, 'click_ax', { ref_id: ref });+ const context = result?.targetContext || {};+ if (!result?.success || !String(context.text || '').includes('Seventh test toot') || /Profile header/.test(String(context.text))+ || !String(context.href || '').endsWith('/@qa/7')) {+ throw new Error(`an inline menu must keep the post it sits in as context: ${JSON.stringify(result)}`);+ }+ });+test(`resolve_visual_target (${browserKind}): nested SVG resolves semantic button`, async (page) => {await setupContentHtml(page, `<style>button { position: fixed; left: 40px; top: 30px; width: 120px; height: 60px; }</style>