Skip to content

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

Bind a row's unlinked menu to the launcher whose click opened it

Claude1a276a091dec
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b63a81355..69e3fe18c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ This changelog was generated from the repository Git history and release tags. V
### Fixed
- Deleting your own Mastodon post through its "…" menu works again on current Mastodon (4.4): the menu fades in a moment after the click, so WebBrain lost track of which post it belonged to and refused "Delete" ("Sil" on a Turkish server) as not belonging to any post. The menu the agent's own click opens is now kept for up to three seconds while it appears, and the menu on a post's own page counts as that post's, since Mastodon draws it beside the post rather than inside it.
+- Deleting an item through its own "…" or "More" menu now works on sites that open that menu elsewhere in the page without linking it to its button, as many apps do. The menu the agent's own click opened, alone and within three seconds, belongs to that item, even while it fades in or opens inside a window already on the page. Before, Delete in such a menu was refused as belonging to no item. A menu opened by a script, by another item's button, or together with a second menu still borrows nothing, and the request still has to name the item or you confirm it on the card.
- Preserve exact editor identity and private values through owned focus and scroll preparation, while permitting the resulting geometry changes.
- Bind native input to the certified receiving control, allowing passive descendants while rejecting unrelated or nested activators.
- Preserve acknowledged click delivery through page rendering and focus restoration, with separate pending effect verification and repeat protection.
diff --git a/docs/architecture.md b/docs/architecture.md
index 0acbc70da..e2f41b229 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -112,7 +112,15 @@ stops at lists, landmarks, editors, headings, other records, other deletion
controls (including hover-only ones) and 2,000 characters, and keeps its
visible text without the control's own caption, together with the text of up
to twelve records of the same kind beside it, nearest first. A menu item
-borrows the record of its expanded aria-controls or popover launcher. A
+borrows the record of its expanded aria-controls or popover launcher, or, for a
+menu the page mounts elsewhere without that link (a portal), of the launcher
+whose own click the probe saw open it: the one new menu shown within three
+seconds of that click, counted even while it fades in, never a menu opened by
+a script, by another launcher, or alongside a second new one. A menu that opens
+inside a dialog already on screen counts, and so does a menu inside a new
+wrapper that opened with it. A Mastodon post's
+menu and its confirmation are captured the same way for the native post, and
+the action bar Mastodon draws beside a detailed status belongs to that status. A
confirmation dialog borrows the record of the agent's own authorized click
only when it opened after that click was checked, within 30 seconds, and holds
that one deletion control. The probe receives nothing from the request.
@@ -130,8 +138,9 @@ without a card. Everything else, including no answer, goes to the user on
WebBrain's card below. The same record is never deleted twice at the same step
in a task, even after a reload, and a changed record, step or set of
neighbours changes the checked action, so a decision cannot carry over to it.
-Toolbar, bulk and selection deletions, menus without a linked launcher and
-confirmation dialogs that cannot be linked get no record and stay blocked.
+Toolbar, bulk and selection deletions, menus with neither a linked launcher nor
+that click provenance, and confirmation dialogs that cannot be linked get no
+record and stay blocked.
Completion after such a deletion uses the ordinary post-submit checks.
When the decision is not a clear "delete this item", WebBrain asks the user on
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 046843c62..9183de435 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -28314,6 +28314,34 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const records = [...(bar?.closest?.('.detailed-status__wrapper')?.querySelectorAll('.detailed-status') || [])];
return records.length === 1 ? records[0] : null;
};
+ // The one popup a click on `control` opens, found by provenance where the
+ // page does not tie them together (aria-controls, popovertarget): the
+ // single new element matching `selector` shown within three seconds of
+ // that click, while no other new one appeared. A popup that mounts late
+ // or fades in from transparent counts; nothing is bound otherwise.
+ const capturePopupAfterClick = (control, selector, onPopup) => {
+ const rendered = () => [...doc.querySelectorAll(selector)].filter(nativeResourceRendered);
+ const before = new Set(rendered());
+ let timer = null;
+ const listener = event => {
+ const path = typeof event.composedPath === 'function' ? event.composedPath() : [event.target];
+ if (!path.includes(control)) return;
+ doc.removeEventListener('click', listener, true);
+ const deadline = Date.now() + 3000;
+ // The new popups, outermost first: a menu inside a dialog that was
+ // already open counts, and a new wrapper with its own menu inside
+ // counts once.
+ const pollFreshPopup = () => {
+ const fresh = rendered().filter(node => !before.has(node) && !node.contains(control));
+ const outer = fresh.filter(node => !fresh.some(other => other !== node && other.contains(node)));
+ if (outer.length === 1) { onPopup(outer[0]); return; }
+ if (!outer.length && Date.now() < deadline) timer = setTimeout(pollFreshPopup, 50);
+ };
+ timer = setTimeout(pollFreshPopup, 0);
+ };
+ doc.addEventListener('click', listener, true);
+ return () => { doc.removeEventListener('click', listener, true); clearTimeout(timer); };
+ };
const nativeResourcePopups = () => {
const native = '.dropdown-menu,.modal-root__modal.safety-action-modal';
const nodes = [...doc.querySelectorAll(`${native},dialog,[role="dialog"],[role="alertdialog"],[role="menu"]`)];
@@ -28413,7 +28441,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const labelledBy = String(popup?.getAttribute('aria-labelledby') || '').split(/\s+/).filter(Boolean);
const controls = String(control?.getAttribute('aria-controls') || '').split(/\s+/).filter(Boolean);
const relation = popup && ((popup.id && launcher?.controlledIds.includes(popup.id) && controls.includes(popup.id))
- || (launcher?.popoverTarget && launcher.popoverTarget === popup && control?.popoverTargetElement === popup));
+ || (launcher?.popoverTarget && launcher.popoverTarget === popup && control?.popoverTargetElement === popup)
+ || (!launcher?.controlledIds?.length && !launcher?.popoverTarget && !!launcher?.provenancePopup
+ && launcher.provenancePopup.contains(popup)));
if (!launcher || launcher.until < Date.now() || launcher.runToken !== args.__wbResourceRunToken
|| launcher.resourceUrl !== scope.url || launcher.scopeToken !== scope.scopeToken
|| !control?.isConnected || control.getRootNode() !== launcher.root || !popup || !isVisible(popup)
@@ -28488,10 +28518,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const controlledIds = String(control.getAttribute('aria-controls') || '').split(/\s+/).filter(Boolean);
const popoverTarget = control.popoverTargetElement || null;
- if ((!controlledIds.length && !popoverTarget) || controlledIds.length > 4) return '';
+ if (controlledIds.length > 4) return '';
const token = crypto.randomUUID();
- scopeRegistry.launchers.set(token, { control, root: control.getRootNode(), controlledIds, popoverTarget,
- resourceUrl: proof.url, scopeToken: proof.scopeToken, runToken: args.__wbResourceRunToken, until: Date.now() + 120000 });
+ const launcher = { control, root: control.getRootNode(), controlledIds, popoverTarget,
+ resourceUrl: proof.url, scopeToken: proof.scopeToken, runToken: args.__wbResourceRunToken, until: Date.now() + 120000,
+ provenancePopup: null };
+ // Without an ARIA or popover relation, the popup this launcher's own
+ // click opens is its popup.
+ if (!controlledIds.length && !popoverTarget) {
+ launcher.cleanup = capturePopupAfterClick(control,
+ '[role="menu"],[role="listbox"],[role="dialog"],[role="alertdialog"],[popover]', popup => { launcher.provenancePopup = popup; });
+ }
+ scopeRegistry.launchers.set(token, launcher);
while (scopeRegistry.launchers.size > 256) {
const oldest = scopeRegistry.launchers.keys().next().value;
scopeRegistry.launchers.get(oldest)?.cleanup?.(); scopeRegistry.launchers.delete(oldest);
@@ -28670,10 +28708,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// deletion controls (including hover-hidden ones) and 2,000 characters.
// Menus and dialogs are never crossed: a menu item borrows its
// launcher's record only through an explicit aria-controls/popover
- // relation, and a confirmation dialog borrows the record of the agent's
- // own preceding authorized click only when it opened after that click
- // was probed. Records with permalink evidence keep the permalinked
- // rules; toolbar, bulk and unrelated popup deletions get no record.
+ // relation, or by provenance as the one new menu that launcher's own
+ // probed click opened (rememberMenuLaunch), and a confirmation dialog
+ // borrows the record of the agent's own preceding authorized click only
+ // when it opened after that click was probed. Records with permalink
+ // evidence keep the permalinked rules; toolbar, bulk and unrelated popup
+ // deletions get no record.
const recordDocument = [url, performance.timeOrigin].join('|');
const recordDialogSelector = 'dialog[open],[role="dialog"],[role="alertdialog"]';
const recordMenuSelector = '[role="menu"],[role="listbox"],[popover]';
@@ -28873,6 +28913,28 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}, 120000);
scopeRegistry.unboundLaunch = launch;
};
+ // A menu the page opens without tying it to its launcher borrows the
+ // launcher's record by provenance: the one new menu shown within three
+ // seconds of a click on the launcher this probe saw. One launch is
+ // remembered, for two minutes on this document and run.
+ const rememberMenuLaunch = control => {
+ scopeRegistry.menuLaunch?.cleanup?.();
+ const launch = { control, document: recordDocument, runToken: args.__wbResourceRunToken, popup: null,
+ until: Date.now() + 120000 };
+ const stop = capturePopupAfterClick(control, recordMenuSelector, popup => { launch.popup = popup; });
+ launch.cleanup = () => { stop(); clearTimeout(launch.timer); };
+ launch.timer = setTimeout(() => {
+ launch.cleanup();
+ if (scopeRegistry.menuLaunch === launch) scopeRegistry.menuLaunch = null;
+ }, 120000);
+ scopeRegistry.menuLaunch = launch;
+ };
+ const recordMenuLaunchProvenance = popup => {
+ const launch = scopeRegistry.menuLaunch;
+ return launch && !!launch.popup?.contains(popup) && launch.document === recordDocument
+ && launch.runToken === args.__wbResourceRunToken && launch.until > Date.now()
+ && launch.control.isConnected && !popup.contains(launch.control) && hasVisibleBox(popup) ? launch.control : null;
+ };
// The agent passes its latest authorized record deletion (same task,
// within 30 s, not yet confirmed). Only a dialog that opened after that
// exact click was probed, and holds this one deletion control, links.
@@ -28926,7 +28988,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const popup = activation.closest(recordPopupSelector);
let resolved = null;
if (popup && !popup.matches(recordDialogSelector) && popup.matches(recordMenuSelector)) {
- const launcher = recordMenuLauncher(popup);
+ const launcher = recordMenuLauncher(popup) || recordMenuLaunchProvenance(popup);
resolved = launcher ? recordOwnerFor(launcher, popup) : null;
} else {
if (activation.closest(recordDialogSelector)) {
@@ -29152,6 +29214,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const popupTarget = /^(?:true|menu|listbox|tree|grid|dialog)$/i.test(control.getAttribute('aria-haspopup') || '')
|| control.hasAttribute('popovertarget');
const actionResource = resourceProofFor(target);
+ // A record's own menu launcher, for a menu that opens unlinked.
+ if (popupTarget && !actionResource && recordOwnerFor(control)) rememberMenuLaunch(control);
return { isSubmit: false, host, url, resolvedOrdinaryActivationTarget: true,
resolvedPreparatoryTarget: popupTarget,
frameDocumentIdentity: [url, performance.timeOrigin].join('|'), actionResource,
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 4e47f4a8c..696e7767d 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -25634,6 +25634,34 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const records = [...(bar?.closest?.('.detailed-status__wrapper')?.querySelectorAll('.detailed-status') || [])];
return records.length === 1 ? records[0] : null;
};
+ // The one popup a click on `control` opens, found by provenance where the
+ // page does not tie them together (aria-controls, popovertarget): the
+ // single new element matching `selector` shown within three seconds of
+ // that click, while no other new one appeared. A popup that mounts late
+ // or fades in from transparent counts; nothing is bound otherwise.
+ const capturePopupAfterClick = (control, selector, onPopup) => {
+ const rendered = () => [...doc.querySelectorAll(selector)].filter(nativeResourceRendered);
+ const before = new Set(rendered());
+ let timer = null;
+ const listener = event => {
+ const path = typeof event.composedPath === 'function' ? event.composedPath() : [event.target];
+ if (!path.includes(control)) return;
+ doc.removeEventListener('click', listener, true);
+ const deadline = Date.now() + 3000;
+ // The new popups, outermost first: a menu inside a dialog that was
+ // already open counts, and a new wrapper with its own menu inside
+ // counts once.
+ const pollFreshPopup = () => {
+ const fresh = rendered().filter(node => !before.has(node) && !node.contains(control));
+ const outer = fresh.filter(node => !fresh.some(other => other !== node && other.contains(node)));
+ if (outer.length === 1) { onPopup(outer[0]); return; }
+ if (!outer.length && Date.now() < deadline) timer = setTimeout(pollFreshPopup, 50);
+ };
+ timer = setTimeout(pollFreshPopup, 0);
+ };
+ doc.addEventListener('click', listener, true);
+ return () => { doc.removeEventListener('click', listener, true); clearTimeout(timer); };
+ };
const nativeResourcePopups = () => {
const native = '.dropdown-menu,.modal-root__modal.safety-action-modal';
const nodes = [...doc.querySelectorAll(`${native},dialog,[role="dialog"],[role="alertdialog"],[role="menu"]`)];
@@ -25733,7 +25761,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const labelledBy = String(popup?.getAttribute('aria-labelledby') || '').split(/\s+/).filter(Boolean);
const controls = String(control?.getAttribute('aria-controls') || '').split(/\s+/).filter(Boolean);
const relation = popup && ((popup.id && launcher?.controlledIds.includes(popup.id) && controls.includes(popup.id))
- || (launcher?.popoverTarget && launcher.popoverTarget === popup && control?.popoverTargetElement === popup));
+ || (launcher?.popoverTarget && launcher.popoverTarget === popup && control?.popoverTargetElement === popup)
+ || (!launcher?.controlledIds?.length && !launcher?.popoverTarget && !!launcher?.provenancePopup
+ && launcher.provenancePopup.contains(popup)));
if (!launcher || launcher.until < Date.now() || launcher.runToken !== args.__wbResourceRunToken
|| launcher.resourceUrl !== scope.url || launcher.scopeToken !== scope.scopeToken
|| !control?.isConnected || control.getRootNode() !== launcher.root || !popup || !isVisible(popup)
@@ -25808,10 +25838,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const controlledIds = String(control.getAttribute('aria-controls') || '').split(/\s+/).filter(Boolean);
const popoverTarget = control.popoverTargetElement || null;
- if ((!controlledIds.length && !popoverTarget) || controlledIds.length > 4) return '';
+ if (controlledIds.length > 4) return '';
const token = crypto.randomUUID();
- scopeRegistry.launchers.set(token, { control, root: control.getRootNode(), controlledIds, popoverTarget,
- resourceUrl: proof.url, scopeToken: proof.scopeToken, runToken: args.__wbResourceRunToken, until: Date.now() + 120000 });
+ const launcher = { control, root: control.getRootNode(), controlledIds, popoverTarget,
+ resourceUrl: proof.url, scopeToken: proof.scopeToken, runToken: args.__wbResourceRunToken, until: Date.now() + 120000,
+ provenancePopup: null };
+ // Without an ARIA or popover relation, the popup this launcher's own
+ // click opens is its popup.
+ if (!controlledIds.length && !popoverTarget) {
+ launcher.cleanup = capturePopupAfterClick(control,
+ '[role="menu"],[role="listbox"],[role="dialog"],[role="alertdialog"],[popover]', popup => { launcher.provenancePopup = popup; });
+ }
+ scopeRegistry.launchers.set(token, launcher);
while (scopeRegistry.launchers.size > 256) {
const oldest = scopeRegistry.launchers.keys().next().value;
scopeRegistry.launchers.get(oldest)?.cleanup?.(); scopeRegistry.launchers.delete(oldest);
@@ -25990,10 +26028,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// deletion controls (including hover-hidden ones) and 2,000 characters.
// Menus and dialogs are never crossed: a menu item borrows its
// launcher's record only through an explicit aria-controls/popover
- // relation, and a confirmation dialog borrows the record of the agent's
- // own preceding authorized click only when it opened after that click
- // was probed. Records with permalink evidence keep the permalinked
- // rules; toolbar, bulk and unrelated popup deletions get no record.
+ // relation, or by provenance as the one new menu that launcher's own
+ // probed click opened (rememberMenuLaunch), and a confirmation dialog
+ // borrows the record of the agent's own preceding authorized click only
+ // when it opened after that click was probed. Records with permalink
+ // evidence keep the permalinked rules; toolbar, bulk and unrelated popup
+ // deletions get no record.
const recordDocument = [url, performance.timeOrigin].join('|');
const recordDialogSelector = 'dialog[open],[role="dialog"],[role="alertdialog"]';
const recordMenuSelector = '[role="menu"],[role="listbox"],[popover]';
@@ -26193,6 +26233,28 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}, 120000);
scopeRegistry.unboundLaunch = launch;
};
+ // A menu the page opens without tying it to its launcher borrows the
+ // launcher's record by provenance: the one new menu shown within three
+ // seconds of a click on the launcher this probe saw. One launch is
+ // remembered, for two minutes on this document and run.
+ const rememberMenuLaunch = control => {
+ scopeRegistry.menuLaunch?.cleanup?.();
+ const launch = { control, document: recordDocument, runToken: args.__wbResourceRunToken, popup: null,
+ until: Date.now() + 120000 };
+ const stop = capturePopupAfterClick(control, recordMenuSelector, popup => { launch.popup = popup; });
+ launch.cleanup = () => { stop(); clearTimeout(launch.timer); };
+ launch.timer = setTimeout(() => {
+ launch.cleanup();
+ if (scopeRegistry.menuLaunch === launch) scopeRegistry.menuLaunch = null;
+ }, 120000);
+ scopeRegistry.menuLaunch = launch;
+ };
+ const recordMenuLaunchProvenance = popup => {
+ const launch = scopeRegistry.menuLaunch;
+ return launch && !!launch.popup?.contains(popup) && launch.document === recordDocument
+ && launch.runToken === args.__wbResourceRunToken && launch.until > Date.now()
+ && launch.control.isConnected && !popup.contains(launch.control) && hasVisibleBox(popup) ? launch.control : null;
+ };
// The agent passes its latest authorized record deletion (same task,
// within 30 s, not yet confirmed). Only a dialog that opened after that
// exact click was probed, and holds this one deletion control, links.
@@ -26246,7 +26308,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const popup = activation.closest(recordPopupSelector);
let resolved = null;
if (popup && !popup.matches(recordDialogSelector) && popup.matches(recordMenuSelector)) {
- const launcher = recordMenuLauncher(popup);
+ const launcher = recordMenuLauncher(popup) || recordMenuLaunchProvenance(popup);
resolved = launcher ? recordOwnerFor(launcher, popup) : null;
} else {
if (activation.closest(recordDialogSelector)) {
@@ -26472,6 +26534,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const popupTarget = /^(?:true|menu|listbox|tree|grid|dialog)$/i.test(control.getAttribute('aria-haspopup') || '')
|| control.hasAttribute('popovertarget');
const actionResource = resourceProofFor(target);
+ // A record's own menu launcher, for a menu that opens unlinked.
+ if (popupTarget && !actionResource && recordOwnerFor(control)) rememberMenuLaunch(control);
return { isSubmit: false, host, url, resolvedOrdinaryActivationTarget: true,
resolvedPreparatoryTarget: popupTarget,
frameDocumentIdentity: [url, performance.timeOrigin].join('|'), actionResource,
diff --git a/test/guards-unbound-deletion.mjs b/test/guards-unbound-deletion.mjs
index f7535e168..66e4e0ad3 100644
--- a/test/guards-unbound-deletion.mjs
+++ b/test/guards-unbound-deletion.mjs
@@ -534,6 +534,90 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(await record('#t'), null);
});
+ // Many apps mount a row's menu elsewhere in the page (a portal), a
+ // moment after the click, fading it in, with no aria-controls. The
+ // menu the probed launcher's own click opens still belongs to its row.
+ await t.test('a menu that opens unlinked borrows the record of the launcher whose click opened it', async () => {
+ const files = '<ul class="files"><li>Quarterly report.pdf <button id="more1" type="button" aria-haspopup="menu">â‹®</button></li>'
+ + '<li>Budget.xlsx <button id="more2" type="button" aria-haspopup="menu">â‹®</button></li></ul><div id="portal"></div>';
+ const install = () => page.evaluate(() => {
+ const style = document.createElement('style');
+ style.textContent = '.fade{animation:qa-fade 250ms}@keyframes qa-fade{from{opacity:0}to{opacity:1}}';
+ document.head.append(style);
+ window.qaMenus = 1;
+ window.qaMenu = () => {
+ const portal = document.getElementById('portal');
+ portal.innerHTML = '';
+ for (let index = 0; index < window.qaMenus; index += 1) {
+ const menu = document.createElement('div');
+ menu.setAttribute('role', 'menu'); menu.className = 'fade';
+ menu.innerHTML = `<button id="t${index || ''}" role="menuitem" type="button">Delete</button><button role="menuitem" type="button">Rename</button>`;
+ portal.append(menu);
+ }
+ };
+ for (const id of ['more1', 'more2']) document.getElementById(id).onclick = () => setTimeout(window.qaMenu, 30);
+ });
+ const openMenu = async (probed, clicked = probed) => {
+ await probe(probed); await page.click(clicked); await page.waitForTimeout(350);
+ };
+ await open(files); await install();
+ await openMenu('#more1');
+ let result = await record('#t');
+ assert.equal(result?.owner, 'li');
+ assert.equal(result.text, 'Quarterly report.pdf');
+ assert.equal(result.stage, 'record');
+ await open(files); await install();
+ await openMenu('#more2');
+ assert.equal((await record('#t'))?.text, 'Budget.xlsx');
+ // A menu opened by anything but the probed launcher's click, two new
+ // menus at once, or a menu that was already shown stays unbound.
+ await open(files); await install();
+ await probe('#more1'); await page.evaluate(() => window.qaMenu()); await page.waitForTimeout(350);
+ assert.equal(await record('#t'), null, 'scripted');
+ await open(files); await install();
+ await openMenu('#more1', '#more2');
+ assert.equal(await record('#t'), null, 'other launcher');
+ await open(files); await install();
+ await page.evaluate(() => { window.qaMenus = 2; });
+ await openMenu('#more1');
+ assert.equal(await record('#t'), null, 'two menus');
+ await open(files); await install();
+ await page.evaluate(() => { window.qaMenu(); for (const id of ['more1', 'more2']) document.getElementById(id).onclick = null; });
+ await openMenu('#more1');
+ assert.equal(await record('#t'), null, 'already shown');
+ });
+
+ // The new menu can open inside a dialog that was already open (a list
+ // of members in a modal), or arrive in a new wrapper that holds the
+ // menu itself (a popover with a menu inside). Either way it is the one
+ // new popup the launcher's click opened.
+ await t.test('an unlinked menu inside an open dialog or its own new wrapper borrows its launcher\'s record', async () => {
+ const rows = '<li>Ayşe Yılmaz <button id="more1" type="button" aria-haspopup="menu">⋮</button></li>'
+ + '<li>Mert Demir <button id="more2" type="button" aria-haspopup="menu">â‹®</button></li>';
+ const inDialog = `<div role="dialog" aria-label="Üyeler"><ul class="members">${rows}</ul><div id="portal"></div></div>`;
+ const wrapped = `<ul class="members">${rows}</ul><div id="portal"></div>`;
+ const install = wrapper => page.evaluate(wrapper => {
+ window.qaMenu = () => {
+ const portal = document.getElementById('portal');
+ const menu = '<div role="menu"><button id="t" role="menuitem" type="button">Sil</button><button role="menuitem" type="button">Düzenle</button></div>';
+ portal.innerHTML = wrapper ? `<div popover="manual" id="pop">${menu}</div>` : menu;
+ document.getElementById('pop')?.showPopover?.();
+ };
+ for (const id of ['more1', 'more2']) document.getElementById(id).onclick = () => setTimeout(window.qaMenu, 30);
+ }, wrapper);
+ for (const [html, wrapper, label] of [[inDialog, false, 'inside an open dialog'], [wrapped, true, 'in a new popover wrapper']]) {
+ await open(html); await install(wrapper);
+ await probe('#more2'); await page.click('#more2'); await page.waitForTimeout(350);
+ const result = await record('#t');
+ assert.equal(result?.owner, 'li', label);
+ assert.equal(result.text, 'Mert Demir', label);
+ // A script opening the same menu, without the launcher's click, still binds nothing.
+ await open(html); await install(wrapper);
+ await probe('#more2'); await page.evaluate(() => window.qaMenu()); await page.waitForTimeout(350);
+ assert.equal(await record('#t'), null, `${label}: scripted`);
+ }
+ });
+
await t.test('a menu borrows the record of its expanded launcher only', async () => {
const files = '<ul class="files"><li>Quarterly report.pdf <button id="more1" type="button" aria-haspopup="menu" aria-controls="file-menu" aria-expanded="false">â‹®</button></li>'
+ '<li>Budget.xlsx <button id="more2" type="button" aria-haspopup="menu" aria-controls="file-menu" aria-expanded="false">â‹®</button></li></ul>'
diff --git a/test/native-resource-deletion-binding.mjs b/test/native-resource-deletion-binding.mjs
index de0cb38be..bd569efd3 100644
--- a/test/native-resource-deletion-binding.mjs
+++ b/test/native-resource-deletion-binding.mjs
@@ -228,6 +228,49 @@ for (const build of ['chrome', 'firefox']) {
} finally { await f.page.close(); }
});
+ // A menu mounted elsewhere without aria-controls belongs to the saved
+ // record whose launcher's own click opened it, and to nothing else.
+ await t.test('an unlinked generic menu borrows the resource of the launcher whose click opened it', async () => {
+ const f = await fixture();
+ try {
+ const neutral = 'https://neutral-resource.invalid/records/300';
+ await f.page.goto('https://neutral-resource.invalid/records');
+ await f.page.setContent(`<!doctype html><article><a rel="bookmark" href="${neutral}">Exact generic resource</a>
+ <p>Exact neutral record</p><button type="button" id="generic-more" aria-haspopup="menu">More</button></article>
+ <article><a rel="bookmark" href="https://neutral-resource.invalid/records/301">Other resource</a>
+ <p>Other neutral record</p><button type="button" id="other-more" aria-haspopup="menu">More</button></article><div id="portal"></div>`);
+ await f.page.evaluate(() => {
+ window.qaOpen = () => { document.querySelector('#portal').innerHTML = '<div role="menu"><button type="button" id="popup-delete">Delete</button></div>'; };
+ for (const id of ['generic-more', 'other-more']) document.getElementById(id).onclick = () => setTimeout(window.qaOpen, 30);
+ });
+ const generic = { __wbNativeResourceAdapter: '' };
+ const more = await f.probe('#generic-more', generic);
+ assert.equal(more.actionResource?.url, neutral); assert.ok(more.popupLauncherToken);
+ f.adopt(more); await f.click('#generic-more'); await f.page.waitForTimeout(300);
+ assert.equal((await f.probe('#popup-delete', generic)).actionResource?.url, neutral,
+ 'The menu the launcher opened belongs to its record');
+ // The same menu opened by a script, or by another record's launcher,
+ // borrows nothing.
+ await f.page.evaluate(() => { document.querySelector('#portal').innerHTML = ''; });
+ const again = await f.probe('#generic-more', generic); f.adopt(again);
+ await f.page.evaluate(() => window.qaOpen()); await f.page.waitForTimeout(300);
+ assert.equal((await f.probe('#popup-delete', generic)).actionResource, null, 'scripted');
+ await f.page.evaluate(() => { document.querySelector('#portal').innerHTML = ''; });
+ const third = await f.probe('#generic-more', generic); f.adopt(third);
+ await f.click('#other-more'); await f.page.waitForTimeout(300);
+ assert.equal((await f.probe('#popup-delete', generic)).actionResource, null, 'other launcher');
+ // A new wrapper dialog holding the menu counts as the one popup the
+ // click opened, and the menu inside it belongs to the same record.
+ await f.page.evaluate(() => {
+ document.querySelector('#portal').innerHTML = '';
+ window.qaOpen = () => { document.querySelector('#portal').innerHTML = '<div role="dialog" aria-label="Actions"><div role="menu"><button type="button" id="popup-delete">Delete</button></div></div>'; };
+ });
+ const fourth = await f.probe('#generic-more', generic); f.adopt(fourth);
+ await f.click('#generic-more'); await f.page.waitForTimeout(300);
+ assert.equal((await f.probe('#popup-delete', generic)).actionResource?.url, neutral, 'nested menu');
+ } finally { await f.page.close(); }
+ });
+
await t.test('final deletion retains exact accepted-task authorization', async () => {
const f = await fixture();
try {