@a11y-pulse/disclosure-operability-audit 0.0.0-stage → 0.1.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 +166 -0
- package/README.md +257 -2
- package/dist/audit.d.ts +81 -0
- package/dist/browser-scripts.d.ts +132 -0
- package/dist/classify.d.ts +80 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +976 -0
- package/dist/index.js.map +1 -0
- package/dist/result.d.ts +65 -0
- package/package.json +61 -5
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,258 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @a11y-pulse/disclosure-operability-audit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@a11y-pulse/disclosure-operability-audit)
|
|
4
|
+
[](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE.md)
|
|
6
|
+
|
|
7
|
+
An accessibility audit for [**WCAG 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) (both Level A). It finds the page's disclosure triggers, the menu buttons, accordion headers and "show more" toggles that carry `aria-expanded`, and operates each one with Enter and Space. A trigger must open, say that it opened by updating `aria-expanded`, and close again.
|
|
8
|
+
|
|
9
|
+
Static analysis can check that `aria-expanded` is present and valid. It cannot tell that a `div role="button"` only listens for clicks, that a mega menu only opens on hover, or that `aria-expanded="false"` was written once in a template and never touched again. This audit presses the keys and watches what the page does.
|
|
10
|
+
|
|
11
|
+
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).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @a11y-pulse/disclosure-operability-audit @a11y-pulse/browser-adaptor puppeteer
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { runDisclosureOperabilityAudit } from "@a11y-pulse/disclosure-operability-audit";
|
|
23
|
+
import { PuppeteerAdaptor } from "@a11y-pulse/browser-adaptor/puppeteer";
|
|
24
|
+
import puppeteer from "puppeteer";
|
|
25
|
+
|
|
26
|
+
const browser = await puppeteer.launch();
|
|
27
|
+
const page = await browser.newPage();
|
|
28
|
+
await page.goto("https://example.com/");
|
|
29
|
+
|
|
30
|
+
const result = await runDisclosureOperabilityAudit(new PuppeteerAdaptor(page));
|
|
31
|
+
|
|
32
|
+
console.log(result.summary);
|
|
33
|
+
// { checked: 2, failed: 1, needsReview: 0, passed: 1, skipped: 1, unchecked: 0 }
|
|
34
|
+
|
|
35
|
+
console.log(result.failed);
|
|
36
|
+
// [
|
|
37
|
+
// {
|
|
38
|
+
// selector: "#brand-filter",
|
|
39
|
+
// html: '<div id="brand-filter" role="button" tabindex="0" aria-expanded="false" aria-controls="brand-options">',
|
|
40
|
+
// role: "button",
|
|
41
|
+
// expanded: "false",
|
|
42
|
+
// controls: "#brand-options",
|
|
43
|
+
// signals: ["keyboard-inoperable"],
|
|
44
|
+
// keysTried: ["Enter", "Space"],
|
|
45
|
+
// attempts: [
|
|
46
|
+
// { key: "Enter", expandedBefore: "false", expandedAfter: "false", contentChanged: false, restoredBy: null },
|
|
47
|
+
// { key: "Space", expandedBefore: "false", expandedAfter: "false", contentChanged: false, restoredBy: null }
|
|
48
|
+
// ],
|
|
49
|
+
// pointer: { click: true, hover: null },
|
|
50
|
+
// openedOnFocus: false,
|
|
51
|
+
// restored: true
|
|
52
|
+
// }
|
|
53
|
+
// ]
|
|
54
|
+
|
|
55
|
+
await browser.close();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A page with no triggers to operate returns `summary.checked: 0`, which is inapplicable.
|
|
59
|
+
|
|
60
|
+
**This audit activates controls on the page.** It presses Enter and Space on each trigger, which runs whatever the page's handler for that control does, then puts the trigger back. It cannot know in advance what a handler does. It guards against the harmful cases it can recognise (see [What it will not touch](#what-it-will-not-touch) and [Safeguards](#safeguards)), but a control that carries `aria-expanded` and does something irreversible when activated, under a name the audit does not recognise as risky, will be activated. Do not run it against a page where that matters, and run it after audits that expect an untouched page, never at the same time as anything else driving the page.
|
|
61
|
+
|
|
62
|
+
## How it decides
|
|
63
|
+
|
|
64
|
+
### Which elements are triggers
|
|
65
|
+
|
|
66
|
+
Every element, including those in open shadow roots, is considered in one call into the page. A trigger is any element with `aria-expanded`.
|
|
67
|
+
|
|
68
|
+
With the `includeControlsOnly` option, a button-like element (`<button>`, `role="button"`, `role="menuitem"`, a link that stays on the page, or anything with `tabindex`) with `aria-controls` and no `aria-expanded` is also a trigger when every element its `aria-controls` names is not rendered. This is the "button that reveals a region and never says so" case. It is off by default because nothing on such a button says it is a disclosure: `aria-controls` on an "Export" or "Load more" button is common, and operating it runs its handler.
|
|
69
|
+
|
|
70
|
+
Native `<details>`, `<summary>` and `<select>` are never triggers: the browser guarantees their behaviour.
|
|
71
|
+
|
|
72
|
+
### What it will not touch
|
|
73
|
+
|
|
74
|
+
Some triggers are found and reported in `skipped` without being activated:
|
|
75
|
+
|
|
76
|
+
| Reason | When |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `navigating-link` | An `<a href>` that leaves the page (anything other than `#…`, empty or `javascript:`), or a control inside one |
|
|
79
|
+
| `submits-form` | A submit or reset button, including a `<button>` in a form with no `type` |
|
|
80
|
+
| `checkable` | A native checkbox or radio button, or `role="checkbox"`, `"radio"`, `"switch"`, `"menuitemcheckbox"` or `"menuitemradio"`. Operating one changes a value, and Enter in a native one submits its form |
|
|
81
|
+
| `risky-name` | Its accessible name matches `riskyNamePattern`: by default delete, remove, erase, log out, sign out, unsubscribe, pay, buy, purchase, send, "order now" and "place/confirm/complete/submit order", as whole words in English |
|
|
82
|
+
| `text-entry` | A text field, `role="combobox"` or editable content, which opens by typing or arrow keys |
|
|
83
|
+
| `composite-item` | A tree item, grid row or cell, option or tab, which expands with arrow keys inside its widget |
|
|
84
|
+
| `disabled` | `disabled`, `aria-disabled="true"`, or inside `inert` content or a disabled fieldset |
|
|
85
|
+
| `hidden` | Not rendered, such as a mobile menu button at a desktop width |
|
|
86
|
+
| `state-on-container` | Not focusable itself but wraps something that is: `aria-expanded` sits on a container |
|
|
87
|
+
|
|
88
|
+
At most `triggerLimit` triggers (20 by default) are operated. A page with more is sampled evenly from top to bottom, and the rest are counted in `summary.unchecked`.
|
|
89
|
+
|
|
90
|
+
### Safeguards
|
|
91
|
+
|
|
92
|
+
These apply to every trigger that is operated:
|
|
93
|
+
|
|
94
|
+
- **A key is only pressed while the trigger holds keyboard focus.** Before each Enter or Space the trigger is focused, and focus is checked again a moment later. If it is anywhere else, as when a dialog the trigger opened keeps focus to itself, the key is not pressed.
|
|
95
|
+
- **A click is only made while focus has not moved elsewhere**, and neither a key nor a click is sent while a modal dialog (`<dialog>` opened modally, or a rendered `aria-modal="true"` element) that the trigger is not part of is on show.
|
|
96
|
+
- **Escape is the only key pressed anywhere else.** When what a trigger opened takes focus and Escape does not close it, the audit stops there. The trigger is reported `not-restored` and the page is left with it open.
|
|
97
|
+
- **Form submissions are stopped** for as long as the audit runs: `submit` events are cancelled before the page's own handlers see them, and `form.submit()` and `form.requestSubmit()` do nothing. A trigger that tried is reported `submit-blocked`.
|
|
98
|
+
- **Navigations to another document are stopped** where the browser has the Navigation API (Chromium). A trigger that tried is reported `navigation-blocked`. Fragment and history-state changes are let through.
|
|
99
|
+
- **A handler that shows nothing is run once.** When Enter clicks the trigger and nothing changes, Space and the scripted click are not sent: they would only run the same handler again.
|
|
100
|
+
|
|
101
|
+
All of this is undone when the audit finishes, on every way out including an error.
|
|
102
|
+
|
|
103
|
+
### How a trigger is operated
|
|
104
|
+
|
|
105
|
+
1. The page is recorded: the trigger's `aria-expanded`, whether its `aria-controls` target is rendered, and which elements outside the trigger are rendered at all. The page is then watched untouched for 50ms. If it changes by itself (a carousel, a ticker), only the trigger's own state and `aria-controls` target are trusted for that trigger.
|
|
106
|
+
2. The trigger is focused. If that alone opens it, no keys are pressed: it passes when `aria-expanded` changed with it and is reviewed otherwise.
|
|
107
|
+
3. Enter is pressed, then Space. Space is not sent to a native link, which it scrolls rather than activates. After each key the audit waits up to `activationTimeout` (250ms) for `aria-expanded` to change or content to appear or disappear. When the key clicked the trigger, so a handler is known to have run, or a transition is playing, it waits up to one second.
|
|
108
|
+
4. After a key that changed something, the audit waits for any transition on the content to finish, then puts the trigger back: with the same key, then Escape, then a click, each subject to the [safeguards](#safeguards). Escape is tried first when the popup took focus, because the key would land inside it.
|
|
109
|
+
5. Only when no key changed anything, a scripted click is tried, then scripted pointer events entering the trigger. This tells a control that is broken for everyone from one that is broken for keyboard users. The click is skipped when a key already clicked the trigger.
|
|
110
|
+
6. Last, the trigger's `aria-expanded` and `aria-controls` target are read once more. A change that arrived after the audit stopped waiting is put back the same way.
|
|
111
|
+
|
|
112
|
+
A trigger that starts expanded is treated the same way in reverse: the keys must collapse it, and it is expanded again afterwards.
|
|
113
|
+
|
|
114
|
+
When the audit finishes, focus and scrolling are returned to where they were.
|
|
115
|
+
|
|
116
|
+
### Signals
|
|
117
|
+
|
|
118
|
+
| Signal | Bucket | Meaning |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| `not-focusable` | `failed` | A click or hover operates it, but it cannot take keyboard focus (2.1.1) |
|
|
121
|
+
| `keyboard-inoperable` | `failed` | A click or hover operates it, but neither Enter nor Space changes anything (2.1.1) |
|
|
122
|
+
| `state-not-exposed` | `failed` | A key shows or hides content while `aria-expanded` is missing or stays the same (4.1.2) |
|
|
123
|
+
| `unresponsive` | `needsReview` | Nothing changed with keys, a click or a hover. Broken for everyone, or it needs something the audit did not do |
|
|
124
|
+
| `state-without-content` | `needsReview` | `aria-expanded` changes but no content was seen to appear or disappear |
|
|
125
|
+
| `space-inoperable` | `needsReview` | A `<button>` or `role="button"` that Enter operates and Space does not |
|
|
126
|
+
| `enter-inoperable` | `needsReview` | Space operates it and Enter does not |
|
|
127
|
+
| `pointer-only-close` | `needsReview` | A key opened it but only a click closed it again |
|
|
128
|
+
| `not-restored` | `needsReview` | Once changed, nothing the audit could safely try put it back. The page was left changed (`restored: false`). When what opened took keyboard focus, only Escape was tried |
|
|
129
|
+
| `submit-blocked` | `needsReview` | Operating it tried to submit a form, which was stopped |
|
|
130
|
+
| `navigation-blocked` | `needsReview` | Operating it tried to load another page, which was stopped |
|
|
131
|
+
| `opens-on-focus` | `needsReview` | Content appears when it takes focus, without `aria-expanded` changing |
|
|
132
|
+
| `trigger-removed` | `needsReview` | The trigger left the document when activated |
|
|
133
|
+
| `not-in-tab-order` | `needsReview` | It works, but has a negative `tabindex` outside a menu, menubar, toolbar, tablist or listbox |
|
|
134
|
+
| `navigated` | `needsReview` | Activating it replaced the document. The audit stopped there (`stopped: "navigated"`) |
|
|
135
|
+
|
|
136
|
+
### When the page navigates
|
|
137
|
+
|
|
138
|
+
Links that leave the page are never activated, but a `<button>` can still navigate from script. Where the browser has the Navigation API the navigation is stopped, the trigger is reported with `navigation-blocked` and the audit carries on. Elsewhere, activating such a trigger replaces the document and the audit stops: that trigger is reported with `navigated`, the result has `stopped: "navigated"`, the triggers after it are counted in `summary.unchecked`, and the page is no longer the one the audit started on. The caller should reload before running anything else.
|
|
139
|
+
|
|
140
|
+
## Browser support
|
|
141
|
+
|
|
142
|
+
| Adaptor | Browser | Supported |
|
|
143
|
+
| --- | --- | --- |
|
|
144
|
+
| Puppeteer | Chrome | Yes |
|
|
145
|
+
| Playwright | Chromium | Yes |
|
|
146
|
+
| Playwright | WebKit | Not yet verified |
|
|
147
|
+
| Playwright | Firefox | Not yet verified |
|
|
148
|
+
|
|
149
|
+
The integration suite runs on every engine in CI; it has so far only been run on the two Chromium engines.
|
|
150
|
+
|
|
151
|
+
## Adaptor requirements
|
|
152
|
+
|
|
153
|
+
The audit uses `evaluate`, `evaluateHandle` and `disposeRef` to inspect the page and build selectors, `pressKey` with `"Enter"`, `"Space"` and `"Escape"`, and calls `ensureFocusReporting` first so that a trigger which opens on focus does so when the page is not in the foreground. It takes no screenshots. `"Space"` was added to `KeyName` in `@a11y-pulse/browser-adaptor` for this audit; a custom adaptor must accept it.
|
|
154
|
+
|
|
155
|
+
## Options
|
|
156
|
+
|
|
157
|
+
| Option | Type | Default | Description |
|
|
158
|
+
| --- | --- | --- | --- |
|
|
159
|
+
| `triggerLimit` | `number` | `20` | Max triggers to operate. A page with more is sampled evenly; the rest are counted in `summary.unchecked`. |
|
|
160
|
+
| `activationTimeout` | `number` | `250` | Milliseconds to wait for a key press to change something before deciding it did nothing. Raise it for slow, script-heavy pages. |
|
|
161
|
+
| `riskyNamePattern` | `string \| null` | `DEFAULT_RISKY_NAME_PATTERN` | Source of a case-insensitive regular expression. A trigger whose accessible name matches is skipped as `risky-name`. Pass your own for a page in another language, or `null` to operate every trigger whatever it is called. |
|
|
162
|
+
| `includeControlsOnly` | `boolean` | `false` | Also operate buttons with `aria-controls` naming hidden content and no `aria-expanded`. |
|
|
163
|
+
|
|
164
|
+
A trigger that works costs about 350ms, and up to a second when its panel animates. A `<button>` that responds to nothing is given a second to act after Enter, then a hover (about 1.4 seconds); a `div` that ignores keys waits out both keys, a click and a hover (about 900ms). A page of 20 dead buttons takes about 30 seconds.
|
|
165
|
+
|
|
166
|
+
## Result shape
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
type DisclosureAttempt = {
|
|
170
|
+
key: "Enter" | "Space";
|
|
171
|
+
/** `aria-expanded` before and after the key press. */
|
|
172
|
+
expandedBefore: string | null;
|
|
173
|
+
expandedAfter: string | null;
|
|
174
|
+
/** Whether content was shown or hidden. */
|
|
175
|
+
contentChanged: boolean;
|
|
176
|
+
/** What undid the change, or null when nothing changed or nothing undid it. */
|
|
177
|
+
restoredBy: "Enter" | "Space" | "Escape" | "click" | "blur" | null;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
type DisclosureTrigger = {
|
|
181
|
+
selector: string;
|
|
182
|
+
/** Truncated opening tag. */
|
|
183
|
+
html: string;
|
|
184
|
+
/** The explicit `role`, or null. */
|
|
185
|
+
role: string | null;
|
|
186
|
+
/** `aria-expanded` as found. Null only for an `aria-controls`-only trigger (`includeControlsOnly`). */
|
|
187
|
+
expanded: string | null;
|
|
188
|
+
/** Selector for the first element `aria-controls` names, or null. */
|
|
189
|
+
controls: string | null;
|
|
190
|
+
/** Every signal that applies, most serious first. Empty when the trigger passes. */
|
|
191
|
+
signals: DisclosureSignal[];
|
|
192
|
+
keysTried: ("Enter" | "Space")[];
|
|
193
|
+
attempts: DisclosureAttempt[];
|
|
194
|
+
/** Whether a click or hover changed anything. Null when not tried. */
|
|
195
|
+
pointer: { click: boolean | null; hover: boolean | null };
|
|
196
|
+
openedOnFocus: boolean;
|
|
197
|
+
/** Whether it was left as it was found. */
|
|
198
|
+
restored: boolean;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
type DisclosureOperabilityResult = {
|
|
202
|
+
failed: DisclosureTrigger[];
|
|
203
|
+
needsReview: DisclosureTrigger[];
|
|
204
|
+
passed: DisclosureTrigger[];
|
|
205
|
+
/** Triggers found but not operated, up to ten. */
|
|
206
|
+
skipped: { selector: string; html: string; reason: DisclosureSkipReason }[];
|
|
207
|
+
/** Set when activating a trigger replaced the document. */
|
|
208
|
+
stopped: "navigated" | null;
|
|
209
|
+
summary: {
|
|
210
|
+
checked: number;
|
|
211
|
+
failed: number;
|
|
212
|
+
needsReview: number;
|
|
213
|
+
passed: number;
|
|
214
|
+
/** Every skipped trigger, including those past the ten listed. */
|
|
215
|
+
skipped: number;
|
|
216
|
+
/** Operable triggers left out by `triggerLimit` or not reached before the audit stopped. */
|
|
217
|
+
unchecked: number;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
`classifyTrigger(observation)`, the pure classifier behind the audit, returns the `signals` and a `verdict` of `"failed"`, `"review"` or null for what was observed on one trigger.
|
|
223
|
+
|
|
224
|
+
## Limitations
|
|
225
|
+
|
|
226
|
+
- **Only declared disclosures.** A control without `aria-expanded` is not found, however much it behaves like a menu. A click-only `div` with no ARIA at all is a job for a keyboard-reachability check.
|
|
227
|
+
- **Risky names are English words.** The default pattern does not recognise "Supprimer" or "Abmelden". Pass `riskyNamePattern` for other languages. A destructive control with a neutral name ("Continue", an icon with no name) is not recognised at all.
|
|
228
|
+
- **Handlers run.** Activating a trigger runs its handler, at least once. Form submissions and, in Chromium, page loads are stopped, but a `fetch`, an analytics event or a change to stored state made by the handler is not.
|
|
229
|
+
- **Scripted pointer, not a real one.** The click is `element.click()` and the hover is dispatched `pointerover`, `pointerenter`, `mouseover` and `mouseenter` events. A menu opened purely by CSS `:hover` does not respond to those, so a CSS-only hover menu is reported as `unresponsive` for review, not as a keyboard failure.
|
|
230
|
+
- **Content is "rendered or not".** An `aria-controls` target counts as shown when it has a box, is not parked off the side of the page and passes `checkVisibility()` including opacity. Everywhere else on the page only being rendered counts, not where: a carousel or ticker moves its slides in and out of the document all the time, and that must not be taken for content a key press revealed. So a panel with no `aria-controls` that is parked off-screen and moved into view, one that slides in with a transform, and one revealed by `clip-path` are not seen to change, which is why `state-without-content` is only reviewed.
|
|
231
|
+
- **Pages over 5,000 elements** are not scanned for content appearing outside the `aria-controls` target, so there a trigger without a resolvable `aria-controls` can only be judged by its `aria-expanded`.
|
|
232
|
+
- **Arrow keys are not pressed.** Comboboxes, tree items and grid rows are skipped, and a menu button that only opens with ArrowDown is reported as `keyboard-inoperable` if a click opens it. The ARIA menu button pattern asks for Enter and Space as well.
|
|
233
|
+
- **What opened is not explored.** The audit does not tab through the opened content, check where focus went or test that focus returns to the trigger on close.
|
|
234
|
+
- **Triggers are sampled once.** Triggers that only exist after another one is opened (a submenu, a nested accordion) are not found.
|
|
235
|
+
- **Main document only.** Triggers inside iframes and closed shadow roots are not reached.
|
|
236
|
+
- **Other state is not restored.** The audit undoes what it can see: `aria-expanded`, rendered content, focus and scrolling. Anything else an activation did, such as an analytics event, a fetched panel left in the DOM or a URL fragment, stays.
|
|
237
|
+
|
|
238
|
+
## Known false positives
|
|
239
|
+
|
|
240
|
+
Cases where the audit reports a problem that is not one. Each says which bucket it lands in.
|
|
241
|
+
|
|
242
|
+
- **A trigger that needs more than a second** (`needsReview`). A panel fetched over the network before it opens looks like a key that did nothing, and is `unresponsive`. A custom control (not a `<button>`) that handles `keydown` itself is only given `activationTimeout`, so raise that for a page of slow custom controls.
|
|
243
|
+
- **`aria-controls` on a button that reveals unrelated hidden content** (`failed`, with `includeControlsOnly` only). A "Load more" button whose `aria-controls` names an empty, hidden list is taken for a disclosure with no expanded state.
|
|
244
|
+
- **A trigger that opens a dialog which ignores Escape** (`needsReview`). The dialog takes focus, the audit will not press anything but Escape inside it, and the trigger is `not-restored`. That a dialog cannot be dismissed with Escape is worth a look in its own right.
|
|
245
|
+
- **A page that adds and removes content by itself, but not during the 50ms watch** (`failed`). A rotating banner that swaps slides with `display` or `hidden`, or a feed that inserts items, can do so just as a key is pressed, which looks like content the key revealed. On a trigger that did nothing, that reads as `state-not-exposed`. A carousel that only moves its slides is not affected.
|
|
246
|
+
- **Consent or sign-up popups that open on first interaction** (`needsReview`). A page that reacts to the first key press or click anywhere by showing a dialog can leave a trigger `not-restored`.
|
|
247
|
+
- **A roving-tabindex widget without a container role** (`needsReview`). Triggers with `tabindex="-1"` in a custom toolbar that has no `role` are `not-in-tab-order`.
|
|
248
|
+
- **Deliberate open-on-focus menus** (`needsReview`). A navigation menu that opens when its link takes focus and has no `aria-expanded` change is `opens-on-focus`; it may be announced another way.
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
Released under the [PolyForm Shield License 1.0.0](./LICENSE.md), in plain language:
|
|
253
|
+
|
|
254
|
+
- **Source-available.** The source is public and you can read, fork, and modify it.
|
|
255
|
+
- **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.
|
|
256
|
+
- **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.
|
|
257
|
+
|
|
258
|
+
See [LICENSE.md](./LICENSE.md) for the full, binding terms.
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type BrowserAdaptor } from "@a11y-pulse/browser-adaptor";
|
|
2
|
+
import { type CollectedTrigger, type DisclosureAction, type DisclosureReading } from "./browser-scripts";
|
|
3
|
+
import { type DisclosureKey, type DisclosureObservation } from "./classify";
|
|
4
|
+
import type { DisclosureOperabilityResult } from "./result";
|
|
5
|
+
export declare const DEFAULT_TRIGGER_LIMIT = 20;
|
|
6
|
+
export declare const DEFAULT_ACTIVATION_TIMEOUT_MS = 250;
|
|
7
|
+
/**
|
|
8
|
+
* Names the audit will not activate, as the source of a case-insensitive pattern. A control that
|
|
9
|
+
* carries `aria-expanded` but is named for an action that cannot be undone is left alone: the
|
|
10
|
+
* audit cannot tell what its handler does until it has run.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_RISKY_NAME_PATTERN = "\\b(delete|remove|erase|log\\s?out|sign\\s?out|unsubscribe|pay|buy|purchase|send|order\\s+now|(place|confirm|complete|submit)\\s+(your\\s+|my\\s+)?order)\\b";
|
|
13
|
+
export type DisclosureOperabilityOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Max triggers to operate. A page with more is sampled evenly from top to bottom. Defaults to
|
|
16
|
+
* 20.
|
|
17
|
+
*/
|
|
18
|
+
triggerLimit?: number;
|
|
19
|
+
/**
|
|
20
|
+
* How long to wait, in milliseconds, for a key press to change something before deciding that it
|
|
21
|
+
* did nothing. Defaults to 250.
|
|
22
|
+
*/
|
|
23
|
+
activationTimeout?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Source of a case-insensitive pattern. A trigger whose accessible name matches is listed in
|
|
26
|
+
* `skipped` as `risky-name` and never activated. Defaults to `DEFAULT_RISKY_NAME_PATTERN`; pass
|
|
27
|
+
* null to operate every trigger whatever it is called.
|
|
28
|
+
*/
|
|
29
|
+
riskyNamePattern?: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Also operate buttons that have `aria-controls` naming hidden content and no `aria-expanded`.
|
|
32
|
+
* Off by default: without `aria-expanded` nothing says the button is a disclosure, and
|
|
33
|
+
* operating it runs whatever its handler does.
|
|
34
|
+
*/
|
|
35
|
+
includeControlsOnly?: boolean;
|
|
36
|
+
};
|
|
37
|
+
/** Thrown by a probe when the document the audit started on has been replaced. */
|
|
38
|
+
export declare class DocumentReplacedError extends Error {
|
|
39
|
+
constructor();
|
|
40
|
+
}
|
|
41
|
+
/** The browser-coupled seams the audit drives. Faked in unit tests. */
|
|
42
|
+
export type DisclosureProbe = {
|
|
43
|
+
/** Record the page as it stands before trigger `index` is touched. */
|
|
44
|
+
begin(index: number): Promise<DisclosureReading>;
|
|
45
|
+
/** Focus the trigger. Resolves to whether it took focus. */
|
|
46
|
+
focus(index: number): Promise<boolean>;
|
|
47
|
+
read(index: number): Promise<DisclosureReading>;
|
|
48
|
+
/** Whether a key press or a click on the trigger would land where it is meant to. */
|
|
49
|
+
ready(index: number, action: DisclosureAction): Promise<boolean>;
|
|
50
|
+
blur(index: number): Promise<void>;
|
|
51
|
+
pressKey(key: DisclosureKey | "Escape"): Promise<void>;
|
|
52
|
+
/** A scripted click on the trigger. */
|
|
53
|
+
click(index: number): Promise<void>;
|
|
54
|
+
/** Scripted pointer events entering (`on`) or leaving the trigger. */
|
|
55
|
+
hover(index: number, on: boolean): Promise<void>;
|
|
56
|
+
/** Put scrolling back as it was when the trigger was begun. */
|
|
57
|
+
end(index: number): Promise<void>;
|
|
58
|
+
sleep(ms: number): Promise<void>;
|
|
59
|
+
};
|
|
60
|
+
type Exercised = {
|
|
61
|
+
observation: DisclosureObservation;
|
|
62
|
+
keysTried: DisclosureKey[];
|
|
63
|
+
};
|
|
64
|
+
export type DisclosureLoopResult = {
|
|
65
|
+
exercised: Exercised[];
|
|
66
|
+
stopped: "navigated" | null;
|
|
67
|
+
};
|
|
68
|
+
/** The engine-neutral loop over the collected triggers. Exported for unit testing with a fake probe. */
|
|
69
|
+
export declare function runDisclosureLoop(probe: DisclosureProbe, triggers: readonly CollectedTrigger[], timeout: number): Promise<DisclosureLoopResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Find the page's disclosure triggers and operate each with Enter and Space, checking that it
|
|
72
|
+
* opens, reports the change through `aria-expanded` and closes again.
|
|
73
|
+
*
|
|
74
|
+
* This activates controls on the page. Links that leave the page, buttons that submit a form,
|
|
75
|
+
* checkboxes, radio buttons and controls named for an action that cannot be undone are never
|
|
76
|
+
* activated; a key is only pressed while the trigger holds focus; and form submissions and
|
|
77
|
+
* navigations to another document are stopped for as long as the audit runs. Every trigger is put
|
|
78
|
+
* back as it was found where the page allows it, along with focus and scrolling.
|
|
79
|
+
*/
|
|
80
|
+
export declare function runDisclosureOperabilityAudit(adaptor: BrowserAdaptor, options?: DisclosureOperabilityOptions): Promise<DisclosureOperabilityResult>;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/** Why a trigger was found but left alone. */
|
|
2
|
+
export type DisclosureSkipReason =
|
|
3
|
+
/** Not rendered, so no one can operate it as the page stands. */
|
|
4
|
+
"hidden"
|
|
5
|
+
/** Disabled, `aria-disabled` or inside inert content. */
|
|
6
|
+
| "disabled"
|
|
7
|
+
/** A link that would leave the page, or a control inside one. */
|
|
8
|
+
| "navigating-link"
|
|
9
|
+
/** A submit or reset button, which would send or clear its form. */
|
|
10
|
+
| "submits-form"
|
|
11
|
+
/** A checkbox, radio button or switch: operating it changes a value, and Enter in a native one submits its form. */
|
|
12
|
+
| "checkable"
|
|
13
|
+
/** Its name suggests an action that cannot be undone, such as "Delete account" or "Sign out". */
|
|
14
|
+
| "risky-name"
|
|
15
|
+
/** A text field or combobox, which opens by typing or arrow keys, not Enter. */
|
|
16
|
+
| "text-entry"
|
|
17
|
+
/** A tree item, grid row or similar, which expands with arrow keys inside its widget. */
|
|
18
|
+
| "composite-item"
|
|
19
|
+
/** Not focusable itself but wraps something that is: the state sits on a container. */
|
|
20
|
+
| "state-on-container";
|
|
21
|
+
/** A trigger as it was found, before anything was pressed. */
|
|
22
|
+
export type CollectedTrigger = {
|
|
23
|
+
/** `outerHTML`, cut to a sane length. Truncate to the opening tag on the host. */
|
|
24
|
+
html: string;
|
|
25
|
+
/** The explicit `role`, or null. */
|
|
26
|
+
role: string | null;
|
|
27
|
+
/**
|
|
28
|
+
* `aria-expanded` as written. Null only for a trigger that has `aria-controls` alone, which is
|
|
29
|
+
* found when `includeControlsOnly` is set.
|
|
30
|
+
*/
|
|
31
|
+
expanded: string | null;
|
|
32
|
+
/** Whether an `aria-controls` id resolved to an element. */
|
|
33
|
+
hasControlled: boolean;
|
|
34
|
+
/** Whether it can be reached with Tab (`tabIndex >= 0`). */
|
|
35
|
+
inTabOrder: boolean;
|
|
36
|
+
/** Whether it sits in a widget that moves focus with arrow keys (menu, toolbar, …). */
|
|
37
|
+
inComposite: boolean;
|
|
38
|
+
/** Whether Space must operate it: a `<button>` or `role="button"`. */
|
|
39
|
+
spaceExpected: boolean;
|
|
40
|
+
/** Whether it is a native link, which Space does not activate. */
|
|
41
|
+
link: boolean;
|
|
42
|
+
};
|
|
43
|
+
export type CollectedSkip = {
|
|
44
|
+
html: string;
|
|
45
|
+
reason: DisclosureSkipReason;
|
|
46
|
+
};
|
|
47
|
+
export type DisclosureCollection = {
|
|
48
|
+
/** Triggers to exercise, in document order. `window[stashKey][i]` is the element. */
|
|
49
|
+
triggers: CollectedTrigger[];
|
|
50
|
+
/** Triggers left alone, up to `skipLimit`. Their elements follow the triggers in the stash. */
|
|
51
|
+
skipped: CollectedSkip[];
|
|
52
|
+
/** Every trigger left alone, including those past `skipLimit`. */
|
|
53
|
+
skippedTotal: number;
|
|
54
|
+
/** Triggers that could have been exercised, including those past `triggerLimit`. */
|
|
55
|
+
eligible: number;
|
|
56
|
+
};
|
|
57
|
+
/** What a trigger and the page around it look like at one moment. */
|
|
58
|
+
export type DisclosureReading = {
|
|
59
|
+
/** False once the trigger has left the document. */
|
|
60
|
+
connected: boolean;
|
|
61
|
+
/** `aria-expanded` now. */
|
|
62
|
+
expanded: string | null;
|
|
63
|
+
/** Whether any `aria-controls` target is rendered, or null when none resolves. */
|
|
64
|
+
controlled: boolean | null;
|
|
65
|
+
/**
|
|
66
|
+
* Elements outside the trigger that are rendered now and were not when the trigger was begun,
|
|
67
|
+
* and the reverse. Null on a page too large to scan.
|
|
68
|
+
*/
|
|
69
|
+
appeared: number | null;
|
|
70
|
+
disappeared: number | null;
|
|
71
|
+
/** Whether the trigger has keyboard focus. */
|
|
72
|
+
focused: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the trigger's content is still on the move: a transition or finite animation is
|
|
75
|
+
* running on it, or its `aria-controls` target changed size since the last reading.
|
|
76
|
+
*/
|
|
77
|
+
settling: boolean;
|
|
78
|
+
/** Clicks the browser itself delivered to the trigger since it was begun, as a key press does. */
|
|
79
|
+
clicks: number;
|
|
80
|
+
/** Form submissions and navigations to another document stopped since the trigger was begun. */
|
|
81
|
+
blocked: {
|
|
82
|
+
submits: number;
|
|
83
|
+
navigations: number;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/** What the audit is about to do to a trigger. */
|
|
87
|
+
export type DisclosureAction = "key" | "click";
|
|
88
|
+
export type DisclosureInstallOptions = {
|
|
89
|
+
/** Also treat a button with `aria-controls`, no `aria-expanded` and a hidden target as a trigger. */
|
|
90
|
+
includeControlsOnly?: boolean;
|
|
91
|
+
/** Source of a case-insensitive pattern: a trigger whose name matches is not operated. */
|
|
92
|
+
riskyNamePattern?: string | null;
|
|
93
|
+
};
|
|
94
|
+
export type DisclosureApi = {
|
|
95
|
+
begin(index: number): DisclosureReading;
|
|
96
|
+
focus(index: number): boolean;
|
|
97
|
+
read(index: number): DisclosureReading;
|
|
98
|
+
/**
|
|
99
|
+
* Whether it is safe to act on the trigger now. A key needs the trigger to hold keyboard focus;
|
|
100
|
+
* a click needs focus not to have moved elsewhere. Neither is safe behind a modal dialog.
|
|
101
|
+
*/
|
|
102
|
+
ready(index: number, action: DisclosureAction): boolean;
|
|
103
|
+
blur(index: number): void;
|
|
104
|
+
click(index: number): void;
|
|
105
|
+
hover(index: number, on: boolean): void;
|
|
106
|
+
end(index: number): void;
|
|
107
|
+
finish(): void;
|
|
108
|
+
};
|
|
109
|
+
/** The document the audit started on has gone: the page navigated. */
|
|
110
|
+
export type DisclosureGone = {
|
|
111
|
+
gone: true;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Find the page's disclosure triggers, stash them on `window[stashKey]` (their first controlled
|
|
115
|
+
* elements on `window[stashKey + "Controls"]`) and leave the functions the audit drives them with
|
|
116
|
+
* on `window[stashKey + "Api"]`.
|
|
117
|
+
*
|
|
118
|
+
* A trigger is an element with `aria-expanded`. With `includeControlsOnly`, so is a button-like
|
|
119
|
+
* element whose `aria-controls` names content that is not rendered. Native `<details>` and
|
|
120
|
+
* `<select>` are not triggers.
|
|
121
|
+
*
|
|
122
|
+
* Until `finish` is called, form submissions and navigations to another document are stopped, so
|
|
123
|
+
* that nothing a trigger does can send data or leave the page.
|
|
124
|
+
*/
|
|
125
|
+
export declare function installDisclosureScript(stashKey: string, triggerLimit: number, skipLimit: number, scanLimit: number, options?: DisclosureInstallOptions): DisclosureCollection;
|
|
126
|
+
/**
|
|
127
|
+
* Call one of the functions installDisclosureScript left on the page. Answers `{ gone: true }` when
|
|
128
|
+
* they are no longer there, which means the document was replaced.
|
|
129
|
+
*/
|
|
130
|
+
export declare function callDisclosureScript(stashKey: string, method: keyof DisclosureApi, ...args: unknown[]): unknown;
|
|
131
|
+
/** Whether the functions installDisclosureScript left on the page are still there. */
|
|
132
|
+
export declare function isDisclosureInstalledScript(stashKey: string): boolean;
|