Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
test(puppeteer): cover shadow accessibility workflows
ldm010fa77c49f15
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.mdindex 7c59d0051..4fa7bc95d 100644--- a/moli-cdp-smoke/README.md+++ b/moli-cdp-smoke/README.md@@ -156,6 +156,20 @@ both sessions. The identical probe timed out at the replacement evaluation after10,000 ms when Moli's parent-session renderer-inspector detach fix was removed,and passed after the fix was restored.+The Puppeteer Shadow DOM accessibility workflow was calibrated on 2026-10-08+with puppeteer-core 24.30.0 against `/usr/bin/chromium` 145.0.7632.116, then run+unchanged against Moli. `puppeteer_shadow_accessibility.mjs` checks default and+unfiltered accessibility snapshots across open, closed, and nested closed shadow+roots, assigned and fallback slots, and a host named from its shadow contents.+ShadowRoot `queryAXTree` requests using `objectId`, `nodeId`, and `backendNodeId`+must return the same backend refs as the full snapshot and stay within the host+subtree. Snapshot refs resolve to the same elements adopted by Puppeteer ARIA+selectors. Three `ElementHandle.click()` calls must emit exactly three trusted+clicks in open/closed/slotted order; updated names preserve AX and backend refs,+and old names stop matching. Removing and restoring a slot assignment must+switch the exposed fallback/assigned controls. The complete `--group puppeteer`+passed one run against each engine; use `--endpoint URL` for the Chromium run.+The `navigation-outcomes` group was calibrated on 2026-08-23 against Debian`/usr/bin/chromium` 145.0.7632.116 and then run unchanged against Moli. Itdirectly drives `Page.navigate` and correlates the result with the matching@@ -510,7 +524,7 @@ Runner layout:against a Chromium CDP endpoint before validating moli.- `groups/playwright_compat.py`: Playwright upstream derived route and CDPSession compatibility samples.- `groups/chrome_remote_interface.py`, `groups/cdp_use.py`, and `groups/stagehand.py`: optional published-client workflows, with subprocess and JSON-result handling shared by `groups/external_process.py`.-- `groups/puppeteer.py` and `puppeteer_smoke.mjs`: pinned Puppeteer workflows driven from the uv runner through Node.+- `groups/puppeteer.py` and `puppeteer_smoke.mjs`: pinned Puppeteer workflows driven from the uv runner through Node. `puppeteer_shadow_accessibility.mjs` covers Shadow DOM snapshots, scoped AX refs, ARIA handle clicks, and slot/name updates.- `groups/agent_browser.py`: optional real agent-browser CLI workflows with isolated config, daemon namespace, and endpoint identity verification.- `groups/network.py`: document/fetch/XHR routing, Network event observation, parser script and stylesheet body capture, WebSocket, and downloads.- `groups/workers.py`: dedicated worker `postMessage`, SharedWorker port reuse, worker fetch routing/auth, and worker XHR routing.diff --git a/moli-cdp-smoke/moli_cdp_smoke/puppeteer_shadow_accessibility.mjs b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_shadow_accessibility.mjsnew file mode 100644index 000000000..4dce2a2f8--- /dev/null+++ b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_shadow_accessibility.mjs@@ -0,0 +1,185 @@+import assert from 'node:assert/strict';++function buttonNames(snapshot) {+ assert.ok(snapshot, 'Puppeteer accessibility snapshot must have a root');+ const names = [];+ const pending = [snapshot];+ while (pending.length) {+ const node = pending.pop();+ if (node.role === 'button') {+ names.push(node.name);+ }+ pending.push(...(node.children ?? []));+ }+ return names.sort();+}++function buttonNode(nodes, name) {+ const matches = nodes.filter(node => !node.ignored+ && node.role?.value === 'button' && node.name?.value === name);+ assert.equal(matches.length, 1, `AX tree must contain exactly one button named ${name}`);+ assert.ok(matches[0].backendDOMNodeId, `${name} must have a backend DOM ref`);+ return matches[0];+}++export async function runPuppeteerShadowAccessibilitySmoke(page) {+ await page.evaluate(() => {+ document.body.innerHTML = `+ <div id="shadow-open"><button id="shadow-slotted" slot="action">Slotted action</button><button>Unassigned action</button></div>+ <div id="shadow-closed"></div>+ <div id="shadow-widget" role="button"></div>+ <button>Outside action</button>+ `;+ const open = document.querySelector('#shadow-open').attachShadow({ mode: 'open' });+ open.innerHTML = `+ <button id="shadow-open-button">Open action</button>+ <slot name="action"><button id="shadow-assigned-fallback">Assigned fallback action</button></slot>+ <slot name="empty"><button>Empty fallback action</button></slot>+ <div id="shadow-nested"></div>+ `;+ const nested = open.querySelector('#shadow-nested').attachShadow({ mode: 'closed' });+ nested.innerHTML = '<button>Nested action</button>';+ const closed = document.querySelector('#shadow-closed').attachShadow({ mode: 'closed' });+ closed.innerHTML = '<button id="shadow-closed-button">Closed action</button>';+ document.querySelector('#shadow-widget').attachShadow({ mode: 'open' })+ .innerHTML = '<span>Shadow host name</span>';+ globalThis.__puppeteerShadowRoots = { open, closed };+ globalThis.__puppeteerShadowClicks = [];+ for (const button of [+ open.querySelector('#shadow-open-button'),+ closed.querySelector('#shadow-closed-button'),+ document.querySelector('#shadow-slotted'),+ ]) {+ button.addEventListener('click', event => {+ __puppeteerShadowClicks.push({ id: button.id, trusted: event.isTrusted });+ button.textContent = button.textContent.replace(' action', ' clicked');+ });+ }+ });++ const expectedNames = [+ 'Closed action', 'Empty fallback action', 'Nested action', 'Open action',+ 'Outside action', 'Shadow host name', 'Slotted action',+ ];+ assert.deepEqual(buttonNames(await page.accessibility.snapshot()), expectedNames);+ assert.deepEqual(+ buttonNames(await page.accessibility.snapshot({ interestingOnly: false })),+ expectedNames,+ );++ const client = await page.createCDPSession();+ try {+ const { nodes: initialNodes } = await client.send('Accessibility.getFullAXTree');+ await client.send('DOM.getDocument', { depth: -1, pierce: true });+ for (const [mode, names] of [+ ['open', ['Empty fallback action', 'Nested action', 'Open action', 'Slotted action']],+ ['closed', ['Closed action']],+ ]) {+ const evaluated = await client.send('Runtime.evaluate', {+ expression: `__puppeteerShadowRoots.${mode}`,+ });+ const objectId = evaluated.result.objectId;+ assert.ok(objectId, `${mode} ShadowRoot must expose a CDP object`);+ try {+ const { nodeId } = await client.send('DOM.requestNode', { objectId });+ const { node } = await client.send('DOM.describeNode', { nodeId });+ assert.equal(node.shadowRootType, mode);+ const expectedRefs = names.map(name => buttonNode(initialNodes, name).backendDOMNodeId).sort();+ for (const reference of [{ objectId }, { nodeId }, { backendNodeId: node.backendNodeId }]) {+ const { nodes } = await client.send('Accessibility.queryAXTree', {+ ...reference, role: 'button',+ });+ assert.deepEqual(nodes.map(node => node.name?.value).sort(), names,+ `${mode} ShadowRoot query must stay within its host subtree`);+ assert.deepEqual(nodes.map(node => node.backendDOMNodeId).sort(), expectedRefs,+ `${mode} ShadowRoot query must reuse full-snapshot refs`);+ }+ } finally {+ await client.send('Runtime.releaseObject', { objectId });+ }+ }++ const actions = [+ ['Open action', 'Open clicked', 'shadow-open-button'],+ ['Closed action', 'Closed clicked', 'shadow-closed-button'],+ ['Slotted action', 'Slotted clicked', 'shadow-slotted'],+ ];+ for (const [name, , id] of actions) {+ const snapshotNode = buttonNode(initialNodes, name);+ const { object } = await client.send('DOM.resolveNode', {+ backendNodeId: snapshotNode.backendDOMNodeId,+ });+ assert.ok(object.objectId, `${name} snapshot ref must resolve to a DOM object`);+ try {+ const resolved = await client.send('Runtime.callFunctionOn', {+ objectId: object.objectId,+ functionDeclaration: 'function() { return this.id; }',+ returnByValue: true,+ });+ assert.equal(resolved.result.value, id);+ } finally {+ await client.send('Runtime.releaseObject', { objectId: object.objectId });+ }++ const handle = await page.$(`aria/${name}[role="button"]`);+ assert.ok(handle, `Puppeteer ARIA selector must match ${name}`);+ try {+ assert.equal(await handle.backendNodeId(), snapshotNode.backendDOMNodeId);+ assert.equal(await handle.evaluate(element => element.id), id);+ await handle.click();+ } finally {+ await handle.dispose();+ }+ }+ assert.deepEqual(await page.evaluate(() => __puppeteerShadowClicks),+ actions.map(([, , id]) => ({ id, trusted: true })));++ const { nodes: updatedNodes } = await client.send('Accessibility.getFullAXTree');+ for (const [oldName, newName] of actions) {+ const before = buttonNode(initialNodes, oldName);+ const after = buttonNode(updatedNodes, newName);+ assert.equal(after.nodeId, before.nodeId, 'Name changes must preserve the AX ref');+ assert.equal(after.backendDOMNodeId, before.backendDOMNodeId);+ const stale = await page.$(`aria/${oldName}[role="button"]`);+ try {+ assert.equal(stale, null, `ARIA queries must observe the updated name of ${oldName}`);+ } finally {+ await stale?.dispose();+ }+ }+ const updatedNames = expectedNames.map(name => actions.find(action => action[0] === name)?.[1] ?? name);+ assert.deepEqual(buttonNames(await page.accessibility.snapshot()), updatedNames.sort());++ await page.evaluate(() => { document.querySelector('#shadow-slotted').slot = 'unmatched'; });+ const fallback = await page.$('aria/Assigned fallback action[role="button"]');+ assert.ok(fallback, 'Removing the slot assignment must expose fallback content');+ try {+ assert.equal(await fallback.evaluate(element => element.id), 'shadow-assigned-fallback');+ } finally {+ await fallback.dispose();+ }+ const withoutAssignment = updatedNames.filter(name => name !== 'Slotted clicked');+ withoutAssignment.push('Assigned fallback action');+ assert.deepEqual(buttonNames(await page.accessibility.snapshot()), withoutAssignment.sort());++ await page.evaluate(() => { document.querySelector('#shadow-slotted').slot = 'action'; });+ assert.deepEqual(buttonNames(await page.accessibility.snapshot()), updatedNames);+ const reassigned = await page.$('aria/Slotted clicked[role="button"]');+ assert.ok(reassigned, 'Restoring the slot assignment must expose the assigned control');+ try {+ assert.equal(await reassigned.backendNodeId(), buttonNode(initialNodes, 'Slotted action').backendDOMNodeId);+ } finally {+ await reassigned.dispose();+ }++ return {+ shadowModes: ['open', 'closed', 'nested-closed'],+ queryReferences: ['objectId', 'nodeId', 'backendNodeId'],+ trustedClicks: actions.length,+ slotAssignmentChanges: 2,+ hostName: 'Shadow host name',+ };+ } finally {+ await client.detach();+ }+}diff --git a/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjs b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjsindex bfcbea330..7346976e3 100644--- a/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjs+++ b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjs@@ -5,6 +5,7 @@ import os from 'node:os';import path from 'node:path';import { runPuppeteerAriaQuerySmoke } from './puppeteer_aria_queries.mjs';+import { runPuppeteerShadowAccessibilitySmoke } from './puppeteer_shadow_accessibility.mjs';import {activateXPathElement,runPuppeteerDomInteractionSmoke,@@ -444,6 +445,12 @@ async function main() {);record('puppeteer_aria_selector_workflow', ariaQueryResult);+ const shadowAccessibilityResult = await withTimeout(+ 'Puppeteer Shadow DOM accessibility workflow',+ runPuppeteerShadowAccessibilitySmoke(page),+ );+ record('puppeteer_shadow_accessibility_workflow', shadowAccessibilityResult);+const domInteractionResult = await withTimeout('Puppeteer DOM interaction matrix',runPuppeteerDomInteractionSmoke(page),