Repository navigation
Add native accessibility tree snapshot via Chrome CDP - #26
compnew2006 wants to merge 1 commit into
Conversation
…native" browser_snapshot gains an opt-in `source: "native"`. Instead of the DOM walker it reads the tree Chrome itself computes (CDP Accessibility.getFullAXTree): exact roles, accessible names (aria-labelledby, <label>, native widget semantics), states (checked, expanded, invalid, heading level) and aria-hidden/inert exclusion. The default stays source:"dom" and never touches the debugger. The output has the same shape as the DOM snapshot and its refs work with every ref tool. Each AX node is bound to its real element in the existing page-side ref registry by a structural path (resolved through the main world, walked in the isolated world, tag-verified), so closed shadow roots and same-origin iframes work, same-named siblings stay distinct, and the smart-selector fallback and isNew behave as before. No page mutation. - per-frame AX trees grafted under their Iframe node; ids namespaced - bridge batched per frame (Chrome rejects mixing JS contexts in one call) - scoping by selector or ref (resolved in the page, located in a pierced DOM.getDocument dump with the same path grammar) - browser-internal controls with no element (a date input's sub-fields) are omitted from the compact tree and counted in unreachableNodes - if the debugger cannot attach, the DOM tree is returned with nativeUnavailable explaining why Verified in headless Chromium with the real extension, and through the real MCP client and daemon. Unit and integration tests added. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0197iXdHWDwMNUNW9NP9nTP5
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Why it isn't this PR's:
Fix (verified in a scratch copy, not pushed here to keep this PR scoped): lockfile-only bump of Suggested paths: land that bump on Generated by Claude Code |
Summary
Adds support for
browser_snapshot source:"native"to retrieve the accessibility tree directly from Chrome's accessibility engine (via CDPAccessibility.getFullAXTree) instead of approximating it from the DOM. This provides agents with the exact tree that assistive technology sees, including proper handling of ARIA, native widget roles, and accessibility state.Key Changes
New module
extension/lib/ax-native.js: Pure utility functions to transform Chrome's CDP accessibility nodes into the same compact/full tree shape the DOM walker produces, enabling agents and ref tools to work unchanged:shapeAxTree(): Converts flat CDP nodes into a nested tree with configurable depth, character budget, and compact/full modesmergeFrameTrees(): Grafts child frame accessibility trees under their owner iframe nodes with proper ID namespacingapplyBindings(): Settles the tree after page binding, attaching hrefs and removing unbound refspathOfTarget()andbackendIdAtPath(): Compute structural paths through shadow roots and iframes to resolve CDP node IDs to live elementsaxProps(),stateOf(),valueOf())New handler
extension/handlers/ax-snapshot.js: Orchestrates the native snapshot pipeline:backendNodeIdvalues to live page elements via the main worldIntegration in
extension/handlers/inspection.js: Routessource:"native"snapshots to the new handler while preserving DOM snapshot as the defaultComprehensive test coverage:
tests/ax-native.test.ts: Unit tests for tree shaping, frame merging, binding, and edge cases (truncation, depth limits, ref caps, scoping)tests/extension-ax-snapshot.test.ts: End-to-end tests with fake DOM and mocked CDP, verifying element binding across shadow roots and iframes, fallback generation, and selector scopingSchema and documentation updates: Added
sourceparameter tobrowser_snapshottool schema, updated agent guidance and README to document the native optionNotable Implementation Details
Runtime.callFunctionOncannot mix JS contexts; resolves paths per frameisNew: truefor incremental updateshttps://claude.ai/code/session_0197iXdHWDwMNUNW9NP9nTP5