You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Show keyboard focus and more ARIA states in press and snapshot#2647
press doesn't report where focus lands, and snapshot doesn't mark the focused element. The snapshot also leaves out aria-pressed, aria-current, aria-haspopup and aria-controls. Could press return the focused element, and could the snapshot mark focus and include those four states?
Use case
We use an agent for keyboard accessibility QA. It tabs through a page and checks that each focus stop is the expected control, in the expected order. It opens a menu button with Enter and checks that focus moves into the menu. It also checks that toggle buttons report their pressed state and that navigation marks the current page.
Today that means an eval of document.activeElement after every key, plus our own snapshot script for the missing states. Menus are often rendered at the end of <body>, far from their trigger in the tree, and aria-controls is how the agent matches a menu to its button.
Request
press <key> reports the focused element after the key: role, name and ref.
snapshot marks the focused element.
snapshot shows aria-pressed, aria-current, aria-haspopup and aria-controls when set, plus the id of the element that aria-controls points to.
On this page, after press Tab, the snapshot could read:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Summary
pressdoesn't report where focus lands, andsnapshotdoesn't mark the focused element. The snapshot also leaves outaria-pressed,aria-current,aria-haspopupandaria-controls. Couldpressreturn the focused element, and could the snapshot mark focus and include those four states?Use case
We use an agent for keyboard accessibility QA. It tabs through a page and checks that each focus stop is the expected control, in the expected order. It opens a menu button with Enter and checks that focus moves into the menu. It also checks that toggle buttons report their pressed state and that navigation marks the current page.
Today that means an
evalofdocument.activeElementafter every key, plus our own snapshot script for the missing states. Menus are often rendered at the end of<body>, far from their trigger in the tree, andaria-controlsis how the agent matches a menu to its button.Request
press <key>reports the focused element after the key: role, name and ref.snapshotmarks the focused element.snapshotshowsaria-pressed,aria-current,aria-haspopupandaria-controlswhen set, plus theidof the element thataria-controlspoints to.On this page, after
press Tab, the snapshot could read:agent-browser open "data:text/html,<a href=%23 aria-current=page>Home</a><button aria-pressed=true>Bold</button><button aria-haspopup=menu aria-expanded=true aria-controls=m1>More</button><div role=menu id=m1><div role=menuitem tabindex=-1>Copy</div></div>"The output format is only a suggestion; the existing
[key=value, ref=…]style would work fine.If you'd accept this, I can implement it.
Found while evaluating agent-browser as a replacement for our Playwright wrapper; reproduced and drafted with Claude Code.
All reactions