@a11y-pulse/unreachable-controls-audit 0.0.0-stage → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,166 @@
1
+ Copyright (c) 2026-present, A11y Pulse (https://www.a11ypulse.com/). All rights reserved.
2
+
3
+ # PolyForm Shield License 1.0.0
4
+
5
+ <https://polyformproject.org/licenses/shield/1.0.0>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree
10
+ to them as both strict obligations and conditions to all
11
+ your licenses.
12
+
13
+ ## Copyright License
14
+
15
+ The licensor grants you a copyright license for the
16
+ software to do everything you might do with the software
17
+ that would otherwise infringe the licensor's copyright
18
+ in it for any permitted purpose. However, you may
19
+ only distribute the software according to [Distribution
20
+ License](#distribution-license) and make changes or new works
21
+ based on the software according to [Changes and New Works
22
+ License](#changes-and-new-works-license).
23
+
24
+ ## Distribution License
25
+
26
+ The licensor grants you an additional copyright license
27
+ to distribute copies of the software. Your license
28
+ to distribute covers distributing the software with
29
+ changes and new works permitted by [Changes and New Works
30
+ License](#changes-and-new-works-license).
31
+
32
+ ## Notices
33
+
34
+ You must ensure that anyone who gets a copy of any part of
35
+ the software from you also gets a copy of these terms or the
36
+ URL for them above, as well as copies of any plain-text lines
37
+ beginning with `Required Notice:` that the licensor provided
38
+ with the software. For example:
39
+
40
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
41
+
42
+ ## Changes and New Works License
43
+
44
+ The licensor grants you an additional copyright license to
45
+ make changes and new works based on the software for any
46
+ permitted purpose.
47
+
48
+ ## Patent License
49
+
50
+ The licensor grants you a patent license for the software that
51
+ covers patent claims the licensor can license, or becomes able
52
+ to license, that you would infringe by using the software.
53
+
54
+ ## Noncompete
55
+
56
+ Any purpose is a permitted purpose, except for providing any
57
+ product that competes with the software or any product the
58
+ licensor or any of its affiliates provides using the software.
59
+
60
+ ## Competition
61
+
62
+ Goods and services compete even when they provide functionality
63
+ through different kinds of interfaces or for different technical
64
+ platforms. Applications can compete with services, libraries
65
+ with plugins, frameworks with development tools, and so on,
66
+ even if they're written in different programming languages
67
+ or for different computer architectures. Goods and services
68
+ compete even when provided free of charge. If you market a
69
+ product as a practical substitute for the software or another
70
+ product, it definitely competes.
71
+
72
+ ## New Products
73
+
74
+ If you are using the software to provide a product that does
75
+ not compete, but the licensor or any of its affiliates brings
76
+ your product into competition by providing a new version of
77
+ the software or another product using the software, you may
78
+ continue using versions of the software available under these
79
+ terms beforehand to provide your competing product, but not
80
+ any later versions.
81
+
82
+ ## Discontinued Products
83
+
84
+ You may begin using the software to compete with a product
85
+ or service that the licensor or any of its affiliates has
86
+ stopped providing, unless the licensor includes a plain-text
87
+ line beginning with `Licensor Line of Business:` with the
88
+ software that mentions that line of business. For example:
89
+
90
+ > Licensor Line of Business: YoyodyneCMS Content Management
91
+ System (http://example.com/cms)
92
+
93
+ ## Sales of Business
94
+
95
+ If the licensor or any of its affiliates sells a line of
96
+ business developing the software or using the software
97
+ to provide a product, the buyer can also enforce
98
+ [Noncompete](#noncompete) for that product.
99
+
100
+ ## Fair Use
101
+
102
+ You may have "fair use" rights for the software under the
103
+ law. These terms do not limit them.
104
+
105
+ ## No Other Rights
106
+
107
+ These terms do not allow you to sublicense or transfer any of
108
+ your licenses to anyone else, or prevent the licensor from
109
+ granting licenses to anyone else. These terms do not imply
110
+ any other licenses.
111
+
112
+ ## Patent Defense
113
+
114
+ If you make any written claim that the software infringes or
115
+ contributes to infringement of any patent, your patent license
116
+ for the software granted under these terms ends immediately. If
117
+ your company makes such a claim, your patent license ends
118
+ immediately for work on behalf of your company.
119
+
120
+ ## Violations
121
+
122
+ The first time you are notified in writing that you have
123
+ violated any of these terms, or done anything with the software
124
+ not covered by your licenses, your licenses can nonetheless
125
+ continue if you come into full compliance with these terms,
126
+ and take practical steps to correct past violations, within
127
+ 32 days of receiving notice. Otherwise, all your licenses
128
+ end immediately.
129
+
130
+ ## No Liability
131
+
132
+ ***As far as the law allows, the software comes as is, without
133
+ any warranty or condition, and the licensor will not be liable
134
+ to you for any damages arising out of these terms or the use
135
+ or nature of the software, under any kind of legal claim.***
136
+
137
+ ## Definitions
138
+
139
+ The **licensor** is the individual or entity offering these
140
+ terms, and the **software** is the software the licensor makes
141
+ available under these terms.
142
+
143
+ A **product** can be a good or service, or a combination
144
+ of them.
145
+
146
+ **You** refers to the individual or entity agreeing to these
147
+ terms.
148
+
149
+ **Your company** is any legal entity, sole proprietorship,
150
+ or other kind of organization that you work for, plus all
151
+ its affiliates.
152
+
153
+ **Affiliates** means the other organizations than an
154
+ organization has control over, is under the control of, or is
155
+ under common control with.
156
+
157
+ **Control** means ownership of substantially all the assets of
158
+ an entity, or the power to direct its management and policies
159
+ by vote, contract, or otherwise. Control can be direct or
160
+ indirect.
161
+
162
+ **Your licenses** are all the licenses granted to you for the
163
+ software under these terms.
164
+
165
+ **Use** means anything you do with the software requiring one
166
+ of your licenses.
package/README.md CHANGED
@@ -1,3 +1,285 @@
1
- # Temporary Holding Version
1
+ # @a11y-pulse/unreachable-controls-audit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@a11y-pulse/unreachable-controls-audit)](https://www.npmjs.com/package/@a11y-pulse/unreachable-controls-audit)
4
+ [![CI](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml/badge.svg)](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml)
5
+ [![License: PolyForm Shield 1.0.0](https://img.shields.io/badge/license-PolyForm%20Shield%201.0.0-blue)](./LICENSE.md)
6
+
7
+ An accessibility audit for [**WCAG 2.2: 2.1.1 Keyboard**](https://www.w3.org/WAI/WCAG22/Understanding/keyboard) and [**4.1.2 Name, Role, Value**](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value). It tabs through a page, then scans it for two things:
8
+
9
+ - **Controls the keyboard never reaches:** elements that handle clicks or have a widget role, but are not in the tab order and have nothing focusable in or around them. A `<div>` with a click listener and no `tabindex` is the usual case.
10
+ - **Focusable controls with no role:** elements that did take focus and handle clicks or key presses, but expose no role, so a screen reader announces them as plain text.
11
+
12
+ It is built to be framework-agnostic and can be used in any environment that allows you to programmatically focus elements and observe the page, such as Puppeteer, Playwright, or Selenium. In Chromium it also asks the browser which event listeners each element has, which is the only way to see a control wired up with `addEventListener`.
13
+
14
+ This audit was developed by [A11y Pulse](https://www.a11ypulse.com/) for its accessibility monitoring service. It is released as source-available under the [PolyForm Shield License 1.0.0](#license).
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @a11y-pulse/unreachable-controls-audit @a11y-pulse/tab-orchestrator @a11y-pulse/browser-adaptor puppeteer
20
+ ```
21
+
22
+ ## Quickstart
23
+
24
+ ```js
25
+ import { runUnreachableControlsAudit } from "@a11y-pulse/unreachable-controls-audit";
26
+ import { PuppeteerAdaptor } from "@a11y-pulse/unreachable-controls-audit/puppeteer";
27
+ import puppeteer from "puppeteer";
28
+
29
+ const browser = await puppeteer.launch({ defaultViewport: { width: 1280, height: 800 } });
30
+ const page = await browser.newPage();
31
+ await page.goto("https://who.likesdogs.nz/");
32
+
33
+ const result = await runUnreachableControlsAudit(new PuppeteerAdaptor(page));
34
+
35
+ console.log(result.outcome);
36
+ // 'findings'
37
+
38
+ console.log(result.unreachable[0]);
39
+ // { selector: '#card-1', verdict: 'failed', reason: 'click-handler', signals: { listeners: ['click'], ... }, ... }
40
+
41
+ await browser.close();
42
+ ```
43
+
44
+ For Playwright, import `PlaywrightAdaptor` from `@a11y-pulse/unreachable-controls-audit/playwright`.
45
+
46
+ ## Shared tab session
47
+
48
+ To run alongside other tab-driven audits on one tab loop, attach the consumer to a shared orchestrator and call `analyse` once the session has run:
49
+
50
+ ```ts
51
+ import { createTabOrchestrator } from "@a11y-pulse/tab-orchestrator";
52
+ import { createUnreachableControlsAudit } from "@a11y-pulse/unreachable-controls-audit";
53
+ import { PuppeteerAdaptor } from "@a11y-pulse/unreachable-controls-audit/puppeteer";
54
+
55
+ const adaptor = new PuppeteerAdaptor(page);
56
+ const orchestrator = createTabOrchestrator(adaptor);
57
+
58
+ const unreachableControls = createUnreachableControlsAudit();
59
+ orchestrator.attach(unreachableControls);
60
+
61
+ const startHref = await page.url();
62
+ await orchestrator.run();
63
+
64
+ const result = await unreachableControls.analyse(adaptor, startHref);
65
+ ```
66
+
67
+ The audit declares no capabilities, so it adds nothing to each tab stop: it only notes which element took focus. `analyse` then makes one call into the page to collect candidates, one round of browser inspection where the adaptor supports it, and two short calls per finding for its selector. Call `analyse` before anything else changes the page (activates a control, resizes the viewport), and pass it the page's URL from before the session so that a navigation the session did not notice makes the result inconclusive.
68
+
69
+ If you already have an adaptor of your own, give it an `inspectElements` method using the helper each adaptor module exports:
70
+
71
+ ```ts
72
+ import { inspectElements } from "@a11y-pulse/unreachable-controls-audit/puppeteer";
73
+
74
+ const adaptor = Object.assign(existingAdaptor, {
75
+ inspectElements: (stashKey, count, roles) => inspectElements(page, stashKey, count, roles),
76
+ });
77
+ ```
78
+
79
+ ## How it decides
80
+
81
+ ### Controls the keyboard never reaches
82
+
83
+ An element is a candidate when it is rendered, is not itself in the tab order, and has nothing focusable inside it or around it. Among candidates:
84
+
85
+ | Evidence | Verdict | `reason` |
86
+ | --- | --- | --- |
87
+ | A widget role (`button`, `link`, `checkbox`, `switch`, `radio`, `tab`, `menuitem`, `option`, `slider`, `textbox`, `combobox`, `treeitem`...) | failed | `widget-role` |
88
+ | Handles `click` or `dblclick` (an `onclick` attribute or property, or a listener the browser reported) | failed | `click-handler` |
89
+ | A `<label>` whose form control is not drawn (it, or anything around it, is `display: none` or `visibility: hidden`) and has no focusable stand-in, so only clicking the label can change it | failed | `hidden-control-label` |
90
+ | Handles `click`, but holds more than ten elements or covers more than 30% of the viewport, and shows no pointer cursor | review | `container-handler` |
91
+ | Handles `click` only through a listener that at least half of the page's unreached elements also carry (20 or more elements examined), with no `onclick` and no pointer cursor of its own. At most five are listed | review | `blanket-listener` |
92
+ | A control with `tabindex="-1"` that is not part of a widget that manages focus | review | `script-focus-only` |
93
+ | Handles pointer or touch presses (`mousedown`, `pointerdown`, `touchstart`...) but not `click` | review | `press-handler` |
94
+ | Nothing but a pointer cursor set on this element | review | `pointer-cursor` |
95
+
96
+ These are left alone:
97
+
98
+ - **Anything around something focusable.** A card with a click listener and a link inside it, a table row that opens the record its first cell links to, and a listener delegated to a wrapper, `<body>` or `document` all hold a tab stop, so they are a convenience and not a control of their own.
99
+ - **Anything inside something focusable**, such as an icon with a handler inside a button.
100
+ - **Framework roots and portal containers.** An element listening for ten or more event types, at least three of which no single control listens for (`submit`, `change`, `input`, `paste`, `load`...), carries a framework's delegated event set: React attaches every event it supports to its root and to each portal container. Such an element is not reported unless it also has a widget role or an `onclick` of its own.
101
+ - **Labels of focusable controls**, and labels of a hidden control that a focusable widget stands in for: one named by the same label through `aria-labelledby`, or one right beside the hidden control (the way Chosen and Select2 replace a `<select>`). Beside a hidden checkbox or radio button, only a neighbour with the role `checkbox`, `switch`, `radio` or `button` counts.
102
+ - **Children of a composite widget that manages focus itself.** Inside a `tablist`, `menu`, `menubar`, `listbox`, `grid`, `treegrid`, `radiogroup`, `toolbar`, `tree` or `combobox`, one element takes the tab stop and arrow keys move among the rest. The widget counts as managed when it or one of its descendants is in the tab order, when it has `aria-activedescendant`, or when a focusable element points at it with `aria-controls`, `aria-owns` or `aria-activedescendant`. Children of a composite that nothing can focus are reported.
103
+ - **Roving tab stops without a composite role:** a `tabindex="-1"` element beside a tabbable element with the same tag and role.
104
+ - **Hidden, `aria-hidden`, `inert` and disabled content**, and native controls taken out of the tab order with `tabindex="-1"`.
105
+ - **Backdrops:** an element with no text or graphics that covers more than 30% of the viewport, which a dialog's close button duplicates.
106
+
107
+ A review of an element that contains, or sits inside, a failed control is dropped as saying nothing new.
108
+
109
+ ### Focusable controls with no role
110
+
111
+ For each element that took focus during the tab pass and is not a native control:
112
+
113
+ | Evidence | Verdict | `reason` |
114
+ | --- | --- | --- |
115
+ | Handles `click` or key presses, with no `role` (or `presentation`, `none`, `generic`) | failed | `handler-without-role` |
116
+ | The same on a custom element, when the browser could not be asked what role it exposes | review | `custom-element` |
117
+ | No handler found, but a pointer cursor | review | `pointer-cursor` |
118
+ | Handles `click` or key presses but holds other tab stops (a scrolling region made focusable, whose listeners serve the buttons inside), or carries a framework's delegated event set | review | `container-handler` |
119
+ | Handles only `click`, through a listener most elements on the page also carry | review | `blanket-listener` |
120
+
121
+ An element with any other `role` attribute is passed, as is one the browser exposes with a control's role (a custom element that sets its role through `ElementInternals`). A focusable element with no handler and no pointer cursor, such as a scrollable region given `tabindex="0"`, is not reported.
122
+
123
+ ### When the tab pass stops early
124
+
125
+ If the session ends for any reason other than reaching the end of the tab order (`limit`, `stuck`, `lostFocus`, `navigation`, `failed`), or the audit's own `elementLimit` or `timeout` cuts it short, the result is `inconclusive` and nothing is reported: the pass has not shown what Tab reaches, and may have left the page in another state.
126
+
127
+ ## Browser support
128
+
129
+ | Adaptor | Browser | Supported | Listeners inspected |
130
+ | --- | --- | --- | --- |
131
+ | Puppeteer | Chrome | Yes | Yes |
132
+ | Playwright | Chromium | Yes | Yes |
133
+ | Playwright | Firefox | Yes | **No.** Only handlers set with an `on…` attribute or property are seen, so a control wired up with `addEventListener` alone is found by its role, or reported for review by its cursor. |
134
+ | Playwright | WebKit | **No.** WebKit does not move focus to links when Tab is pressed, so the audit only reaches a subset of the page. | No |
135
+
136
+ `result.listenersInspected` says which applied.
137
+
138
+ ## Adaptor requirements
139
+
140
+ The audit runs against a `BrowserAdaptor` from `@a11y-pulse/browser-adaptor`. One optional method adds what only the browser knows:
141
+
142
+ ```ts
143
+ interface UnreachableControlsAdaptor extends BrowserAdaptor {
144
+ /**
145
+ * Inspect each element of the array a page script left on window[stashKey], in order. `roles`
146
+ * lists the indices whose accessibility role is wanted. Resolve to null when the browser cannot
147
+ * be asked.
148
+ */
149
+ inspectElements?(
150
+ stashKey: string,
151
+ count: number,
152
+ roles: readonly number[],
153
+ ): Promise<Array<{ listeners: string[]; role: string | null }> | null>;
154
+ }
155
+ ```
156
+
157
+ The bundled adaptors implement it over the Chrome DevTools Protocol (`DOMDebugger.getEventListeners` and `Accessibility.getPartialAXTree`), on a session they open and close for the call.
158
+
159
+ ## Options
160
+
161
+ | Option | Type | Default | Description |
162
+ | --- | --- | --- | --- |
163
+ | `elementLimit` | `number` | `1024` | Max focusable elements to tab through. Hitting it makes the result inconclusive. |
164
+ | `screenshotSettleDelay` | `number` | `33` | How long to wait (in ms) after each Tab for the page to settle. |
165
+ | `timeout` | `number` | `0` (no timeout) | Limit how long (in ms) the tab loop runs. Hitting it makes the result inconclusive. |
166
+ | `candidateLimit` | `number` | `500` | Max elements examined as possible controls. Elements with a sign of being one (a handler property, a widget role, a pointer cursor, `tabindex="-1"`) are taken first; the rest are only examined when listeners can be inspected. |
167
+ | `findingLimit` | `number` | `50` | Max findings reported across `unreachable` and `missingRole`. Failures are kept ahead of reviews. |
168
+
169
+ ## Result shape
170
+
171
+ ```ts
172
+ type UnreachableControlsResult = {
173
+ /**
174
+ * `clean` is not proof that every control is reachable: see Limitations.
175
+ * `inconclusive` means the tab pass did not cover the page, or the page could not be scanned.
176
+ */
177
+ outcome: "findings" | "clean" | "inconclusive";
178
+ inconclusiveReason?:
179
+ | "session-ended-early"
180
+ | "element-limit"
181
+ | "timeout"
182
+ | "navigated"
183
+ | "scan-failed";
184
+ /** Controls Tab never reached, in document order. */
185
+ unreachable: Array<{
186
+ selector: string;
187
+ html: string;
188
+ /** Start of the element's text. */
189
+ text: string;
190
+ verdict: "failed" | "review";
191
+ reason:
192
+ | "widget-role"
193
+ | "click-handler"
194
+ | "hidden-control-label"
195
+ | "container-handler"
196
+ | "script-focus-only"
197
+ | "press-handler"
198
+ | "pointer-cursor"
199
+ | "blanket-listener";
200
+ signals: ControlSignals;
201
+ }>;
202
+ /** Focused elements that act as controls but expose no role, in tab order. */
203
+ missingRole: Array<{
204
+ selector: string;
205
+ html: string;
206
+ text: string;
207
+ verdict: "failed" | "review";
208
+ reason:
209
+ | "handler-without-role"
210
+ | "custom-element"
211
+ | "pointer-cursor"
212
+ | "container-handler"
213
+ | "blanket-listener";
214
+ signals: ControlSignals;
215
+ /** The role the browser exposes (`generic` for a plain div), or null when it was not asked. */
216
+ computedRole: string | null;
217
+ /** 1-based tab stop at which the element took focus. */
218
+ tabIndex: number;
219
+ }>;
220
+ /** The browser was asked which listeners each element has. */
221
+ listenersInspected: boolean;
222
+ /**
223
+ * `candidateLimit` or `findingLimit` cut the scan or the findings short, or only a sample of the
224
+ * `blanket-listener` elements is listed.
225
+ */
226
+ truncated: boolean;
227
+ summary: {
228
+ /** Tab stops recorded. */
229
+ checked: number;
230
+ passed: number;
231
+ /** Findings with verdict `failed`. */
232
+ failed: number;
233
+ reachedLimit: boolean;
234
+ reachedFailedElementLimit: boolean;
235
+ timedOut: boolean;
236
+ sessionEnd: "completed" | "lostFocus" | "navigation" | "failed" | "stuck" | "limit" | null;
237
+ };
238
+ };
239
+
240
+ /** Why an element was taken to be a control. */
241
+ type ControlSignals = {
242
+ /** Pointer and keyboard event types handled on the element itself. */
243
+ listeners: string[];
244
+ /** The `role` attribute, or null. */
245
+ role: string | null;
246
+ /** The computed cursor is `pointer`. */
247
+ cursorPointer: boolean;
248
+ /** The `tabindex` attribute, or null. */
249
+ tabindex: number | null;
250
+ };
251
+ ```
252
+
253
+ ## Limitations
254
+
255
+ - **Delegated listeners say nothing about the control.** A click handled by a listener on an ancestor, `<body>` or `document` leaves nothing on the element itself. The browser does report the listeners on the element a framework delegates to (React attaches every event it supports to its root and to each portal container), but those show where the framework listens, not which elements inside respond, so that element is recognised by its event set and left alone. A control in a React page, or one wired up by jQuery-style delegation, is therefore reported for review at most, by its pointer cursor.
256
+ - **Finding limit.** When more is found than `findingLimit` allows, failures are kept first, then reviews, then `blanket-listener` elements, and `truncated` is set.
257
+ - **Listeners need Chromium.** Elsewhere only `on…` handlers, roles and cursors are seen.
258
+ - **Reachable is not operable.** An element in the tab order that ignores Enter and Space is not reported, and neither is a composite widget whose arrow keys do nothing: the audit does not press keys on controls.
259
+ - **Shortcuts are not counted.** A control reachable only through a keyboard shortcut, or through another control that does the same thing elsewhere on the page, is still reported.
260
+ - **One page state, one viewport.** Controls inside closed menus, dialogs and collapsed sections are not rendered and so are not examined.
261
+ - **Shadow DOM.** Open shadow roots are scanned; closed ones are not. `aria-controls` and its relatives are only followed within the document, not into or out of a shadow root.
262
+ - **Frames are not entered.**
263
+ - **The page as it stands after the pass.** The scan runs once the tab pass has finished, so a control that was added or removed while tabbing is judged by its final state.
264
+
265
+ ## Known false positives
266
+
267
+ Cases where the audit reports a problem that is not one. Each says which bucket it lands in.
268
+
269
+ - **A click target that duplicates another control** (`failed`). A card with a click listener beside, not around, its "View" link, or a hero image that opens the same page as the button below it. The audit only knows a control is duplicated when the focusable one is inside it.
270
+ - **Click listeners that are not controls** (`failed`). A listener that only tracks clicks for analytics, stops propagation or closes a menu when clicked outside is indistinguishable from one that does something. On small elements these fail; on large containers with no pointer cursor they are sent for review as `container-handler`, and when a script puts one on most elements of the page they are sent for review as `blanket-listener`. A tracking script that instruments fewer than half of the unreached elements, or a page with fewer than 20 of them, still fails each one.
271
+ - **A hidden control replaced by a widget that is not beside it** (`failed`). The label of a `display: none` select or checkbox is passed when a focusable widget sits right before or after the control or uses the label as its name. A replacement placed elsewhere and named some other way is not recognised, so the label is reported as `hidden-control-label`.
272
+ - **Widgets that manage focus without saying so** (`failed` or `review`). A custom listbox or menu with no composite role, whose items have a role but no `tabindex` and are moved through with arrow keys by a script, has its items reported. Giving the container the role it acts as, or the pattern's `aria-activedescendant`, fixes both the report and the widget.
273
+ - **Swipe areas and drag handles** (`review`). A carousel track or a splitter that listens for pointer presses is reported as `press-handler` even where arrow buttons or keys do the same.
274
+ - **Decorative pointer cursors** (`review`). A card with a hover effect and `cursor: pointer` but no behaviour is reported as `pointer-cursor`.
275
+ - **Focus targets with a pointer cursor** (`review`). A focusable element that is not a control but inherits `cursor: pointer` from a clickable ancestor is reported as a possible missing role.
276
+
277
+ ## License
278
+
279
+ Released under the [PolyForm Shield License 1.0.0](./LICENSE.md), in plain language:
280
+
281
+ - **Source-available.** The source is public and you can read, fork, and modify it.
282
+ - **Permitted for non-competing use.** You can use this package freely in your own products and services, as long as they don't compete with A11y Pulse.
283
+ - **Competing products are forbidden.** You may not use this software (or a modified version of it) to build a product or service that competes with A11y Pulse's accessibility monitoring offering.
284
+
285
+ See [LICENSE.md](./LICENSE.md) for the full, binding terms.
@@ -0,0 +1,24 @@
1
+ import type { BrowserAdaptor } from "@a11y-pulse/browser-adaptor";
2
+ export type { BrowserAdaptor, ElementRef } from "@a11y-pulse/browser-adaptor";
3
+ /** What the browser itself knows about one element, which no page script can read. */
4
+ export type ElementInspection = {
5
+ /** Event types with a listener registered directly on the element, such as `click`. */
6
+ listeners: string[];
7
+ /** The role the browser exposes in its accessibility tree, or null when it could not be read. */
8
+ role: string | null;
9
+ };
10
+ /**
11
+ * The adaptor the audit runs against. `inspectElements` is optional: without it the audit only
12
+ * knows about handlers a page script can see (an `onclick` attribute or property), widget roles and
13
+ * the pointer cursor, so a control wired up with `addEventListener` alone is reported for review
14
+ * at most.
15
+ */
16
+ export interface UnreachableControlsAdaptor extends BrowserAdaptor {
17
+ /**
18
+ * Inspect each element of the array a page script left on `window[stashKey]`, in order, and
19
+ * resolve to one entry per element. Resolve to null when the browser cannot be asked (anything
20
+ * other than Chromium), which the audit treats the same as the method being absent. `roles` lists
21
+ * the indices whose accessibility role is wanted; `role` is null for every other element.
22
+ */
23
+ inspectElements?(stashKey: string, count: number, roles: readonly number[]): Promise<ElementInspection[] | null>;
24
+ }
@@ -0,0 +1,12 @@
1
+ import type { ElementInspection } from "../adaptor";
2
+ /** The part of a Chrome DevTools Protocol session this needs, as Puppeteer and Playwright expose it. */
3
+ export type CdpSession = {
4
+ send(method: any, params?: any): Promise<any>;
5
+ detach(): Promise<unknown>;
6
+ };
7
+ /**
8
+ * Ask Chromium which event listeners sit on each element of the array at `window[stashKey]`, and
9
+ * the accessibility role of those listed in `roles`. An element the browser cannot answer for
10
+ * comes back with no listeners and a null role.
11
+ */
12
+ export declare function inspectStashedElements(session: CdpSession, stashKey: string, count: number, roles: readonly number[]): Promise<ElementInspection[]>;
@@ -0,0 +1,16 @@
1
+ import { PlaywrightAdaptor as BrowserPlaywrightAdaptor, type PlaywrightAdaptorOptions } from "@a11y-pulse/browser-adaptor/playwright";
2
+ import type { Page } from "playwright-core";
3
+ import type { ElementInspection, UnreachableControlsAdaptor } from "../adaptor";
4
+ export type { PlaywrightAdaptorOptions } from "@a11y-pulse/browser-adaptor/playwright";
5
+ /**
6
+ * Inspect the elements a page script stashed on `window[stashKey]` over a DevTools session of its
7
+ * own. Null on Firefox and WebKit, which have no such session. Use it to give an existing adaptor
8
+ * an `inspectElements`.
9
+ */
10
+ export declare function inspectElements(page: Page, stashKey: string, count: number, roles: readonly number[]): Promise<ElementInspection[] | null>;
11
+ /** An UnreachableControlsAdaptor backed by a Playwright Page. */
12
+ export declare class PlaywrightAdaptor extends BrowserPlaywrightAdaptor implements UnreachableControlsAdaptor {
13
+ private readonly inspectedPage;
14
+ constructor(page: Page, options?: PlaywrightAdaptorOptions);
15
+ inspectElements(stashKey: string, count: number, roles: readonly number[]): Promise<ElementInspection[] | null>;
16
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ inspectStashedElements
3
+ } from "../chunk-64WLKNK6.js";
4
+
5
+ // src/adaptors/playwright.ts
6
+ import {
7
+ PlaywrightAdaptor as BrowserPlaywrightAdaptor
8
+ } from "@a11y-pulse/browser-adaptor/playwright";
9
+ async function inspectElements(page, stashKey, count, roles) {
10
+ let session;
11
+ try {
12
+ session = await page.context().newCDPSession(page);
13
+ } catch {
14
+ return null;
15
+ }
16
+ try {
17
+ return await inspectStashedElements(session, stashKey, count, roles);
18
+ } catch {
19
+ return null;
20
+ } finally {
21
+ await session.detach().catch(() => {
22
+ });
23
+ }
24
+ }
25
+ var PlaywrightAdaptor = class extends BrowserPlaywrightAdaptor {
26
+ inspectedPage;
27
+ constructor(page, options = {}) {
28
+ super(page, options);
29
+ this.inspectedPage = page;
30
+ }
31
+ inspectElements(stashKey, count, roles) {
32
+ return inspectElements(this.inspectedPage, stashKey, count, roles);
33
+ }
34
+ };
35
+ export {
36
+ PlaywrightAdaptor,
37
+ inspectElements
38
+ };
39
+ //# sourceMappingURL=playwright.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adaptors/playwright.ts"],"sourcesContent":["import {\n\tPlaywrightAdaptor as BrowserPlaywrightAdaptor,\n\ttype PlaywrightAdaptorOptions,\n} from \"@a11y-pulse/browser-adaptor/playwright\";\nimport type { Page } from \"playwright-core\";\nimport type { ElementInspection, UnreachableControlsAdaptor } from \"../adaptor\";\nimport { type CdpSession, inspectStashedElements } from \"./cdp\";\n\nexport type { PlaywrightAdaptorOptions } from \"@a11y-pulse/browser-adaptor/playwright\";\n\n/**\n * Inspect the elements a page script stashed on `window[stashKey]` over a DevTools session of its\n * own. Null on Firefox and WebKit, which have no such session. Use it to give an existing adaptor\n * an `inspectElements`.\n */\nexport async function inspectElements(\n\tpage: Page,\n\tstashKey: string,\n\tcount: number,\n\troles: readonly number[],\n): Promise<ElementInspection[] | null> {\n\tlet session: CdpSession;\n\n\ttry {\n\t\tsession = await page.context().newCDPSession(page);\n\t} catch {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\treturn await inspectStashedElements(session, stashKey, count, roles);\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tawait session.detach().catch(() => {});\n\t}\n}\n\n/** An UnreachableControlsAdaptor backed by a Playwright Page. */\nexport class PlaywrightAdaptor\n\textends BrowserPlaywrightAdaptor\n\timplements UnreachableControlsAdaptor\n{\n\tprivate readonly inspectedPage: Page;\n\n\tconstructor(page: Page, options: PlaywrightAdaptorOptions = {}) {\n\t\tsuper(page, options);\n\t\tthis.inspectedPage = page;\n\t}\n\n\tinspectElements(\n\t\tstashKey: string,\n\t\tcount: number,\n\t\troles: readonly number[],\n\t): Promise<ElementInspection[] | null> {\n\t\treturn inspectElements(this.inspectedPage, stashKey, count, roles);\n\t}\n}\n"],"mappings":";;;;;AAAA;AAAA,EACC,qBAAqB;AAAA,OAEf;AAYP,eAAsB,gBACrB,MACA,UACA,OACA,OACsC;AACtC,MAAI;AAEJ,MAAI;AACH,cAAU,MAAM,KAAK,QAAQ,EAAE,cAAc,IAAI;AAAA,EAClD,QAAQ;AACP,WAAO;AAAA,EACR;AAEA,MAAI;AACH,WAAO,MAAM,uBAAuB,SAAS,UAAU,OAAO,KAAK;AAAA,EACpE,QAAQ;AACP,WAAO;AAAA,EACR,UAAE;AACD,UAAM,QAAQ,OAAO,EAAE,MAAM,MAAM;AAAA,IAAC,CAAC;AAAA,EACtC;AACD;AAGO,IAAM,oBAAN,cACE,yBAET;AAAA,EACkB;AAAA,EAEjB,YAAY,MAAY,UAAoC,CAAC,GAAG;AAC/D,UAAM,MAAM,OAAO;AACnB,SAAK,gBAAgB;AAAA,EACtB;AAAA,EAEA,gBACC,UACA,OACA,OACsC;AACtC,WAAO,gBAAgB,KAAK,eAAe,UAAU,OAAO,KAAK;AAAA,EAClE;AACD;","names":[]}
@@ -0,0 +1,16 @@
1
+ import { PuppeteerAdaptor as BrowserPuppeteerAdaptor, type PuppeteerAdaptorOptions } from "@a11y-pulse/browser-adaptor/puppeteer";
2
+ import type { Page } from "puppeteer";
3
+ import type { ElementInspection, UnreachableControlsAdaptor } from "../adaptor";
4
+ export type { PuppeteerAdaptorOptions } from "@a11y-pulse/browser-adaptor/puppeteer";
5
+ /**
6
+ * Inspect the elements a page script stashed on `window[stashKey]` over a DevTools session of its
7
+ * own. Null when the session cannot be opened. Use it to give an existing adaptor an
8
+ * `inspectElements`.
9
+ */
10
+ export declare function inspectElements(page: Page, stashKey: string, count: number, roles: readonly number[]): Promise<ElementInspection[] | null>;
11
+ /** An UnreachableControlsAdaptor backed by a Puppeteer Page. */
12
+ export declare class PuppeteerAdaptor extends BrowserPuppeteerAdaptor implements UnreachableControlsAdaptor {
13
+ private readonly inspectedPage;
14
+ constructor(page: Page, options?: PuppeteerAdaptorOptions);
15
+ inspectElements(stashKey: string, count: number, roles: readonly number[]): Promise<ElementInspection[] | null>;
16
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ inspectStashedElements
3
+ } from "../chunk-64WLKNK6.js";
4
+
5
+ // src/adaptors/puppeteer.ts
6
+ import {
7
+ PuppeteerAdaptor as BrowserPuppeteerAdaptor
8
+ } from "@a11y-pulse/browser-adaptor/puppeteer";
9
+ async function inspectElements(page, stashKey, count, roles) {
10
+ let session;
11
+ try {
12
+ session = await page.createCDPSession();
13
+ } catch {
14
+ return null;
15
+ }
16
+ try {
17
+ return await inspectStashedElements(session, stashKey, count, roles);
18
+ } catch {
19
+ return null;
20
+ } finally {
21
+ await session.detach().catch(() => {
22
+ });
23
+ }
24
+ }
25
+ var PuppeteerAdaptor = class extends BrowserPuppeteerAdaptor {
26
+ inspectedPage;
27
+ constructor(page, options = {}) {
28
+ super(page, options);
29
+ this.inspectedPage = page;
30
+ }
31
+ inspectElements(stashKey, count, roles) {
32
+ return inspectElements(this.inspectedPage, stashKey, count, roles);
33
+ }
34
+ };
35
+ export {
36
+ PuppeteerAdaptor,
37
+ inspectElements
38
+ };
39
+ //# sourceMappingURL=puppeteer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adaptors/puppeteer.ts"],"sourcesContent":["import {\n\tPuppeteerAdaptor as BrowserPuppeteerAdaptor,\n\ttype PuppeteerAdaptorOptions,\n} from \"@a11y-pulse/browser-adaptor/puppeteer\";\nimport type { Page } from \"puppeteer\";\nimport type { ElementInspection, UnreachableControlsAdaptor } from \"../adaptor\";\nimport { inspectStashedElements } from \"./cdp\";\n\nexport type { PuppeteerAdaptorOptions } from \"@a11y-pulse/browser-adaptor/puppeteer\";\n\n/**\n * Inspect the elements a page script stashed on `window[stashKey]` over a DevTools session of its\n * own. Null when the session cannot be opened. Use it to give an existing adaptor an\n * `inspectElements`.\n */\nexport async function inspectElements(\n\tpage: Page,\n\tstashKey: string,\n\tcount: number,\n\troles: readonly number[],\n): Promise<ElementInspection[] | null> {\n\tlet session: Awaited<ReturnType<Page[\"createCDPSession\"]>>;\n\n\ttry {\n\t\tsession = await page.createCDPSession();\n\t} catch {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\treturn await inspectStashedElements(session, stashKey, count, roles);\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tawait session.detach().catch(() => {});\n\t}\n}\n\n/** An UnreachableControlsAdaptor backed by a Puppeteer Page. */\nexport class PuppeteerAdaptor\n\textends BrowserPuppeteerAdaptor\n\timplements UnreachableControlsAdaptor\n{\n\tprivate readonly inspectedPage: Page;\n\n\tconstructor(page: Page, options: PuppeteerAdaptorOptions = {}) {\n\t\tsuper(page, options);\n\t\tthis.inspectedPage = page;\n\t}\n\n\tinspectElements(\n\t\tstashKey: string,\n\t\tcount: number,\n\t\troles: readonly number[],\n\t): Promise<ElementInspection[] | null> {\n\t\treturn inspectElements(this.inspectedPage, stashKey, count, roles);\n\t}\n}\n"],"mappings":";;;;;AAAA;AAAA,EACC,oBAAoB;AAAA,OAEd;AAYP,eAAsB,gBACrB,MACA,UACA,OACA,OACsC;AACtC,MAAI;AAEJ,MAAI;AACH,cAAU,MAAM,KAAK,iBAAiB;AAAA,EACvC,QAAQ;AACP,WAAO;AAAA,EACR;AAEA,MAAI;AACH,WAAO,MAAM,uBAAuB,SAAS,UAAU,OAAO,KAAK;AAAA,EACpE,QAAQ;AACP,WAAO;AAAA,EACR,UAAE;AACD,UAAM,QAAQ,OAAO,EAAE,MAAM,MAAM;AAAA,IAAC,CAAC;AAAA,EACtC;AACD;AAGO,IAAM,mBAAN,cACE,wBAET;AAAA,EACkB;AAAA,EAEjB,YAAY,MAAY,UAAmC,CAAC,GAAG;AAC9D,UAAM,MAAM,OAAO;AACnB,SAAK,gBAAgB;AAAA,EACtB;AAAA,EAEA,gBACC,UACA,OACA,OACsC;AACtC,WAAO,gBAAgB,KAAK,eAAe,UAAU,OAAO,KAAK;AAAA,EAClE;AACD;","names":[]}
@@ -0,0 +1,37 @@
1
+ import { type BaseAuditOptions, type TabConsumer } from "@a11y-pulse/tab-orchestrator";
2
+ import type { UnreachableControlsAdaptor } from "./adaptor";
3
+ import type { UnreachableControlsResult } from "./result";
4
+ export declare const DEFAULT_CANDIDATE_LIMIT = 500;
5
+ export declare const DEFAULT_FINDING_LIMIT = 50;
6
+ /** How many `blanket-listener` elements are listed: enough to show the pattern. */
7
+ export declare const BLANKET_LISTENER_SAMPLE = 5;
8
+ export type UnreachableControlsOptions = Omit<BaseAuditOptions, "failedElementLimit"> & {
9
+ /**
10
+ * Max elements examined as possible controls. Elements with a sign of being one (a handler
11
+ * property, a widget role, a pointer cursor) are taken first.
12
+ */
13
+ candidateLimit?: number;
14
+ /** Max findings reported across `unreachable` and `missingRole`. */
15
+ findingLimit?: number;
16
+ };
17
+ /**
18
+ * Record which elements take focus during a tab session, then scan the page for elements that
19
+ * behave as controls but never took focus (WCAG 2.1.1 Keyboard), and for elements that took focus
20
+ * and behave as controls but expose no role (WCAG 4.1.2 Name, Role, Value). Attach to a
21
+ * `createTabOrchestrator` session, then call `analyse` once the session has run. Or use
22
+ * `runUnreachableControlsAudit` to run as the sole consumer.
23
+ */
24
+ export declare function createUnreachableControlsAudit(options?: UnreachableControlsOptions): TabConsumer & {
25
+ result: UnreachableControlsResult;
26
+ /**
27
+ * Scan the page and judge it against the recorded stops. `startHref` is the page's URL before
28
+ * the session, so a navigation the session did not notice still makes the result inconclusive.
29
+ */
30
+ analyse(adaptor: UnreachableControlsAdaptor, startHref?: string): Promise<UnreachableControlsResult>;
31
+ };
32
+ /**
33
+ * Tab through the page, then report controls the keyboard never reached and focused controls that
34
+ * expose no role. Builds a private tab session, drives the loop, and hands back this consumer's
35
+ * result.
36
+ */
37
+ export declare function runUnreachableControlsAudit(adaptor: UnreachableControlsAdaptor, options?: UnreachableControlsOptions): Promise<UnreachableControlsResult>;