@surea11y/puppeteer 1.2.0 → 1.3.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/README.md +66 -13
- package/package.json +8 -7
- package/src/A11yCoreBuilder.d.ts +29 -4
- package/src/A11yCoreBuilder.js +4 -0
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ await page.goto('https://example.com/');
|
|
|
25
25
|
const results = await new A11yCoreBuilder({ page })
|
|
26
26
|
.include('#main') // optional -- call multiple times for multi-region scans
|
|
27
27
|
.exclude('.cookie-banner') // optional
|
|
28
|
-
.
|
|
28
|
+
.withWcag('2.2', 'AA') // the rules for WCAG 2.2's A and AA criteria
|
|
29
29
|
.disableRules(['meta-refresh-no-exceptions'])
|
|
30
30
|
.options({ contrast: { mode: 'auditorAssist' } })
|
|
31
31
|
.analyze();
|
|
@@ -34,19 +34,21 @@ console.log(results.checksResults.filter(r => r.outcome === 'fail'));
|
|
|
34
34
|
await browser.close();
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
`results` is `@surea11y/core`'s own native result shape — see its [`OUTPUT_SCHEMA.md`](https://github.com/SureA11y/core/blob/main/docs/OUTPUT_SCHEMA.md) — not the `violations`/`passes`/`incomplete`/`inapplicable` shape used by other popular accessibility testing tools. The builder's *method names* are modeled on common conventions in this space for migration familiarity; the richer result schema is kept as-is. `results.engine.version` names the `@surea11y/core` release that produced it (such as `"1.
|
|
37
|
+
`results` is `@surea11y/core`'s own native result shape — see its [`OUTPUT_SCHEMA.md`](https://github.com/SureA11y/core/blob/main/docs/OUTPUT_SCHEMA.md) — not the `violations`/`passes`/`incomplete`/`inapplicable` shape used by other popular accessibility testing tools. The builder's *method names* are modeled on common conventions in this space for migration familiarity; the richer result schema is kept as-is. `results.engine.version` names the `@surea11y/core` release that produced it (such as `"1.11.1"`); quote it in a bug report.
|
|
38
38
|
|
|
39
|
-
From 1.
|
|
39
|
+
From 1.3.0 this package needs `@surea11y/core` 1.11.1 or later, which npm installs with it. Core's rules and messages change between its releases; see [What changes with `@surea11y/core` 1.11](#what-changes-with-surea11ycore-111) below and core's [changelog](https://github.com/SureA11y/core/blob/main/CHANGELOG.md).
|
|
40
40
|
|
|
41
41
|
Also see `examples/basic-scan.js` for a runnable script (`npm run example -- <url>`).
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
`.withWcag(version, level)` selects by conformance target: `.withWcag('2.2', 'AA')` runs the rules for WCAG 2.2's Level A and AA criteria, by the level each criterion has in that version (4.1.1 Parsing, which 2.2 removed, is part of a `'2.1'` target and not of a `'2.2'` one). `.withBestPractices()` adds the rules that name no WCAG criterion, such as `region` and `heading-order`; on its own it runs only those. `.withRules()` and `.withTags()` add to a target's rules, and the disable methods apply after. A version other than `'2.0'`, `'2.1'` or `'2.2'`, or a level other than `'A'`, `'AA'` or `'AAA'`, throws a `TypeError` with `code: 'INVALID_RUN_ONLY'` at the call. Both need `@surea11y/core` 1.11 or later.
|
|
44
|
+
|
|
45
|
+
`withTags()`/`disableRules()` have counterparts: `.withRules([...])` (only run these specific rule IDs) and `.disableTags([...])` (never run rules carrying any of these tags). All four compose the same way similar allow/deny-list options do in other accessibility testing tools, with one non-obvious rule worth knowing: a "disable" always wins over a "with" on the same ID/tag (e.g. `.withRules(['a']).disableRules(['a'])` drops `'a'` entirely), and combining `.withRules()` **and** `.withTags()` together requires a rule to satisfy *both* (`@surea11y/core`'s default `includeMode: 'and'` — see [`ENGINE_OPTIONS.md`](https://github.com/SureA11y/core/blob/main/docs/ENGINE_OPTIONS.md)), not either one.
|
|
44
46
|
|
|
45
47
|
Each of the four takes a string or an array of strings. Anything else, such as `undefined` from a missing config value or an empty string, throws a `TypeError` with `code: 'INVALID_RUN_ONLY'` at the call. A list that names nothing the engine knows (`.withRules(['img-alt-presnt'])`) makes `analyze()` reject instead; see [Errors](#errors).
|
|
46
48
|
|
|
47
49
|
`.exclude(selector)` above excludes globally. Pass a second argument to scope it to specific rule IDs instead: `.exclude('.mat-select', { rules: ['aria-required-children'] })` skips `.mat-select` for that rule only — every other rule still sees it. Global and rule-scoped `.exclude()` calls compose freely.
|
|
48
50
|
|
|
49
|
-
**Create one builder per scan.** `A11yCoreBuilder` is a mutable object with no reset between `.analyze()` calls — `include()`/`exclude()`/`withRules()`/`disableRules()`/`withTags()`/`disableTags()`/`options()`/`withCustomRules()` all push onto or merge into internal state that persists for the instance's lifetime. Calling one of them again before a second `.analyze()` call *accumulates* on top of the first scan's scope rather than replacing it (this is exactly what makes "call `.include()` several times for one scan," above, work — the same accumulation just also applies across separate scans if you reuse an instance). `.reportOnly()`/`.frames()`/`.elementRef()` are the exception: each call replaces the previous value instead of merging with it.
|
|
51
|
+
**Create one builder per scan.** `A11yCoreBuilder` is a mutable object with no reset between `.analyze()` calls — `include()`/`exclude()`/`withRules()`/`disableRules()`/`withTags()`/`disableTags()`/`options()`/`withCustomRules()`/`withPacks()` all push onto or merge into internal state that persists for the instance's lifetime. Calling one of them again before a second `.analyze()` call *accumulates* on top of the first scan's scope rather than replacing it (this is exactly what makes "call `.include()` several times for one scan," above, work — the same accumulation just also applies across separate scans if you reuse an instance). `.reportOnly()`/`.frames()`/`.elementRef()`/`.withWcag()`/`.withBestPractices()` are the exception: each call replaces the previous value instead of merging with it.
|
|
50
52
|
|
|
51
53
|
This binding works against both browsers Puppeteer supports — Chrome (the default) and Firefox via `puppeteer.launch({ browser: 'firefox' })` — verified with a real Firefox run, see `tests/cross-browser.test.js`. There's no WebKit option; that's a Playwright-only engine.
|
|
52
54
|
|
|
@@ -70,9 +72,9 @@ assert.ok(
|
|
|
70
72
|
);
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
`getScanGaps(results)` lists what the scan left out, which `checksResults` alone would pass over as clean: an `.include()` scope that matched nothing (`kind: 'context-not-found'`; nothing was scanned, so every rule reports `notApplicable`), some of several `.include()` selectors that matched nothing (`'context-partly-not-found'`),
|
|
75
|
+
`getScanGaps(results)` lists what the scan left out, which `checksResults` alone would pass over as clean: an `.include()` scope that matched nothing (`kind: 'context-not-found'`; nothing was scanned, so every rule reports `notApplicable`), some of several `.include()` selectors that matched nothing (`'context-partly-not-found'`), each custom rule the engine did not run (`'custom-rule-skipped'`, with the engine's reason), and each pack the page did not run (`'pack-skipped'`, from `results.skippedPacks`; see [Scanning with packs](#scanning-with-packs-standards-checklists-and-your-own-rules)). Each gap has a `message`. Checking it is what keeps a mistyped scope from passing the gate. `analyze()` also prints each gap's message with `console.warn` (as `@surea11y/puppeteer (<frame url>): <message>`, once per scanned frame under `.frames(true)`), so a scan that left something out shows in the log even where nothing asserts on it.
|
|
74
76
|
|
|
75
|
-
See `examples/e2e-test-example.test.js` for a fuller, runnable version (`npm run example:e2e`) — one test proving real violations get caught (unlabeled button, missing `alt`), one proving a mistyped `.include()` scope is caught rather than passed, one proving a well-formed page passes cleanly. It uses `node:test` directly rather than a dedicated test-runner package: Puppeteer has no first-party test runner the way `@playwright/test` is the default for Playwright, and `node:test` is a zero-new-dependency choice that already matches this project's own test suite.
|
|
77
|
+
See `examples/e2e-test-example.test.js` for a fuller, runnable version (`npm run example:e2e`) — one test proving real violations get caught (unlabeled button, missing `alt`), one proving a mistyped `.include()` scope is caught rather than passed, one proving a well-formed page passes cleanly, and one gating a page on a pack's checklist. It uses `node:test` directly rather than a dedicated test-runner package: Puppeteer has no first-party test runner the way `@playwright/test` is the default for Playwright, and `node:test` is a zero-new-dependency choice that already matches this project's own test suite.
|
|
76
78
|
|
|
77
79
|
### Readable console/CI output on failure
|
|
78
80
|
|
|
@@ -81,12 +83,12 @@ A bare length/equality assertion alone gets you a *working* gate, but the failur
|
|
|
81
83
|
```
|
|
82
84
|
AssertionError [ERR_ASSERTION]: 1) button-name-present (serious): This button has no accessible name.
|
|
83
85
|
at html > body > button
|
|
84
|
-
|
|
85
|
-
2) img-alt-present (serious):
|
|
86
|
+
Give the button visible text, or name it with aria-label, so screen reader users know what it does.
|
|
87
|
+
2) img-alt-present (serious): This <img> has no alt attribute.
|
|
86
88
|
at html > body > img
|
|
87
|
-
Add an alt attribute
|
|
89
|
+
Add an alt attribute that says what the image shows, or alt="" if the image is purely decorative.
|
|
88
90
|
|
|
89
|
-
Scanned with @surea11y/core 1.
|
|
91
|
+
Scanned with @surea11y/core 1.11.1.
|
|
90
92
|
```
|
|
91
93
|
|
|
92
94
|
and a scope that matched nothing prints:
|
|
@@ -94,7 +96,7 @@ and a scope that matched nothing prints:
|
|
|
94
96
|
```
|
|
95
97
|
AssertionError [ERR_ASSERTION]: Nothing was scanned: the scan scope matched no element ("#main").
|
|
96
98
|
|
|
97
|
-
Scanned with @surea11y/core 1.
|
|
99
|
+
Scanned with @surea11y/core 1.11.1.
|
|
98
100
|
```
|
|
99
101
|
|
|
100
102
|
An element inside a shadow tree is located through its shadow hosts, as `my-app >>> my-card >>> img`; `formatOccurrenceLocation(occurrence)` gives that line on its own. Passing `results.checksResults` instead of `results` still works and lists the findings alone.
|
|
@@ -124,6 +126,16 @@ const messages = [results.topFrame, ...results.frames].map((frame) =>
|
|
|
124
126
|
|
|
125
127
|
Unlike script-injection-based accessibility tools (which need a `postMessage`-based protocol to reach cross-origin iframes, since they're injected as a plain `<script>` fully subject to the browser's same-origin policy), this needs no extra `@surea11y/core` engine support at all — Puppeteer drives every frame via CDP at the automation-process level, so cross-origin `frame.evaluate()` already just works. Verified against a real cross-origin page (`example.org` embedded in an unrelated origin) — see `tests/builder.test.js`. Default off, so plain `.analyze()` is unaffected unless you opt in.
|
|
126
128
|
|
|
129
|
+
`@surea11y/core`'s reporters take this result as it is (core 1.11.1 and later): `renderSarifReport(results)`, `renderJunitReport(results)`, `renderHtmlReport(results)` and the baseline functions report every frame's findings, and a frame that couldn't be scanned as not scanned, so it never reads as a pass.
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
const fs = require('node:fs');
|
|
133
|
+
const { renderSarifReport } = require('@surea11y/core/sarif');
|
|
134
|
+
|
|
135
|
+
const results = await new A11yCoreBuilder({ page }).frames(true).analyze();
|
|
136
|
+
fs.writeFileSync('a11y.sarif', renderSarifReport(results));
|
|
137
|
+
```
|
|
138
|
+
|
|
127
139
|
### Trimming the result to just violations
|
|
128
140
|
|
|
129
141
|
By default `analyze()` returns every rule's outcome, including `pass`/`notApplicable` — `@surea11y/core`'s own deliberate "not a violations-only list" design (see [`OUTPUT_SCHEMA.md`](https://github.com/SureA11y/core/blob/main/docs/OUTPUT_SCHEMA.md)). Use `.reportOnly()` to post-filter down to only the outcomes you care about:
|
|
@@ -138,6 +150,8 @@ console.log(results.checksResults); // only fail/cantTell entries, pass/notAppli
|
|
|
138
150
|
|
|
139
151
|
Valid outcome values are `'pass'`, `'fail'`, `'cantTell'`, `'notApplicable'`. This is pure binding-layer filtering — the engine itself still computes every rule; nothing about the scan itself changes. Combines with `.frames(true)`: the filter is applied to `results.topFrame` and each entry of `results.frames` independently.
|
|
140
152
|
|
|
153
|
+
A result trimmed this way is no longer the whole scan to `@surea11y/core`'s reporters: JUnit counts one test per rule it finds, and EARL makes one assertion per rule. To keep a result small and still hand it to them, ask the engine for a compact one instead, with `.options({ output: { detail: 'findings' } })`: a rule that passed or did not apply keeps only its outcome, and every reporter reads it as the full result. An empty page's result goes from about 238 KB to 82 KB.
|
|
154
|
+
|
|
141
155
|
### Getting a live element handle, not just a selector string
|
|
142
156
|
|
|
143
157
|
By default each occurrence carries a CSS selector + HTML snippet, not a live reference to the element. Opt in to a real Puppeteer `ElementHandle` with `.elementRef(true)`:
|
|
@@ -188,6 +202,33 @@ const results = await new A11yCoreBuilder({ page })
|
|
|
188
202
|
|
|
189
203
|
Invalid input (a missing/empty `id`, or a `runInPage`/`applicability` that's neither a function nor a non-empty string) throws immediately from `.withCustomRules()` itself, rather than surfacing later as a skipped rule deep inside the page — easier to catch during development. A *raw* `.options({ customRules })` call bypasses this check and defers to `@surea11y/core`, which skips a descriptor it can't use without throwing. The result lists each one in `skippedCustomRules` as `{ id, reason }`, and `getScanGaps()`/`formatFailures(results)` report it, so a rule that did not run doesn't look like one that passed.
|
|
190
204
|
|
|
205
|
+
### Scanning with packs: standards, checklists and your own rules
|
|
206
|
+
|
|
207
|
+
A pack brings rules, variants of core's rules, a standard or a checklist, and their profiles and messages, from a package of its own: a national standard such as RGAA, or your organisation's accessibility policy. `@surea11y/core` runs a pack as it runs its own rules and standards, so its results, rollups and report entries look like core's. Packs need `@surea11y/core` 1.11.1 or later.
|
|
208
|
+
|
|
209
|
+
`.withPacks()` registers packs in the page, and in every frame with `.frames(true)`, before the scan; a pack's profile is chosen with `.options({ profile })`:
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
const acmePolicy = require('@acme/a11y-policy'); // a pack
|
|
213
|
+
|
|
214
|
+
const results = await new A11yCoreBuilder({ page })
|
|
215
|
+
.withPacks(acmePolicy)
|
|
216
|
+
.options({ profile: 'acme-web-2026' })
|
|
217
|
+
.analyze();
|
|
218
|
+
|
|
219
|
+
results.engine.packs; // ['@acme/a11y-policy@1.0.0']
|
|
220
|
+
results.engine.profile; // 'acme-web-2026'
|
|
221
|
+
|
|
222
|
+
// A checklist's items, each one result, beside core's WCAG rollups:
|
|
223
|
+
results.rulesResults.filter((r) => r.meta && r.meta.standard === 'Acme web policy');
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
A pack's own rules appear in `checksResults` like core's, with ids that start with its namespace (`acme-no-autoplay`). Without its profile, a pack's rules run only when selected, with `.withRules()` or by a tag. `@surea11y/core`'s HTML, SARIF and JUnit reports show a standard's or a checklist's items in a section of their own. Pass an array, or call `.withPacks()` again, to scan with several packs.
|
|
227
|
+
|
|
228
|
+
**Writing a pack.** A pack is an object made with `definePack` from `@surea11y/core/pack`. [`examples/acme-policy-pack.js`](./examples/acme-policy-pack.js) is a small one: a house rule, a checklist profile (WCAG 2.2 A and AA, `region`, and the house rule) and two checklist items. `npm run example:pack` scans a page with it, and [`examples/e2e-test-example.test.js`](./examples/e2e-test-example.test.js) uses it as a test gate. For a pack of your own, `npx surea11y-pack new <folder>` (from `@surea11y/core`) writes a package that works as generated, with its tests, docs and lint; core's [`PACKS.md`](https://github.com/SureA11y/core/blob/main/docs/PACKS.md) is the guide.
|
|
229
|
+
|
|
230
|
+
**When a pack doesn't run.** `.withPacks()` builds the page's script with the `@surea11y/core` this binding loads, and checks each pack as it does: `.analyze()` throws before scanning for a pack that core can't run, such as one whose `core` range leaves out the installed core, or whose profile names a rule that doesn't exist. A pack the page then doesn't run (one named with a raw `.options({ packs })` and never registered, or a page running another core version, when two copies of core are installed) is listed in `results.skippedPacks` with the reason. `getScanGaps()` reports that as `'pack-skipped'`, and `.analyze()` warns about it, so a test gate that asserts on `getScanGaps(results)` fails rather than passing with the pack's checks never run. Install the pack beside the binding, so npm resolves one core for both.
|
|
231
|
+
|
|
191
232
|
### Element addressing beyond a CSS selector
|
|
192
233
|
|
|
193
234
|
Every occurrence already carries `selector` and (with `.elementRef(true)`, above) a live `ElementHandle`. It also carries `structuralPath` — a sibling-index path from the document root down to the flagged element (e.g. `[1, 0, 2]`) — a more robust identity than a selector string alone, since it survives some DOM changes a selector wouldn't (an id/class rename, for instance). No opt-in needed; it's already on every `fail`/`cantTell` occurrence today. See [`OUTPUT_SCHEMA.md`](https://github.com/SureA11y/core/blob/main/docs/OUTPUT_SCHEMA.md) for the full field description.
|
|
@@ -198,6 +239,8 @@ Every occurrence already carries `selector` and (with `.elementRef(true)`, above
|
|
|
198
239
|
|
|
199
240
|
- `'INVALID_RUN_ONLY'`: a `.withRules()`/`.withTags()` list in which no value names a rule or a tag the engine knows, such as a misspelled rule ID. A value that names nothing beside ones that do is ignored, with a `console.warn` in the page.
|
|
200
241
|
- `'INVALID_CONTEXT_SELECTOR'`: an `.include()` selector the browser can't parse. `error.selector` is that selector.
|
|
242
|
+
- `'INVALID_ENGINE_OPTIONS'`: with `.options({ strictOptions: true })`, an option the engine doesn't read or a value it can't use. The message names each, with the closest known option (`lcoale`: did you mean `locale`?). Without `strictOptions`, a likely typo is only warned about in the page's console.
|
|
243
|
+
- `'PAGE_BUILTINS_BROKEN'`: the page's own scripts broke a JavaScript built-in the engine relies on (`Array.prototype.filter`, `Map`, `JSON.stringify`, ...), so no result it gave could be trusted. The message names each one.
|
|
201
244
|
|
|
202
245
|
```js
|
|
203
246
|
const { A11yCoreBuilder, EngineError } = require('@surea11y/puppeteer');
|
|
@@ -216,7 +259,17 @@ try {
|
|
|
216
259
|
|
|
217
260
|
## TypeScript
|
|
218
261
|
|
|
219
|
-
`src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships types for the whole builder API plus `@surea11y/core`'s native result shapes (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result shapes are `@surea11y/core`'s own types (its `ScanResult` and the rest), with `elementHandle` added to an occurrence, so they follow the engine: `engine.version`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors` and `margin` are all declared. `EngineError`, `ScanGap` and `EngineErrorCode` come from `@surea11y/binding-base`. `analyze()` is typed `Promise<A11yCoreResult | A11yCoreMultiFrameResult>` — narrow on `'topFrame' in results` (or cast, if you already know which mode you called) to get the specific shape back, since a fluent builder can't statically track that `.frames(true)` was called earlier in the chain. `puppeteer` is a `peerDependencies` entry (not just `devDependencies`) since the class's `page` argument and `Occurrence#elementHandle` both come from it — consumers need their own `puppeteer` install for the types to resolve, same as they already do to construct a `Page` in the first place.
|
|
262
|
+
`src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships types for the whole builder API plus `@surea11y/core`'s native result shapes (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result shapes are `@surea11y/core`'s own types (its `ScanResult` and the rest), with `elementHandle` added to an occurrence, so they follow the engine: `engine.version`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors` and `margin` are all declared. `EngineError`, `ScanGap` and `EngineErrorCode` come from `@surea11y/binding-base`, and so do the types of `withWcag()` (`WcagVersion`, `WcagLevel`) and `withPacks()`, which takes a pack made with `definePack` (`PackLike`). Code that handles every `ScanGap` kind it knows and treats the rest in an `else` branch needs a branch for `'pack-skipped'`, which carries `pack` rather than `selectors`. `analyze()` is typed `Promise<A11yCoreResult | A11yCoreMultiFrameResult>` — narrow on `'topFrame' in results` (or cast, if you already know which mode you called) to get the specific shape back, since a fluent builder can't statically track that `.frames(true)` was called earlier in the chain. `puppeteer` is a `peerDependencies` entry (not just `devDependencies`) since the class's `page` argument and `Occurrence#elementHandle` both come from it — consumers need their own `puppeteer` install for the types to resolve, same as they already do to construct a `Page` in the first place.
|
|
263
|
+
|
|
264
|
+
## What changes with `@surea11y/core` 1.11
|
|
265
|
+
|
|
266
|
+
The binding passes rule IDs, tags and options through to the engine, so these show in results without a change here (see core's [`CHANGELOG.md`](https://github.com/SureA11y/core/blob/main/CHANGELOG.md) for the full list):
|
|
267
|
+
|
|
268
|
+
- **Messages are reworded** in all five languages to say plainly what is wrong and what to do (`This <img> has no alt attribute.`). Message keys, rule IDs, reason codes and baselines are unchanged; a test that matches message text needs the new wording.
|
|
269
|
+
- **Contrast and target size measure what is on screen.** In a browser, the contrast rules check only text a reader can see, measure it against what is painted under it, and measure form field values and placeholders. `target-size-minimum` measures the area a pointer can hit, and exempts only links in a sentence. Expect new findings, and some old ones gone.
|
|
270
|
+
- **`aria-hidden-focus` maps to 4.1.2 only**, no longer to 2.4.7 Focus Visible, so `.withTags('wcag2aa')` alone no longer selects it.
|
|
271
|
+
- **A custom rule counts toward its WCAG criterion.** A `.withCustomRules()` rule with `meta.wcagSc` (or a WCAG `normativeMappings` entry) fails that criterion's rollup when it fails, and custom rules run after core's.
|
|
272
|
+
- **On/off options read as meant**: `.options({ perfStats: 'false' })` is off, where it was on. `.options({ strictOptions: true })` rejects any option the engine doesn't read (see [Errors](#errors)).
|
|
220
273
|
|
|
221
274
|
## Relationship to `@surea11y/playwright`
|
|
222
275
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surea11y/puppeteer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Puppeteer binding for surea11y -- scan real, live-rendered pages for accessibility issues.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
|
@@ -39,20 +39,21 @@
|
|
|
39
39
|
"LICENSE"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@surea11y/binding-base": "^1.
|
|
43
|
-
"@surea11y/core": "^1.
|
|
42
|
+
"@surea11y/binding-base": "^1.3.1",
|
|
43
|
+
"@surea11y/core": "^1.11.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"puppeteer": ">=22.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^
|
|
50
|
-
"puppeteer": "^25.
|
|
51
|
-
"typescript": "^
|
|
49
|
+
"@types/node": "^20.19.43",
|
|
50
|
+
"puppeteer": "^25.13.0",
|
|
51
|
+
"typescript": "^7.0.2"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"test": "node --test tests/*.test.js",
|
|
55
55
|
"example": "node examples/basic-scan.js",
|
|
56
|
-
"example:e2e": "node --test examples/e2e-test-example.test.js"
|
|
56
|
+
"example:e2e": "node --test examples/e2e-test-example.test.js",
|
|
57
|
+
"example:pack": "node examples/scan-with-pack.js"
|
|
57
58
|
}
|
|
58
59
|
}
|
package/src/A11yCoreBuilder.d.ts
CHANGED
|
@@ -33,7 +33,15 @@ export {
|
|
|
33
33
|
formatOccurrenceLocation,
|
|
34
34
|
EngineError
|
|
35
35
|
} from '@surea11y/binding-base';
|
|
36
|
-
export type {
|
|
36
|
+
export type {
|
|
37
|
+
ScanGap,
|
|
38
|
+
EngineErrorCode,
|
|
39
|
+
OccurrenceLocation,
|
|
40
|
+
PackLike,
|
|
41
|
+
WcagVersion,
|
|
42
|
+
WcagLevel
|
|
43
|
+
} from '@surea11y/binding-base';
|
|
44
|
+
import type { PackLike, WcagVersion, WcagLevel } from '@surea11y/binding-base';
|
|
37
45
|
|
|
38
46
|
export type Category = Core.RuleMeta['category'];
|
|
39
47
|
export type LocaleResolutionReason = Core.LocaleResolution['reason'];
|
|
@@ -119,10 +127,23 @@ export class A11yCoreBuilder {
|
|
|
119
127
|
withRules(ruleIds: string | string[]): this;
|
|
120
128
|
/** Never run these specific rule IDs (applied after withRules). */
|
|
121
129
|
disableRules(ruleIds: string | string[]): this;
|
|
130
|
+
/**
|
|
131
|
+
* Run the rules for a WCAG conformance target: `withWcag('2.2', 'AA')`
|
|
132
|
+
* runs those of WCAG 2.2's A and AA criteria. withTags()/withRules() add
|
|
133
|
+
* to them. A later call replaces the target.
|
|
134
|
+
*/
|
|
135
|
+
withWcag(version: WcagVersion | 2.0 | 2.1 | 2.2, level?: WcagLevel): this;
|
|
136
|
+
/** Also run the best-practice rules, those that name no WCAG criterion. */
|
|
137
|
+
withBestPractices(enabled?: boolean): this;
|
|
122
138
|
/** Merge arbitrary engineOptions (locale, contrast.mode, policyContract, ...). */
|
|
123
139
|
options(partialEngineOptions: Record<string, unknown>): this;
|
|
124
140
|
/** Register one or more custom rules for just this scan. Call multiple times to accumulate. */
|
|
125
141
|
withCustomRules(rules: CustomRuleDescriptor | CustomRuleDescriptor[]): this;
|
|
142
|
+
/**
|
|
143
|
+
* Packs from `@surea11y/core/pack` (core 1.11 or later): registered in each
|
|
144
|
+
* frame before the scan, and named in `engineOptions.packs`.
|
|
145
|
+
*/
|
|
146
|
+
withPacks(packs: PackLike | PackLike[]): this;
|
|
126
147
|
/** Post-filter checksResults down to only the given outcomes. */
|
|
127
148
|
reportOnly(outcomes: Core.Outcome | Core.Outcome[]): this;
|
|
128
149
|
/** Opt in to also scanning every sub-frame on the page (including cross-origin iframes). */
|
|
@@ -133,9 +154,13 @@ export class A11yCoreBuilder {
|
|
|
133
154
|
/**
|
|
134
155
|
* Runs the scan. Returns { topFrame, frames } instead of a single result
|
|
135
156
|
* when .frames(true) was used; include() then scopes the top frame only,
|
|
136
|
-
* and each sub-frame is scanned whole. Rejects with an EngineError
|
|
137
|
-
*
|
|
138
|
-
*
|
|
157
|
+
* and each sub-frame is scanned whole. Rejects with an EngineError for
|
|
158
|
+
* input the engine cannot use, with its `code`: 'INVALID_RUN_ONLY'
|
|
159
|
+
* (withRules()/withTags() named no rule or tag it knows),
|
|
160
|
+
* 'INVALID_CONTEXT_SELECTOR' (an include() selector the browser can't
|
|
161
|
+
* parse), 'INVALID_ENGINE_OPTIONS' (an option `strictOptions: true`
|
|
162
|
+
* rejects) or 'PAGE_BUILTINS_BROKEN' (the page's scripts broke a
|
|
163
|
+
* JavaScript built-in the engine relies on).
|
|
139
164
|
*/
|
|
140
165
|
analyze(): Promise<A11yCoreResult | A11yCoreMultiFrameResult>;
|
|
141
166
|
}
|
package/src/A11yCoreBuilder.js
CHANGED
|
@@ -134,6 +134,9 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
134
134
|
*/
|
|
135
135
|
async analyze() {
|
|
136
136
|
const { contextSelector, engineOptions, runOnly } = this._buildEngineArgs();
|
|
137
|
+
// The script that registers withPacks()'s packs in a frame, which the
|
|
138
|
+
// scan names in engineOptions.packs; null without packs.
|
|
139
|
+
const packScript = this._packScript();
|
|
137
140
|
|
|
138
141
|
// Unlike Playwright's page.evaluate(fn, arg), which only accepts a
|
|
139
142
|
// SINGLE argument (forcing a hand-built single-arg wrapper there --
|
|
@@ -152,6 +155,7 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
152
155
|
// `code`; any other error in the page rejects evaluate() as before.
|
|
153
156
|
const runInFrame = async (frameOrPage, frameContextSelector) => {
|
|
154
157
|
const frameUrl = this._url || (typeof frameOrPage.url === 'function' ? frameOrPage.url() : null);
|
|
158
|
+
if (packScript) await frameOrPage.evaluate(packScript);
|
|
155
159
|
const result = rethrowEngineError(
|
|
156
160
|
await frameOrPage.evaluate(inPageScan, frameUrl, frameContextSelector, engineOptions, runOnly)
|
|
157
161
|
);
|