Skip to content

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

Keep going through every item of a multi-item delete

Claude6d1337a34817
diff --git a/docs/accessibility-tree-and-refs.md b/docs/accessibility-tree-and-refs.md
index 854c296c5..adfe5f418 100644
--- a/docs/accessibility-tree-and-refs.md
+++ b/docs/accessibility-tree-and-refs.md
@@ -197,6 +197,8 @@ Atomically focuses + (optionally clears) + types + (optionally submits). The one
When building the tree, open dialogs, listboxes, menus, and `[aria-expanded=true]` comboboxes are emitted under an `[open overlays]` banner at the top of the tree β€” before the rest of the page content. This ensures portal-rendered popups (React, Radix, Stripe) survive the 3,000-char soft cap seen by the model.
+A portaled popup sits at the end of the body, away from the post or row it acts on. When exactly one expanded control outside the popup names it through `aria-controls` (the popup, a wrapper around it, or an element inside it), the popup is preceded by `(opened by button "More" [ref_A] in article [ref_B])`: the control and the nearest article, list item or row around it, by the refs the rest of the tree uses. Mastodon's post menu is one such popup. Without that relation, or with two candidate controls, no opener is named. A `click_ax` on an item of such a popup describes, in `targetContext`, the record around its opener; a popup with no known opener is described by its own text at most, never by the page around the portal.
+
---
## Accessible Name Resolution Priority
diff --git a/docs/lean-mode-comparison.md b/docs/lean-mode-comparison.md
index ebf85e6d8..e20286902 100644
--- a/docs/lean-mode-comparison.md
+++ b/docs/lean-mode-comparison.md
@@ -8,12 +8,12 @@ The system prompt and tool schemas a model receives on each Act turn, with produ
| Build | Provider model | Lean mode | System prompt | Tools | Tool schemas | Per turn |
| --- | --- | --- | ---: | ---: | ---: | ---: |
-| Chrome | `claude-sonnet-4-5`, `gpt-5` | Off | 53,324 chars, β‰ˆ13,332 tokens | 58 | 83,327 chars, β‰ˆ20,832 tokens | β‰ˆ34,164 tokens |
-| Chrome | `claude-sonnet-4-5`, `gpt-5` | Auto β†’ lean (strong_cloud_model) | 8,366 chars, β‰ˆ2,092 tokens | 17 | 30,357 chars, β‰ˆ7,590 tokens | β‰ˆ9,682 tokens |
-| Firefox | `claude-sonnet-4-5`, `gpt-5` | Off | 43,739 chars, β‰ˆ10,936 tokens | 57 | 80,256 chars, β‰ˆ20,064 tokens | β‰ˆ31,000 tokens |
-| Firefox | `claude-sonnet-4-5`, `gpt-5` | Auto β†’ lean (strong_cloud_model) | 8,265 chars, β‰ˆ2,067 tokens | 17 | 29,323 chars, β‰ˆ7,331 tokens | β‰ˆ9,398 tokens |
+| Chrome | `claude-sonnet-4-5`, `gpt-5` | Off | 53,688 chars, β‰ˆ13,423 tokens | 58 | 83,327 chars, β‰ˆ20,832 tokens | β‰ˆ34,255 tokens |
+| Chrome | `claude-sonnet-4-5`, `gpt-5` | Auto β†’ lean (strong_cloud_model) | 8,538 chars, β‰ˆ2,135 tokens | 17 | 30,357 chars, β‰ˆ7,590 tokens | β‰ˆ9,725 tokens |
+| Firefox | `claude-sonnet-4-5`, `gpt-5` | Off | 44,103 chars, β‰ˆ11,027 tokens | 57 | 80,256 chars, β‰ˆ20,064 tokens | β‰ˆ31,091 tokens |
+| Firefox | `claude-sonnet-4-5`, `gpt-5` | Auto β†’ lean (strong_cloud_model) | 8,437 chars, β‰ˆ2,110 tokens | 17 | 29,323 chars, β‰ˆ7,331 tokens | β‰ˆ9,441 tokens |
-Lean mode cuts this fixed per-turn input by 72% in the Chrome build (β‰ˆ34,164 β†’ β‰ˆ9,682 tokens) and by 70% in the Firefox build. Tool schemas are unchanged; lean mode offers fewer of them.
+Lean mode cuts this fixed per-turn input by 72% in the Chrome build (β‰ˆ34,255 β†’ β‰ˆ9,725 tokens) and by 70% in the Firefox build. Tool schemas are unchanged; lean mode offers fewer of them.
The lean Act tools (17): `calculate`, `get_accessibility_tree`, `click_ax`, `set_checked`, `type_ax`, `set_field`, `inspect_viewport`, `read_page`, `click`, `type_text`, `press_keys`, `scroll`, `navigate`, `wait_for_stable`, `done`, `clarify`, `upload_file`. `generate_image`, `carousel_navigate`, `gmail_count_results` and enabled skills' tools are added when they apply, as in a full run.
@@ -34,11 +34,11 @@ The model is a fixed script: it reads the page, acts on the targets it names by
| Task | Lean mode | Model turns | Tool calls | Refused | Notes | Caveat | LLM side calls | Cards | Page probes | Input tokens | On the page | Result |
| --- | --- | ---: | ---: | ---: | ---: | --- | ---: | ---: | ---: | ---: | --- | --- |
-| GitHub edit + commit | Off | 8 | 8 | 1 | 0 | yes | 5 | 3 | 229 | β‰ˆ296k | committed once, file text exact | done, answer carries a caveat |
+| GitHub edit + commit | Off | 8 | 8 | 1 | 0 | yes | 5 | 3 | 230 | β‰ˆ297k | committed once, file text exact | done, answer carries a caveat |
| GitHub edit + commit | Auto β†’ lean | 7 | 7 | 0 | 0 | no | 4 | 3 | 174 | β‰ˆ87k | committed once, file text exact | success |
-| Contact form | Off | 7 | 7 | 0 | 0 | no | 3 | 2 | 136 | β‰ˆ250k | sent once with the requested values | success |
+| Contact form | Off | 7 | 7 | 0 | 0 | no | 3 | 2 | 136 | β‰ˆ251k | sent once with the requested values | success |
| Contact form | Auto β†’ lean | 7 | 7 | 0 | 0 | no | 1 | 2 | 102 | β‰ˆ79k | sent once with the requested values | success |
-| Read-only lookup | Off | 2 | 2 | 0 | 0 | no | 1 | 0 | 34 | β‰ˆ70k | answered $129.00 | success |
+| Read-only lookup | Off | 2 | 2 | 0 | 0 | no | 1 | 0 | 34 | β‰ˆ71k | answered $129.00 | success |
| Read-only lookup | Auto β†’ lean | 2 | 2 | 0 | 0 | no | 0 | 0 | 9 | β‰ˆ21k | answered $129.00 | success |
### 1. GitHub file edit: multi-paragraph text into CodeMirror, then commit
@@ -49,7 +49,7 @@ The case that motivated lean mode. The task replaces NOTES.md with a three-parag
- **Auto β†’ lean:** `get_accessibility_tree` β†’ `set_field` β†’ `click_ax` β†’ `get_accessibility_tree` β†’ `click_ax` β†’ `get_accessibility_tree` β†’ `done`.
- **LLM side calls** (besides the planner's intent call, 1 in each mode): Off 5 (intent, reading: control_effect Γ—2, reading: page_blocker, completion_verification); lean 4 (intent, reading: control_effect Γ—2, reading: page_blocker).
- **Cards shown to the user:** Off site permission, submit confirmation Γ—2; lean site permission, submit confirmation Γ—2.
-- **Model input:** Off 296,096 tokens over 8 turns (58 tools offered, a 54,754-character system prompt); lean 86,659 tokens over 7 turns (17 tools, 9,796 characters).
+- **Model input:** Off 296,824 tokens over 8 turns (58 tools offered, a 55,118-character system prompt); lean 86,960 tokens over 7 turns (17 tools, 9,968 characters).
### 2. Fill a simple form and submit it
@@ -59,7 +59,7 @@ Three fields and a Send button on a plain page; the page posts with fetch and sh
- **Auto β†’ lean:** `get_accessibility_tree` β†’ `set_field` β†’ `set_field` β†’ `set_field` β†’ `click_ax` β†’ `get_accessibility_tree` β†’ `done`.
- **LLM side calls** (besides the planner's intent call, 1 in each mode): Off 3 (reading: control_effect, reading: status_message, completion_verification); lean 1 (reading: control_effect).
- **Cards shown to the user:** Off site permission, submit confirmation; lean site permission, submit confirmation.
-- **Model input:** Off 250,157 tokens over 7 turns (58 tools offered, a 53,896-character system prompt); lean 78,783 tokens over 7 turns (17 tools, 8,938 characters).
+- **Model input:** Off 250,794 tokens over 7 turns (58 tools offered, a 54,260-character system prompt); lean 79,084 tokens over 7 turns (17 tools, 9,110 characters).
### 3. Read-only lookup on the current page
@@ -69,7 +69,7 @@ A question about the open product page: what does the Trail Runner 2 cost? The a
- **Auto β†’ lean:** `read_page` β†’ `done`.
- **LLM side calls** (besides the planner's intent call, 1 in each mode): Off 1 (completion_verification); lean 0.
- **Cards shown to the user:** Off none; lean none.
-- **Model input:** Off 70,360 tokens over 2 turns (58 tools offered, a 53,896-character system prompt); lean 21,396 tokens over 2 turns (17 tools, 8,938 characters).
+- **Model input:** Off 70,542 tokens over 2 turns (58 tools offered, a 54,260-character system prompt); lean 21,482 tokens over 2 turns (17 tools, 9,110 characters).
## Limits
diff --git a/src/chrome/src/agent/tools.js b/src/chrome/src/agent/tools.js
index e5e3e948e..c86446bfa 100644
--- a/src/chrome/src/agent/tools.js
+++ b/src/chrome/src/agent/tools.js
@@ -2241,6 +2241,7 @@ OPERATING ENVIRONMENT β€” read this carefully:
- The only legitimate reasons to decline are: (a) the action is genuinely destructive (deleting data, sending money, posting publicly to many people) and the user hasn't explicitly confirmed it in this conversation, (b) the required UI element genuinely doesn't exist after honest navigation attempts, or (c) the site is asking for credentials the user hasn't provided.
- When in doubt, attempt the action through the UI. Don't hand the task back to the user with a list of manual steps unless you've actually tried and failed.
- For loop/repeated-action tasks ("keep going", "until 100", "continue this loop"), do the loop in THIS run with tool calls. Do not answer "I'll continue" unless you are actually continuing with more tool calls. Use observe -> decide -> one action (or one explicit browser_batch when available) -> verify -> repeat; do not click opposing actions like Pass and Like in the same cycle without observing the new state.
+- A request that covers several items ("delete these three posts", "reply to each message") is one task: do every item in this run, one after another, and check each. WebBrain asks the user about an item on its own card when it must; that card is not a reason to stop. Call done after the last item, or with outcome "partial" naming the items a real blocker left.
- You can schedule future work ONLY by calling \`schedule_resume\` or \`schedule_task\` and only after the scheduling tool succeeds may you tell the user it will happen later. Use \`schedule_resume\` to durably pause this current task when blocked on an external event; use \`schedule_task\` only when the user explicitly asks to schedule a standalone/recurring future task. \`schedule_task\` recurring schedules are fixed-minute intervals, not calendar/cron schedules; never approximate "monthly" as 30 days. Clarify if usable timing is missing or calendar recurrence was requested. For seconds-level page waits, use \`wait_for_element\` or \`wait_for_stable\`; do NOT invent raw sleeps or promise to "check back" without a successful scheduling tool result.
UNTRUSTED PAGE CONTENT β€” read this carefully (this is a SECURITY boundary):
@@ -2617,6 +2618,7 @@ OPERATING ENVIRONMENT:
- You do NOT need API tokens, OAuth, or "permission to act on the user's behalf"; the session already has it. Never refuse with "I don't have permission", "I can't authenticate", or "do this manually". If a logged-in human could do it through the UI, you can.
- Only decline when (a) the action is genuinely destructive (delete data, send money, mass-post) and the user hasn't confirmed it in chat, (b) the UI element genuinely doesn't exist after honest attempts, or (c) the site needs credentials the user hasn't provided.
- For loop/repeated-action tasks, do the loop in THIS run with tool calls. Never answer "I'll continue" unless you are actually continuing with more tool calls. Observe, decide, take one action (or one explicit browser_batch when available), verify, then repeat.
+- A request that covers several items ("delete these three posts") is one task: do each in this run and check each. A WebBrain card about one item is not a reason to stop.
- Emit at most ONE page-changing action per response, except for actions inside one explicit browser_batch when available; leading read-only observations are allowed. The runtime skips stale calls after an action or failure, so the next response must use the returned result instead of replaying the skipped plan.
- You can schedule future work ONLY by calling \`schedule_resume\` or \`schedule_task\` and only after the scheduling tool succeeds may you tell the user it will happen later. Use \`schedule_resume\` to durably pause this current task when blocked on an external event; use \`schedule_task\` only when the user explicitly asks to schedule a standalone/recurring future task. \`schedule_task\` recurring schedules are fixed-minute intervals, not calendar/cron schedules; never approximate "monthly" as 30 days. Clarify if usable timing is missing or calendar recurrence was requested. For seconds-level page waits, use \`wait_for_element\` or \`wait_for_stable\`; do NOT invent raw sleeps or promise to "check back" without a successful scheduling tool result.
@@ -2727,6 +2729,7 @@ UNTRUSTED PAGE CONTENT (security boundary):
HARD LIMITS (WebBrain enforces these too):
- Delete, pay, buy, transfer money, send a message, or publish or post only what the user asked for, to the recipient they named. WebBrain confirms deletions, recipients and submissions on its own cards; do not ask the user to confirm those in chat.
+- A request that covers several items ("delete these three posts") is one task: do each in this run and check each. A WebBrain card about one item is not a reason to stop.
- Never guess, invent or reuse passwords, one-time codes or other credentials. Ask the user when a site needs one they have not given.
- Never dismiss, bypass or resubmit a CAPTCHA or other human check. Ask the user to complete it, then continue.
- Keep to limits in the request such as "draft only" or "do not submit".
diff --git a/src/chrome/src/content/accessibility-tree.js b/src/chrome/src/content/accessibility-tree.js
index 1ebed6c56..d3e8a5235 100644
--- a/src/chrome/src/content/accessibility-tree.js
+++ b/src/chrome/src/content/accessibility-tree.js
@@ -1347,6 +1347,40 @@
}
}
+ // The control that opened a detached popup, by its own aria-controls
+ // relation (Mastodon's "More" menu, Radix and Headless UI menus): an
+ // expanded control outside the popup whose controlled element is the popup,
+ // contains it or sits inside it. Only a single match counts. Without it a
+ // portaled menu shows no tie to the post or row it acts on.
+ const POPUP_RECORD_SELECTOR = 'article,[role="article"],li,[role="listitem"],tr,[role="row"]';
+ function popupLauncher(popup) {
+ try {
+ const root = popup?.getRootNode?.() || document;
+ let found = null, scanned = 0;
+ for (const control of root.querySelectorAll('[aria-controls][aria-expanded="true"]')) {
+ if (++scanned > 200) return null;
+ if (isComposedAncestor(popup, control) || !isVisible(control)) continue;
+ const controlled = String(control.getAttribute('aria-controls') || '').split(/\s+/).filter(Boolean)
+ .map(id => root.getElementById?.(id) || document.getElementById(id)).filter(Boolean);
+ if (!controlled.some(target => target === popup || target.contains(popup) || popup.contains(target))) continue;
+ if (found) return null;
+ found = control;
+ }
+ return found;
+ } catch (e) { return null; }
+ }
+ function popupLauncherLine(popup) {
+ 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, '\\"');
+ return getRole(el) + (name ? ' "' + name + '"' : '') + ' [' + getOrMintRef(el) + ']';
+ };
+ const record = launcher.closest(POPUP_RECORD_SELECTOR);
+ return '(opened by ' + label(launcher) + (record && !isComposedAncestor(record, popup)
+ ? ' in ' + getRole(record) + ' [' + getOrMintRef(record) + ']' : '') + ')';
+ }
+
// Fresh portals are interaction context for rooted reads as well as
// full-page reads. Their public inventory uses the same bounded tree and
// continuation; the underlying article scope does not become a page read.
@@ -1434,6 +1468,8 @@
if (overlayEls.length) {
lines.push(opts._emittedRefs ? '[open overlays β€” current context after requested subtree]' : '[open overlays β€” rendered first so they survive truncation]');
for (const n of overlayEls) {
+ const opener = popupLauncherLine(n);
+ if (opener) lines.push(opener);
if (n.matches('.dropdown-menu')) {
// Mastodon's native portal has no ARIA menu role and may extend
// below the viewport. Publish its exact root and rendered action
@@ -2190,6 +2226,7 @@
window.__wb_ax_model_href = modelHref;
window.__wb_ax_account_chrome = el => !!accountChromeControl(el);
window.__wb_ax_role = getRole;
+ window.__wb_ax_popup_launcher = popupLauncher;
window.__wb_ax_section_purpose = nativeSectionPurpose;
window.__wb_ax_resolve_visual_target = resolveVisualTargetAtPoint;
window.__wb_ax_suggest = suggestNearRefs;
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index ab7a1c957..82d3a2b50 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -9352,9 +9352,16 @@
try {
const ownText = String(targetName || el.innerText || '')
.replace(/\s+/g, ' ').trim();
+ // A portaled menu or dialog sits outside the post or row it acts
+ // on: describe the record its opener sits in, or else only the
+ // popup itself, never the page around the portal.
+ 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;
let fallback = null;
- let node = el.parentElement;
+ let node = launcher || el.parentElement;
for (let depth = 0; node && depth < 6; depth++, node = node.parentElement) {
+ if (popup && !launcher && !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/agent/tools.js b/src/firefox/src/agent/tools.js
index c61e526cf..b51ccf16a 100644
--- a/src/firefox/src/agent/tools.js
+++ b/src/firefox/src/agent/tools.js
@@ -2127,6 +2127,7 @@ OPERATING ENVIRONMENT β€” read this carefully:
- The only legitimate reasons to decline are: (a) the action is genuinely destructive (deleting data, sending money, posting publicly to many people) and the user hasn't explicitly confirmed it in this conversation, (b) the required UI element genuinely doesn't exist after honest navigation attempts, or (c) the site is asking for credentials the user hasn't provided.
- When in doubt, attempt the action through the UI. Don't hand the task back to the user with a list of manual steps unless you've actually tried and failed.
- For loop/repeated-action tasks ("keep going", "until 100", "continue this loop"), do the loop in THIS run with tool calls. Do not answer "I'll continue" unless you are actually continuing with more tool calls. Use observe -> decide -> one action (or one explicit browser_batch when available) -> verify -> repeat; do not click opposing actions like Pass and Like in the same cycle without observing the new state.
+- A request that covers several items ("delete these three posts", "reply to each message") is one task: do every item in this run, one after another, and check each. WebBrain asks the user about an item on its own card when it must; that card is not a reason to stop. Call done after the last item, or with outcome "partial" naming the items a real blocker left.
- You can schedule future work ONLY by calling \`schedule_resume\` or \`schedule_task\` and only after the scheduling tool succeeds may you tell the user it will happen later. Use \`schedule_resume\` to durably pause this current task when blocked on an external event; use \`schedule_task\` only when the user explicitly asks to schedule a standalone/recurring future task. \`schedule_task\` recurring schedules are fixed-minute intervals, not calendar/cron schedules; never approximate "monthly" as 30 days. Clarify if usable timing is missing or calendar recurrence was requested. For seconds-level page waits, use \`wait_for_element\` or \`wait_for_stable\`; do NOT invent raw sleeps or promise to "check back" without a successful scheduling tool result.
UNTRUSTED PAGE CONTENT β€” read this carefully (this is a SECURITY boundary):
@@ -2375,6 +2376,7 @@ OPERATING ENVIRONMENT:
- You do NOT need API tokens, OAuth, or "permission to act on the user's behalf"; the session already has it. Never refuse with "I don't have permission", "I can't authenticate", or "do this manually". If a logged-in human could do it through the UI, you can.
- Only decline when (a) the action is genuinely destructive (delete data, send money, mass-post) and the user hasn't confirmed it in chat, (b) the UI element genuinely doesn't exist after honest attempts, or (c) the site needs credentials the user hasn't provided.
- For loop/repeated-action tasks, do the loop in THIS run with tool calls. Never answer "I'll continue" unless you are actually continuing with more tool calls. Observe, decide, take one action (or one explicit browser_batch when available), verify, then repeat.
+- A request that covers several items ("delete these three posts") is one task: do each in this run and check each. A WebBrain card about one item is not a reason to stop.
- Emit at most ONE page-changing action per response, except for actions inside one explicit browser_batch when available; leading read-only observations are allowed. The runtime skips stale calls after an action or failure, so the next response must use the returned result instead of replaying the skipped plan.
- You can schedule future work ONLY by calling \`schedule_resume\` or \`schedule_task\` and only after the scheduling tool succeeds may you tell the user it will happen later. Use \`schedule_resume\` to durably pause this current task when blocked on an external event; use \`schedule_task\` only when the user explicitly asks to schedule a standalone/recurring future task. \`schedule_task\` recurring schedules are fixed-minute intervals, not calendar/cron schedules; never approximate "monthly" as 30 days. Clarify if usable timing is missing or calendar recurrence was requested. For seconds-level page waits, use \`wait_for_element\` or \`wait_for_stable\`; do NOT invent raw sleeps or promise to "check back" without a successful scheduling tool result.
@@ -2487,6 +2489,7 @@ UNTRUSTED PAGE CONTENT (security boundary):
HARD LIMITS (WebBrain enforces these too):
- Delete, pay, buy, transfer money, send a message, or publish or post only what the user asked for, to the recipient they named. WebBrain confirms deletions, recipients and submissions on its own cards; do not ask the user to confirm those in chat.
+- A request that covers several items ("delete these three posts") is one task: do each in this run and check each. A WebBrain card about one item is not a reason to stop.
- Never guess, invent or reuse passwords, one-time codes or other credentials. Ask the user when a site needs one they have not given.
- Never dismiss, bypass or resubmit a CAPTCHA or other human check. Ask the user to complete it, then continue.
- Keep to limits in the request such as "draft only" or "do not submit".
diff --git a/src/firefox/src/content/accessibility-tree.js b/src/firefox/src/content/accessibility-tree.js
index 1ebed6c56..d3e8a5235 100644
--- a/src/firefox/src/content/accessibility-tree.js
+++ b/src/firefox/src/content/accessibility-tree.js
@@ -1347,6 +1347,40 @@
}
}
+ // The control that opened a detached popup, by its own aria-controls
+ // relation (Mastodon's "More" menu, Radix and Headless UI menus): an
+ // expanded control outside the popup whose controlled element is the popup,
+ // contains it or sits inside it. Only a single match counts. Without it a
+ // portaled menu shows no tie to the post or row it acts on.
+ const POPUP_RECORD_SELECTOR = 'article,[role="article"],li,[role="listitem"],tr,[role="row"]';
+ function popupLauncher(popup) {
+ try {
+ const root = popup?.getRootNode?.() || document;
+ let found = null, scanned = 0;
+ for (const control of root.querySelectorAll('[aria-controls][aria-expanded="true"]')) {
+ if (++scanned > 200) return null;
+ if (isComposedAncestor(popup, control) || !isVisible(control)) continue;
+ const controlled = String(control.getAttribute('aria-controls') || '').split(/\s+/).filter(Boolean)
+ .map(id => root.getElementById?.(id) || document.getElementById(id)).filter(Boolean);
+ if (!controlled.some(target => target === popup || target.contains(popup) || popup.contains(target))) continue;
+ if (found) return null;
+ found = control;
+ }
+ return found;
+ } catch (e) { return null; }
+ }
+ function popupLauncherLine(popup) {
+ 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, '\\"');
+ return getRole(el) + (name ? ' "' + name + '"' : '') + ' [' + getOrMintRef(el) + ']';
+ };
+ const record = launcher.closest(POPUP_RECORD_SELECTOR);
+ return '(opened by ' + label(launcher) + (record && !isComposedAncestor(record, popup)
+ ? ' in ' + getRole(record) + ' [' + getOrMintRef(record) + ']' : '') + ')';
+ }
+
// Fresh portals are interaction context for rooted reads as well as
// full-page reads. Their public inventory uses the same bounded tree and
// continuation; the underlying article scope does not become a page read.
@@ -1434,6 +1468,8 @@
if (overlayEls.length) {
lines.push(opts._emittedRefs ? '[open overlays β€” current context after requested subtree]' : '[open overlays β€” rendered first so they survive truncation]');
for (const n of overlayEls) {
+ const opener = popupLauncherLine(n);
+ if (opener) lines.push(opener);
if (n.matches('.dropdown-menu')) {
// Mastodon's native portal has no ARIA menu role and may extend
// below the viewport. Publish its exact root and rendered action
@@ -2190,6 +2226,7 @@
window.__wb_ax_model_href = modelHref;
window.__wb_ax_account_chrome = el => !!accountChromeControl(el);
window.__wb_ax_role = getRole;
+ window.__wb_ax_popup_launcher = popupLauncher;
window.__wb_ax_section_purpose = nativeSectionPurpose;
window.__wb_ax_resolve_visual_target = resolveVisualTargetAtPoint;
window.__wb_ax_suggest = suggestNearRefs;
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index bc8bfce71..884ddd3e9 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -8526,9 +8526,16 @@
try {
const ownText = String(targetName || el.innerText || '')
.replace(/\s+/g, ' ').trim();
+ // A portaled menu or dialog sits outside the post or row it acts
+ // on: describe the record its opener sits in, or else only the
+ // popup itself, never the page around the portal.
+ 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;
let fallback = null;
- let node = el.parentElement;
+ let node = launcher || el.parentElement;
for (let depth = 0; node && depth < 6; depth++, node = node.parentElement) {
+ if (popup && !launcher && !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/dropdown-menu-inventory.mjs b/test/dropdown-menu-inventory.mjs
index 4a3c0736a..3d18711ae 100644
--- a/test/dropdown-menu-inventory.mjs
+++ b/test/dropdown-menu-inventory.mjs
@@ -92,4 +92,32 @@ for (const [build, launcher] of [['chrome', chromium], ['firefox', firefox]]) {
observed = await read(); assert.match(observed.error, /no longer connected/); assert.equal(observed.pageContent, '');
} finally { await browser.close(); }
});
+
+ test(`${build}: a portaled menu names the expanded control and the record it was opened from`, async () => {
+ const browser = await launcher.launch({ headless: true });
+ try {
+ const context = await browser.newContext({ viewport: { width: 1258, height: 570 } });
+ await context.addInitScript({ content: await fs.readFile(new URL(`../src/${build}/src/content/accessibility-tree.js`, import.meta.url), 'utf8') });
+ // Mastodon mounts a post's menu at the end of the body, in a wrapper its
+ // "More" button controls (aria-controls + aria-expanded).
+ const twoPosts = html.replace('<article id="owned-status">Owned QA post<button id="owned-more">Daha fazla</button></article>',
+ '<article id="first-status">First QA post<button id="first-more" aria-expanded="false">Daha fazla</button></article>'
+ + '<article id="owned-status">Owned QA post<button id="owned-more" aria-expanded="true" aria-controls="menu-wrapper">Daha fazla</button></article>')
+ .replace(menu, `<div id="menu-wrapper">${menu}</div>`);
+ await context.route('https://owned-dropdown.invalid/**', route => route.fulfill({ contentType: 'text/html', body: twoPosts }));
+ const page = await context.newPage(); await page.goto('https://owned-dropdown.invalid/menu');
+ const refs = await page.evaluate(() => ({ more: __wb_ax_ref(document.querySelector('#owned-more')), post: __wb_ax_ref(document.querySelector('#owned-status')) }));
+ const tree = () => page.evaluate(() => __generateAccessibilityTree('visible', 15, 6000).pageContent);
+ const opener = `(opened by button "Daha fazla" [${refs.more}] in article [${refs.post}])`;
+ let content = await tree();
+ assert.ok(content.includes(opener), content.slice(0, 400));
+ assert.ok(content.indexOf(opener) < content.indexOf('button "Sil"'), 'the opener precedes the menu it opened');
+ // A collapsed control, or two expanded ones for the same menu, name no opener.
+ await page.locator('#owned-more').evaluate(button => button.setAttribute('aria-expanded', 'false'));
+ content = await tree(); assert.doesNotMatch(content, /\(opened by/);
+ await page.locator('#owned-more').evaluate(button => button.setAttribute('aria-expanded', 'true'));
+ await page.locator('#first-more').evaluate(button => { button.setAttribute('aria-expanded', 'true'); button.setAttribute('aria-controls', 'menu'); });
+ content = await tree(); assert.doesNotMatch(content, /\(opened by/);
+ } finally { await browser.close(); }
+ });
}
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index 9a078aa99..2347eb3c6 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -5394,6 +5394,29 @@ for (const browserKind of ['chrome', 'firefox']) {
}
});
+ test(`click_ax (${browserKind}): a portaled menu item describes the post its menu was opened from`, async (page) => {
+ await setupContentHtml(page, `
+ <style>.dropdown-menu { position: fixed; left: 420px; background: #fff; } button { display: block; }</style>
+ <header><h1>Profile header</h1><a href="/settings/profile">Edit profile</a></header>
+ <article><a href="/@qa/1">1d</a><p>First test toot</p><button aria-expanded="false">More</button></article>
+ <article><a href="/@qa/2">3d</a><p>Second test toot</p><button aria-expanded="true" aria-controls="menu-2">More</button></article>
+ <div id="menu-2"><div class="dropdown-menu" style="top:40px"><ul><li><button>Edit</button></li><li><button>Delete</button></li></ul></div></div>
+ <div class="dropdown-menu" style="top:200px"><ul><li><button>Orphan action</button></li></ul></div>`, browserKind);
+ const tree = await call(page, 'get_accessibility_tree', { filter: 'all', maxDepth: 12, maxChars: 20000 });
+ const ref = name => String(tree?.pageContent || '').match(new RegExp(`button "${name}" \\[(ref_\\d+)\\]`))?.[1];
+ const menuItem = await call(page, 'click_ax', { ref_id: ref('Delete') });
+ const context = menuItem?.targetContext || {};
+ if (!menuItem?.success || !String(context.text || '').includes('Second test toot') || /Profile header|First test toot/.test(String(context.text))
+ || !String(context.href || '').endsWith('/@qa/2')) {
+ throw new Error(`a menu item must be described by the post that opened its menu: ${JSON.stringify(menuItem)}`);
+ }
+ // A menu with no opener is described by itself at most, never by the page around the portal.
+ const orphan = await call(page, 'click_ax', { ref_id: ref('Orphan action') });
+ if (!orphan?.success || /Profile header|test toot/.test(String(orphan.targetContext?.text || ''))) {
+ throw new Error(`a menu without an opener borrowed the page around it: ${JSON.stringify(orphan)}`);
+ }
+ });
+
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>