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
Let an X post own its controls
Claudee4d6f07463b8
diff --git a/docs/page-feedback-monitor.md b/docs/page-feedback-monitor.mdindex 27f121e7f..738ae6941 100644--- a/docs/page-feedback-monitor.md+++ b/docs/page-feedback-monitor.md@@ -317,6 +317,19 @@ Steer or grant authorization. Enter and Alt+Enter retain their existing behaviorcontrol is bound by its `datetime` value rather than its rendered text, so arelative timestamp ticking over ("2 min" to "3 min") is not a change ofcontext, while a changed `datetime` still is.+- An article the page offers as one item to assistive technology owns its+ controls the same way, without a feed position: an `article` or+ `role="article"` that can take focus (any valid `tabindex`), named by its own+ `aria-label` or a complete `aria-labelledby`, that links somewhere and holds+ no field or editor, with at most 64 controls. X marks each timeline post this+ way (`tabindex="0"`), and the post a status page shows (`tabindex="-1"`).+ Its labels, controls, images and attributes stay bound, so a change in+ another post keeps the decision, while the post's own counters changing, or+ its virtualized cell showing another post, invalidates it. X also names the+ timestamp link with the relative time ("17 hours ago"), and that name is+ bound as written, so when it ticks over the post's decision is no longer+ certified either. Unnamed, unfocusable or unlinked articles gain nothing from+ this rule.- Inside an unnamed region, or outside any entity, the nearest focusable itemthe page names for assistive technology owns the controls inside it: anelement in the tab order (`tabindex` 0 or more), with no role ordiff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.jsindex c90892178..fad587170 100644--- a/src/chrome/src/content/page-monitor.js+++ b/src/chrome/src/content/page-monitor.js@@ -1414,6 +1414,28 @@}return null;}+ // A post the page offers as one item to assistive technology: an article+ // that can take focus (any valid tabindex) and has a name of its own+ // (aria-label, or aria-labelledby with every reference present), holding a+ // real link and no editor. X marks each timeline post this way (tabindex 0)+ // and the post a status page shows (tabindex -1), with no feed position.+ function namedFocusableArticle(node) {+ if (!(node instanceof Element) || !node.matches('article,[role="article"]')+ || !/^\s*-?\d+\s*$/.test(node.getAttribute('tabindex') || '')) return false;+ let named = !!String(node.getAttribute('aria-label') || '').trim();+ if (!named) {+ const ids = String(node.getAttribute('aria-labelledby') || '').trim().split(/\s+/).filter(Boolean);+ const labels = ids.length ? modelLabels(node) : null;+ named = !!labels && ids.every(id => labels.some(label => label.node.id === id))+ && labels.some(label => String(window.__wb_ax_name?.(label.node) || label.node.textContent || '').trim());+ }+ if (!named || node.querySelectorAll(modelControlSelector).length > 64+ || node.querySelector('input:not([type="hidden"]),textarea,select,[contenteditable]:not([contenteditable="false"]),[role="textbox"]')) return false;+ return [...node.querySelectorAll('a[href]')].some(link => {+ const href = String(link.getAttribute('href') || '').trim();+ return visible(link) && !!href && !href.startsWith('#') && !/^javascript:/i.test(href);+ });+ }// `keyboard` leaves out which node is on top at the target's centre; only// keyboard input to the focused field is checked against such a footprint// (see keyboardBoundField).@@ -1645,11 +1667,12 @@// An item of an ARIA feed (an article with its position in the feed,// as Mastodon and other social timelines mark each post) is an entity// of its own: its controls are bound with the item, and changes in other- // items of the feed are not this item's context.+ // items of the feed are not this item's context. So is an article the+ // page names and lets take focus as one item (namedFocusableArticle).const feedItem = owner.matches('article[aria-posinset],[role="article"][aria-posinset]')&& !!owner.parentElement?.closest('[role="feed"]');meaningfulOwner ||= headings.length > 0 || identities.length > 0 || owner.matches(modelEntityIdentitySelector) || feedItem- || namedItemOwner;+ || namedItemOwner || namedFocusableArticle(owner);if (meaningfulOwner) {const images = [...owner.querySelectorAll('img')].filter(node => belongs(node, navigationOwner)&& !node.closest('input,textarea,[contenteditable]:not([contenteditable="false"])')diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.jsindex c90892178..fad587170 100644--- a/src/firefox/src/content/page-monitor.js+++ b/src/firefox/src/content/page-monitor.js@@ -1414,6 +1414,28 @@}return null;}+ // A post the page offers as one item to assistive technology: an article+ // that can take focus (any valid tabindex) and has a name of its own+ // (aria-label, or aria-labelledby with every reference present), holding a+ // real link and no editor. X marks each timeline post this way (tabindex 0)+ // and the post a status page shows (tabindex -1), with no feed position.+ function namedFocusableArticle(node) {+ if (!(node instanceof Element) || !node.matches('article,[role="article"]')+ || !/^\s*-?\d+\s*$/.test(node.getAttribute('tabindex') || '')) return false;+ let named = !!String(node.getAttribute('aria-label') || '').trim();+ if (!named) {+ const ids = String(node.getAttribute('aria-labelledby') || '').trim().split(/\s+/).filter(Boolean);+ const labels = ids.length ? modelLabels(node) : null;+ named = !!labels && ids.every(id => labels.some(label => label.node.id === id))+ && labels.some(label => String(window.__wb_ax_name?.(label.node) || label.node.textContent || '').trim());+ }+ if (!named || node.querySelectorAll(modelControlSelector).length > 64+ || node.querySelector('input:not([type="hidden"]),textarea,select,[contenteditable]:not([contenteditable="false"]),[role="textbox"]')) return false;+ return [...node.querySelectorAll('a[href]')].some(link => {+ const href = String(link.getAttribute('href') || '').trim();+ return visible(link) && !!href && !href.startsWith('#') && !/^javascript:/i.test(href);+ });+ }// `keyboard` leaves out which node is on top at the target's centre; only// keyboard input to the focused field is checked against such a footprint// (see keyboardBoundField).@@ -1645,11 +1667,12 @@// An item of an ARIA feed (an article with its position in the feed,// as Mastodon and other social timelines mark each post) is an entity// of its own: its controls are bound with the item, and changes in other- // items of the feed are not this item's context.+ // items of the feed are not this item's context. So is an article the+ // page names and lets take focus as one item (namedFocusableArticle).const feedItem = owner.matches('article[aria-posinset],[role="article"][aria-posinset]')&& !!owner.parentElement?.closest('[role="feed"]');meaningfulOwner ||= headings.length > 0 || identities.length > 0 || owner.matches(modelEntityIdentitySelector) || feedItem- || namedItemOwner;+ || namedItemOwner || namedFocusableArticle(owner);if (meaningfulOwner) {const images = [...owner.querySelectorAll('img')].filter(node => belongs(node, navigationOwner)&& !node.closest('input,textarea,[contenteditable]:not([contenteditable="false"])')diff --git a/test/page-monitor-feed-items.mjs b/test/page-monitor-feed-items.mjsindex 4d1b54a4b..1174b97cd 100644--- a/test/page-monitor-feed-items.mjs+++ b/test/page-monitor-feed-items.mjs@@ -5,6 +5,8 @@// is not a change of context; a change of the item's own controls still is.// A post shown on its own page, and each reply around it, is a focusable item// the page names for assistive technology; it owns its controls the same way.+// So is an article the page names and lets take focus as one item, as X marks+// each timeline post without a feed position.import assert from 'node:assert/strict';import fs from 'node:fs';import { test } from 'node:test';@@ -43,6 +45,27 @@ const detail = (wrapper = 'tabindex="0" aria-label="Emre, gönderi 1, 14 Eki 12:<button type="button" aria-label="Daha fazla" id="more1">…</button></div></div>${reply(2, 'Mert', '9 dk')}${reply(3, 'Can', '8 dk')}</div></div></div>`;+// An X home timeline post as X renders it: a focusable article named by+// aria-labelledby (author line, text, engagement group) inside a virtualized+// cell, with no feed role and no position in a feed.+const xPost = (n, { name = 'Illia', handle = 'illia', article = 'aria-labelledby="name{n} text{n} group{n}" tabindex="0"',+ statusHref = `/${handle}/status/211190481654505${n}`, likes = '780' } = {}) => `<div data-testid="cellInnerDiv">+ <article ${article.replaceAll('{n}', n)} role="article" data-testid="tweet"><div><div>+ <div data-testid="Tweet-User-Avatar"><a href="/${handle}" role="link" tabindex="-1"><img alt="" width="40" height="40"+ src="data:image/gif;base64,R0lGODlhAQABAAAAACw="></a></div>+ <div id="name${n}" data-testid="User-Name"><a href="/${handle}" role="link"><span id="author${n}">${name}</span></a>+ <a href="/${handle}" role="link" tabindex="-1"><span>@${handle}</span></a><span>·</span>+ <a id="time${n}" href="${statusHref}" role="link"><time datetime="2026-10-18T02:0${n}:00.000Z">17h</time></a></div>+ <button id="more${n}" aria-label="More" role="button" type="button">…</button>+ <div id="text${n}" data-testid="tweetText" lang="en"><span>Post ${n}</span></div>+ <div id="group${n}" role="group" aria-label="8 replies, ${likes} likes">+ <button aria-label="8 Replies. Reply" role="button" type="button">8</button>+ <button id="like${n}" aria-label="${likes} Likes. Like" role="button" type="button">${likes}</button>+ <button id="bookmark${n}" aria-label="Bookmark" role="button" type="button">B</button></div>+ </div></div></article></div>`;+const xTimeline = posts => `<main role="main"><section role="region" aria-labelledby="timeline-heading">+ <h1 id="timeline-heading">Your Home Timeline</h1><div aria-label="Timeline: Your Home Timeline">${posts}</div></section></main>`;+async function open(engine, build, body, targetId = 'more1') {const browser = await engine.launch({ headless: true });const context = await browser.newContext({ viewport: { width: 1000, height: 800 } });@@ -170,6 +193,71 @@ for (const build of ['chrome', 'firefox']) {} finally { await unlinked.browser.close(); }});+ test(`${build} on ${engineName}: an X post owns its controls`, async () => {+ // QA P1: "Open the third post on this timeline and bookmark it." Every+ // click on an X post was uncertified (owner_unresolved), so the+ // timeline's constant updates blocked each one.+ const timeline = xTimeline(xPost(1) + xPost(2, { name: 'Ada', handle: 'ada' }) + xPost(3, { name: 'Can', handle: 'can' }));+ for (const target of ['time1', 'bookmark1']) {+ const f = await open(engine, build, timeline, target);+ try {+ assert.equal((await f.validate()).ready, true, `${target}: the post's own control is certified`);+ // Another post of the timeline changes: not this post's context.+ await f.page.evaluate(() => {+ document.getElementById('author2').textContent = 'Mert';+ const like = document.getElementById('like2');+ like.textContent = '781'; like.setAttribute('aria-label', '781 Likes. Like');+ });+ assert.equal((await f.validate()).ready, true, `${target}: a change in another post keeps the decision`);+ // This post's own controls change.+ await f.page.evaluate(() => {+ const like = document.getElementById('like1');+ like.textContent = '781'; like.setAttribute('aria-label', '781 Likes. Like');+ });+ const counted = await f.validate();+ assert.equal(counted.ready, false, target);+ assert.equal(counted.reason, 'semantic_binding_changed', target);+ } finally { await f.browser.close(); }+ }+ // The post a status page shows is focusable outside the tab order.+ const status = await open(engine, build, xTimeline(xPost(1, { article: 'aria-labelledby="name{n} text{n} group{n}" tabindex="-1"' })+ + xPost(2, { name: 'Ada', handle: 'ada' })), 'bookmark1');+ try {+ assert.equal((await status.validate()).ready, true, 'The shown post\'s Bookmark is certified');+ } finally { await status.browser.close(); }+ // The virtualized cell is reused for another post.+ const f = await open(engine, build, timeline, 'bookmark1');+ try {+ assert.equal((await f.validate()).ready, true);+ await f.page.evaluate(() => {+ document.getElementById('author1').textContent = 'Deniz';+ document.getElementById('time1').setAttribute('href', '/deniz/status/2111904816545051999');+ });+ const reused = await f.validate();+ assert.equal(reused.ready, false);+ assert.equal(reused.reason, 'semantic_binding_changed');+ } finally { await f.browser.close(); }+ });++ test(`${build} on ${engineName}: an article that is not offered as one named, focusable, linked item owns nothing new`, async () => {+ const cases = [+ ['unfocusable', xPost(1, { article: 'aria-labelledby="name{n} text{n} group{n}"' })],+ ['with an invalid tabindex', xPost(1, { article: 'aria-labelledby="name{n} text{n} group{n}" tabindex="first"' })],+ ['unnamed', xPost(1, { article: 'tabindex="0"' })],+ ['named by a missing element', xPost(1, { article: 'aria-labelledby="name{n} missing-name" tabindex="0"' })],+ ['linking nowhere', xPost(1, { handle: 'illia', statusHref: '#' }).replaceAll('href="/illia"', 'href="#"')],+ ['holding an editor', xPost(1).replace('<div id="text1"', '<textarea aria-label="Reply"></textarea><div id="text1"')],+ ];+ for (const [name, post] of cases) {+ const f = await open(engine, build, xTimeline(post + xPost(2, { name: 'Ada', handle: 'ada' })), 'bookmark1');+ try {+ const result = await f.validate();+ assert.equal(result.ready, false, name);+ assert.equal(result.certificationFailure, 'owner_unresolved', name);+ } finally { await f.browser.close(); }+ }+ });+test(`${build} on ${engineName}: an article outside a feed, or without its place in one, owns nothing new`, async () => {for (const body of [`<main>${post(1, '2 dk')}${post(2, '9 dk')}</main>`,`<main><div role="feed">${post(1, '2 dk', { feedItem: false })}${post(2, '9 dk', { feedItem: false })}</div></main>`]) {