fix(web): read visibility as rendered, null box, checkable values, embedded names

Merged
OK
2mo ago
+451-109

Web reads now report what renders, Playwright's way, and keep accessibility-tree exclusion separate. Fixes bug bash B51, B52, N46, N48, N49.

  • Render visibility vs a11y exclusion (packages/web/src/in-page/read-semantics.ts): isHidden (states.hidden, so toBeVisible/toBeHidden/isVisible/waitFor/visible: true) no longer treats aria-hidden as hidden. A decorative spinner marked aria-hidden stays visible until it leaves. hidesSubtree still drops aria-hidden and inert subtrees from the agent's observation, and role queries still skip them.

  • content-visibility: hidden: content under it (slotted content included) reads hidden. The element keeps its own box. The tree walk does not descend into it, and the element reports none of its own text, which matches its innerText.

  • N46: text directly under a display: contents; visibility: hidden element reads hidden. It paints nothing, but Playwright calls it visible, so this is a deliberate difference, written down in the docs.

  • N49: visibility: hidden no longer prunes the whole subtree in the tree walk, because a child can set visibility: visible and paint again. display: none still prunes.

  • visible: true narrowing: a new selector engine e2e-shown (packages/web/src/shown-selector.ts) runs the reader's own hidden check inside Playwright's chain. It replaces filter({ visible: true }) plus the old :not([aria-hidden]) step, so first(), filters, and scopes agree with toBeVisible() by construction.

  • B52:

    • rect is null when the element has no layout box. boundingBox() on a display: none node therefore returns null, matching Playwright, not {0,0,0,0}.
    • A checkbox or radio now reports its DOM value (on by default) in a locator read, whatever its checked state. The observation tree still leaves that value out, as it does for an option's.
    • getByDisplayValue no longer treats checkboxes and radios as candidates.
  • N48: an embedded control now adds to an accessible name the way Playwright's role selector reads it:

    • a textbox or searchbox adds its value
    • a select or listbox adds its selected options
    • a range widget adds aria-valuetext, else aria-valuenow, else its value

    A secure field adds nothing. Label text, which getByLabel matches, still leaves values out. 9 axe-core conformance cases now agree and were removed from tests/conformance/expected.txt.

  • Docs: docs/reference/screen.mdx now covers visibility semantics, a null box, and checkable values. A row in docs/migrate/playwright.mdx now says selectOption('x') matches the label only, where Playwright matches the value or the label; the table had said "same". The skill text and a changeset are updated too.

Verified

Ran it locally: yes

The scratch project /tmp/oskar-fix-web-visibility-reads/ runs the real built CLI (node packages/e2e/dist/cli/bin.js run --reporter list) against a static server. main uses an @e2e-dev/web dist built from origin/main; the branch uses this branch's dist.

casemainthis branch
B51 toBeHidden on an aria-hidden spinner that is removed after 900msisVisible() is false on the rendered spinner, so toBeHidden passes at oncepasses after 959ms, count 0
B51 button under content-visibility: hidden, toBeHiddenfails: observed visiblepasses
B52 boundingBox() on display: none{"x":0,"y":0,"width":0,"height":0}null
B52 checkbox inputValue() / toHaveValue('on'), radio toHaveValue('monthly')"", "not a form control"on, passes
N46 display: contents; visibility: hidden text, toBeHiddenfails: observed visiblepasses
N48 toHaveAccessibleName('Flash the screen 3 times')"Flash the screen times"passes, and getByRole finds it
getByText('Save', { visible: true }).first() with a hidden display: contents twin firstpicks the invisible twinpicks the button
N49 agent observation (e2e mcp, observe)button "Child visible" missinglisted

The observation through e2e mcp on the same page:

main:
 #n6004 text="Invisible text" testid="dc"
 #n6005 button "Flash the screen times" testid="flash"
  #n6006 textbox value="3"
 #n6007 text="Plan"
branch:
 #n6004 button "Flash the screen 3 times" text="Flash the screen times" testid="flash"
  #n6005 textbox value="3"
 #n6006 button "Child visible" testid="vischild"
 #n6007 text="Plan"

Tests in packages/web/tests/integration/ check each case against Playwright as the oracle (isHidden(), boundingBox(), inputValue(), getByRole({ name, exact })): visibility.test.ts, read-node-names.test.ts, read-node-checked.test.ts, lifecycle.test.ts. Run against main's src, 12 of them fail. Also run:

  • pnpm check, pnpm test, pnpm test:testbed, pnpm test:web-benchmark: all pass.
  • Crosscheck against the benchmark (CROSSCHECK_BENCHMARK_URL): passes. crosscheck/expected.txt is unchanged.
  • Web-benchmark test:agent replay: identical on main and this branch (25 replayed · 2 handed off · 4 missed, same 7 failures). The 7 come from no local AI_GATEWAY_API_KEY, so no committed recording changes.