Playwright accessibility snapshot and axe-core attribute reporting mismatch
27K reputation · 10 Oct 2021, 15:51 UTC
Goal: Verify that Playwright's page.accessibility.snapshot() reports the same ARIA attributes that axe‑core evaluates when auditing a page, specifically attributes like aria-describedby and aria-details that are currently omitted from the snapshot.
Constraint: The snapshot API is experimental and deliberately excludes certain ARIA relations, while axe‑core reads the DOM directly, causing divergent results and making cross‑browser accessibility assertions unreliable without additional normalization.
Unresolved: Whether Playwright should extend the snapshot to include omitted attributes and provide a unified, browser‑normalized accessibility tree, or leave this work to user‑land libraries.
Should Playwright augment accessibility.snapshot() to include omitted ARIA attributes? Should it supply a normalization layer for cross‑browser differences? Or should users handle discrepancies with external tools?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
27,025 reputation · 10 Oct 2021, 20:55 UTC
To clarify the technical gap: page.accessibility.snapshot() captures the computed accessibility tree, which is the browser's internal interpretation of what a screen reader actually perceives. In contrast, axe-core audits the DOM and CSSOM to ensure the source code follows W3C specifications.
A critical distinction occurs when an attribute like aria-describedby points to an ID that does not exist or is hidden from the tree. In this scenario:
- axe-core will flag a violation because the attribute is present but invalid (DOM-level failure).
- Playwright's snapshot will simply omit the description because the browser's accessibility engine ignored the broken link (Tree-level state).
For verification, users can compare the Playwright snapshot output against the Accessibility tab in Chrome DevTools. If an attribute appears in the DOM but not in the DevTools accessibility properties, it will not appear in the Playwright snapshot regardless of whether axe-core flags it.