@surea11y/puppeteer 0.1.4 → 1.0.1
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 +33 -36
- package/package.json +3 -3
- package/src/A11yCoreBuilder.d.ts +7 -2
- package/src/A11yCoreBuilder.js +17 -17
- package/src/formatFailures.js +3 -4
package/README.md
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
# surea11y
|
|
1
|
+
# @surea11y/puppeteer
|
|
2
2
|
|
|
3
|
-
A Puppeteer binding for [
|
|
3
|
+
A Puppeteer binding for [`@surea11y/core`](https://github.com/rumoroso/surea11y-core) — scans a real, already-rendered page for accessibility issues using surea11y's DOM-rules engine.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Install (local development)
|
|
8
|
-
|
|
9
|
-
`surea11y` isn't published to npm yet, so this package depends on it via a relative `file:` path (see `package.json`):
|
|
10
|
-
|
|
11
|
-
```json
|
|
12
|
-
"dependencies": { "surea11y": "file:../core" }
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
That means this project must stay a sibling of `surea11y` (or you update the path) for `npm install` to resolve it.
|
|
5
|
+
## Install
|
|
16
6
|
|
|
17
7
|
```bash
|
|
18
|
-
npm install
|
|
19
|
-
npm test
|
|
8
|
+
npm install @surea11y/puppeteer puppeteer
|
|
20
9
|
```
|
|
21
10
|
|
|
22
|
-
|
|
11
|
+
Puppeteer downloads its own bundled Chrome as part of `npm install` — unlike the Playwright binding, there's no separate browser-install step needed for `npm test` to work.
|
|
23
12
|
|
|
24
13
|
The cross-browser regression test in `tests/cross-browser.test.js` (proving this works against Firefox too, not just Chrome) additionally needs `npx puppeteer browsers install firefox`.
|
|
25
14
|
|
|
@@ -27,7 +16,7 @@ The cross-browser regression test in `tests/cross-browser.test.js` (proving this
|
|
|
27
16
|
|
|
28
17
|
```js
|
|
29
18
|
const puppeteer = require('puppeteer');
|
|
30
|
-
const { A11yCoreBuilder } = require('surea11y
|
|
19
|
+
const { A11yCoreBuilder } = require('@surea11y/puppeteer');
|
|
31
20
|
|
|
32
21
|
const browser = await puppeteer.launch();
|
|
33
22
|
const page = await browser.newPage();
|
|
@@ -45,11 +34,13 @@ console.log(results.checksResults.filter(r => r.outcome === 'fail'));
|
|
|
45
34
|
await browser.close();
|
|
46
35
|
```
|
|
47
36
|
|
|
48
|
-
`results` is surea11y's own native result shape — see [
|
|
37
|
+
`results` is `@surea11y/core`'s own native result shape — see its [`OUTPUT_SCHEMA.md`](https://github.com/rumoroso/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.
|
|
49
38
|
|
|
50
39
|
Also see `examples/basic-scan.js` for a runnable script (`npm run example -- <url>`).
|
|
51
40
|
|
|
52
|
-
`withTags()`/`disableRules()` above 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's default `includeMode: 'and'` — see
|
|
41
|
+
`withTags()`/`disableRules()` above 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/rumoroso/surea11y-core/blob/main/docs/ENGINE_OPTIONS.md)), not either one.
|
|
42
|
+
|
|
43
|
+
`.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.
|
|
53
44
|
|
|
54
45
|
**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.
|
|
55
46
|
|
|
@@ -61,7 +52,7 @@ The pattern above works unchanged inside a real test:
|
|
|
61
52
|
|
|
62
53
|
```js
|
|
63
54
|
const puppeteer = require('puppeteer');
|
|
64
|
-
const { A11yCoreBuilder, formatFailures } = require('surea11y
|
|
55
|
+
const { A11yCoreBuilder, formatFailures } = require('@surea11y/puppeteer');
|
|
65
56
|
|
|
66
57
|
const browser = await puppeteer.launch();
|
|
67
58
|
const page = await browser.newPage();
|
|
@@ -72,7 +63,7 @@ const results = await new A11yCoreBuilder({ page }).reportOnly(['fail']).analyze
|
|
|
72
63
|
assert.strictEqual(results.checksResults.length, 0, formatFailures(results.checksResults));
|
|
73
64
|
```
|
|
74
65
|
|
|
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 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
|
|
66
|
+
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 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.
|
|
76
67
|
|
|
77
68
|
### Readable console/CI output on failure
|
|
78
69
|
|
|
@@ -87,7 +78,7 @@ Error: 1) button-name-present (serious): This button has no accessible name.
|
|
|
87
78
|
Add an alt attribute (use alt="" only for decorative images).
|
|
88
79
|
```
|
|
89
80
|
|
|
90
|
-
Deliberately a plain function, not a custom `expect` matcher — no dependency on any particular assertion library, so it works the same with `node:assert`, Jest, Vitest, or a hand-rolled `if`/`throw`. Defaults to `fail`/`cantTell` outcomes (the only two that ever carry occurrences); pass `{ outcomes: [...] }` to narrow further. A thrown rule (`occurrences: []`, `error` set — see
|
|
81
|
+
Deliberately a plain function, not a custom `expect` matcher — no dependency on any particular assertion library, so it works the same with `node:assert`, Jest, Vitest, or a hand-rolled `if`/`throw`. Defaults to `fail`/`cantTell` outcomes (the only two that ever carry occurrences); pass `{ outcomes: [...] }` to narrow further. A thrown rule (`occurrences: []`, `error` set — see [`OUTPUT_SCHEMA.md`](https://github.com/rumoroso/surea11y-core/blob/main/docs/OUTPUT_SCHEMA.md)) is still surfaced using its `error` message rather than silently dropped.
|
|
91
82
|
|
|
92
83
|
### Scanning every frame, including cross-origin iframes
|
|
93
84
|
|
|
@@ -100,11 +91,11 @@ for (const frame of results.frames) {
|
|
|
100
91
|
}
|
|
101
92
|
```
|
|
102
93
|
|
|
103
|
-
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
|
|
94
|
+
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.
|
|
104
95
|
|
|
105
96
|
### Trimming the result to just violations
|
|
106
97
|
|
|
107
|
-
By default `analyze()` returns every rule's outcome, including `pass`/`notApplicable` — surea11y's own deliberate "not a violations-only list" design (see
|
|
98
|
+
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/rumoroso/surea11y-core/blob/main/docs/OUTPUT_SCHEMA.md)). Use `.reportOnly()` to post-filter down to only the outcomes you care about:
|
|
108
99
|
|
|
109
100
|
```js
|
|
110
101
|
const results = await new A11yCoreBuilder({ page })
|
|
@@ -114,7 +105,7 @@ const results = await new A11yCoreBuilder({ page })
|
|
|
114
105
|
console.log(results.checksResults); // only fail/cantTell entries, pass/notApplicable dropped
|
|
115
106
|
```
|
|
116
107
|
|
|
117
|
-
Valid outcome values are `'pass'`, `'fail'`, `'cantTell'`, `'notApplicable'`. This is pure binding-layer filtering —
|
|
108
|
+
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.
|
|
118
109
|
|
|
119
110
|
### Getting a live element handle, not just a selector string
|
|
120
111
|
|
|
@@ -134,7 +125,7 @@ Each `ElementHandle` holds a browser-side reference until garbage collected or e
|
|
|
134
125
|
|
|
135
126
|
### Registering a custom rule at runtime
|
|
136
127
|
|
|
137
|
-
|
|
128
|
+
`@surea11y/core` supports registering additional rules per-scan via `engineOptions.customRules`. Use `.withCustomRules()` to register one:
|
|
138
129
|
|
|
139
130
|
```js
|
|
140
131
|
const results = await new A11yCoreBuilder({ page })
|
|
@@ -151,7 +142,7 @@ const results = await new A11yCoreBuilder({ page })
|
|
|
151
142
|
.analyze();
|
|
152
143
|
```
|
|
153
144
|
|
|
154
|
-
A custom rule descriptor is the same shape as one of surea11y's own internal rule modules (`{ id, meta, runInPage, applicability?, data? }`) — see
|
|
145
|
+
A custom rule descriptor is the same shape as one of `@surea11y/core`'s own internal rule modules (`{ id, meta, runInPage, applicability?, data? }`) — see its [`ENGINE_OPTIONS.md`](https://github.com/rumoroso/surea11y-core/blob/main/docs/ENGINE_OPTIONS.md) for the full contract. Results appear in `checksResults` exactly like a built-in rule's, including automatic `selector`/`html`/`structuralPath` fill-in. Registered per-scan only (nothing persists between calls or shows up in any catalog listing), and a custom rule whose `id` collides with a built-in one overrides it for that scan.
|
|
155
146
|
|
|
156
147
|
Pass an array to register several at once, or call `.withCustomRules()` again to add more — like `.withRules()`/`.withTags()`, it accumulates rather than replacing what was already registered:
|
|
157
148
|
|
|
@@ -162,24 +153,30 @@ const results = await new A11yCoreBuilder({ page })
|
|
|
162
153
|
.analyze();
|
|
163
154
|
```
|
|
164
155
|
|
|
165
|
-
**Why `.withCustomRules()` instead of the raw `.options({ customRules })` passthrough** (still supported, and composes with this method if you use both): `runInPage`/`applicability` must reach the page as a function-source *string*, not a live `Function` — a Puppeteer `page.evaluate()` argument crosses a serialization boundary that can't carry a live function reference, only a string surea11y can reconstruct with `new Function` on the page side. Passing a raw live function via `.options()` directly would silently fail to serialize; `.withCustomRules()` calls `.toString()` on a live function for you, so you can write a normal function and not have to remember that constraint yourself. A string is still accepted as-is if you already have one.
|
|
156
|
+
**Why `.withCustomRules()` instead of the raw `.options({ customRules })` passthrough** (still supported, and composes with this method if you use both): `runInPage`/`applicability` must reach the page as a function-source *string*, not a live `Function` — a Puppeteer `page.evaluate()` argument crosses a serialization boundary that can't carry a live function reference, only a string `@surea11y/core` can reconstruct with `new Function` on the page side. Passing a raw live function via `.options()` directly would silently fail to serialize; `.withCustomRules()` calls `.toString()` on a live function for you, so you can write a normal function and not have to remember that constraint yourself. A string is still accepted as-is if you already have one.
|
|
166
157
|
|
|
167
|
-
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 silently-skipped rule deep inside the page — easier to catch during development. (Note: a *raw* `.options({ customRules })` call bypasses this check entirely and defers to surea11y's own engine-side behavior, which silently skips an invalid descriptor rather than throwing
|
|
158
|
+
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 silently-skipped rule deep inside the page — easier to catch during development. (Note: a *raw* `.options({ customRules })` call bypasses this check entirely and defers to `@surea11y/core`'s own engine-side behavior, which silently skips an invalid descriptor rather than throwing.)
|
|
168
159
|
|
|
169
160
|
### Element addressing beyond a CSS selector
|
|
170
161
|
|
|
171
|
-
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
|
|
162
|
+
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/rumoroso/surea11y-core/blob/main/docs/OUTPUT_SCHEMA.md) for the full field description.
|
|
172
163
|
|
|
173
164
|
## TypeScript
|
|
174
165
|
|
|
175
|
-
`src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships hand-written types for the whole builder API plus surea11y's native result shapes (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.), mirrored from
|
|
166
|
+
`src/A11yCoreBuilder.d.ts` (re-exported from `src/index.d.ts`, wired up via `package.json`'s `types` field) ships hand-written types for the whole builder API plus `@surea11y/core`'s native result shapes (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.), mirrored from [`OUTPUT_SCHEMA.md`](https://github.com/rumoroso/surea11y-core/blob/main/docs/OUTPUT_SCHEMA.md). `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.
|
|
167
|
+
|
|
168
|
+
## Relationship to `@surea11y/playwright`
|
|
169
|
+
|
|
170
|
+
This binding's builder API is deliberately identical to `@surea11y/playwright`'s — same method names, same mutability contract, same result shapes — so switching between the two (or running the same accessibility gate logic against both) is a drop-in swap of `puppeteer.launch()`/`playwright.chromium.launch()` and nothing else. The one real implementation difference is internal: `analyze()`'s injection call is simpler here, since Puppeteer's `page.evaluate()` is genuinely variadic and doesn't need the wrapper/`eval()` trick Playwright's single-argument `evaluate()` requires.
|
|
171
|
+
|
|
172
|
+
## Building another framework binding?
|
|
176
173
|
|
|
177
|
-
|
|
174
|
+
See `@surea11y/core`'s [`BINDING_AUTHORS_GUIDE.md`](https://github.com/rumoroso/surea11y-core/blob/main/docs/BINDING_AUTHORS_GUIDE.md) — a reference for building a new binding, covering which parity features are engine-level (work through a generic `.options()`/`runOnly` passthrough with zero binding code, including WCAG-version tag filtering) vs. binding-layer (element refs, `reportOnly`-style verbosity filtering, the `page.evaluate()`/`frame.evaluate()` serialization-boundary caveat that `.withCustomRules()` exists to paper over). It cites this project's `.elementRef()`, `.reportOnly()`, `.frames(true)`, and `.withCustomRules()` by name as worked examples alongside `@surea11y/playwright`'s.
|
|
178
175
|
|
|
179
|
-
|
|
176
|
+
`A11yCoreBuilder` here extends `A11yCoreBuilderBase` from [`@surea11y/binding-base`](https://github.com/rumoroso/surea11y-core-binding-base), a small shared package holding the scaffolding common to every framework binding. A new binding should depend on that package from the start.
|
|
180
177
|
|
|
181
|
-
|
|
178
|
+
## License
|
|
182
179
|
|
|
183
|
-
|
|
180
|
+
MIT — see [`LICENSE`](./LICENSE).
|
|
184
181
|
|
|
185
|
-
|
|
182
|
+
This package depends on [`@surea11y/core`](https://github.com/rumoroso/surea11y-core), which is MPL-2.0. MPL-2.0's copyleft is file-level and applies only to `@surea11y/core`'s own source files; consuming it as a normal package dependency doesn't affect this package's license.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surea11y/puppeteer",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Puppeteer binding for surea11y -- scan real, live-rendered pages for accessibility issues.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"LICENSE"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@surea11y/core": "^1.
|
|
30
|
-
"@surea11y/binding-base": "^1.
|
|
29
|
+
"@surea11y/core": "^1.1.0",
|
|
30
|
+
"@surea11y/binding-base": "^1.1.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"puppeteer": ">=22.0.0"
|
package/src/A11yCoreBuilder.d.ts
CHANGED
|
@@ -170,8 +170,13 @@ export class A11yCoreBuilder {
|
|
|
170
170
|
|
|
171
171
|
/** Scope the scan to one region. Call multiple times for a multi-region union. */
|
|
172
172
|
include(selector: string): this;
|
|
173
|
-
/**
|
|
174
|
-
|
|
173
|
+
/**
|
|
174
|
+
* Skip elements matching this selector anywhere in the scanned scope.
|
|
175
|
+
* With `opts.rules`, scopes the exclusion to just the named rule ID(s)
|
|
176
|
+
* instead of globally -- on top of, not instead of, any global exclusions
|
|
177
|
+
* from other `.exclude(selector)` calls.
|
|
178
|
+
*/
|
|
179
|
+
exclude(selector: string, opts?: { rules?: string | string[] }): this;
|
|
175
180
|
/** Only run rules carrying at least one of these tags. */
|
|
176
181
|
withTags(tags: string | string[]): this;
|
|
177
182
|
/** Never run rules carrying any of these tags (applied after withTags). */
|
package/src/A11yCoreBuilder.js
CHANGED
|
@@ -14,15 +14,15 @@ const { A11yCoreBuilderBase } = require('@surea11y/binding-base');
|
|
|
14
14
|
* .options({ contrast: { mode: 'auditorAssist' } })
|
|
15
15
|
* .analyze();
|
|
16
16
|
*
|
|
17
|
-
* `results` is surea11y's own native result shape (checksResults /
|
|
18
|
-
* rulesResults -- see
|
|
17
|
+
* `results` is @surea11y/core's own native result shape (checksResults /
|
|
18
|
+
* rulesResults -- see ../core/docs/OUTPUT_SCHEMA.md), not the
|
|
19
19
|
* violations/passes/incomplete/inapplicable shape used by other tools in
|
|
20
20
|
* this space. Method names are modeled on common conventions in this space
|
|
21
21
|
* for migration ease, but the richer native schema (severity, confidence,
|
|
22
22
|
* occurrences, policy contract, WCAG SC mappings) is kept as-is rather than
|
|
23
23
|
* reshaped to match.
|
|
24
24
|
*
|
|
25
|
-
* Extends `A11yCoreBuilderBase` (from
|
|
25
|
+
* Extends `A11yCoreBuilderBase` (from `@surea11y/binding-base`), which owns
|
|
26
26
|
* every method with no driver-specific work at all -- `include()`/
|
|
27
27
|
* `exclude()`/`withTags()`/`disableTags()`/`withRules()`/`disableRules()`/
|
|
28
28
|
* `options()`/`reportOnly()`/`elementRef()`/`frames()`/`withCustomRules()`'s
|
|
@@ -31,7 +31,7 @@ const { A11yCoreBuilderBase } = require('@surea11y/binding-base');
|
|
|
31
31
|
* boundary), and `_buildEngineArgs()`. This class adds exactly the parts
|
|
32
32
|
* that are genuinely Puppeteer-specific: `analyze()`'s injection mechanics,
|
|
33
33
|
* frame traversal, and `_attachElementRefs()`. See
|
|
34
|
-
* `../
|
|
34
|
+
* `../binding-base/README.md` for what's shared and why.
|
|
35
35
|
*
|
|
36
36
|
* Opt in to scanning every frame on the page (including cross-origin
|
|
37
37
|
* iframes) via .frames(true):
|
|
@@ -43,17 +43,17 @@ const { A11yCoreBuilderBase } = require('@surea11y/binding-base');
|
|
|
43
43
|
* Unlike script-injection-based accessibility engines (which need a
|
|
44
44
|
* postMessage-based protocol, runPartial/finishRun, to reach cross-origin
|
|
45
45
|
* iframes, since they're injected as a plain <script> and are fully subject
|
|
46
|
-
* to the browser's same-origin policy), this doesn't need any surea11y
|
|
46
|
+
* to the browser's same-origin policy), this doesn't need any @surea11y/core
|
|
47
47
|
* engine support: Puppeteer drives every frame
|
|
48
48
|
* via CDP at the automation-process level, not as in-page script, so
|
|
49
49
|
* cross-origin frame.evaluate() already just works -- verified empirically
|
|
50
|
-
* against a real cross-origin iframe, see
|
|
51
|
-
*
|
|
50
|
+
* against a real cross-origin iframe, see tests/builder.test.js. Default
|
|
51
|
+
* off, so plain .analyze() keeps returning
|
|
52
52
|
* the single native result object it always has.
|
|
53
53
|
*
|
|
54
54
|
* By default `analyze()` returns every rule's outcome, including
|
|
55
|
-
* `pass`/`notApplicable` -- surea11y's own deliberate "not a
|
|
56
|
-
* violations-only list" design (see
|
|
55
|
+
* `pass`/`notApplicable` -- @surea11y/core's own deliberate "not a
|
|
56
|
+
* violations-only list" design (see ../core/docs/OUTPUT_SCHEMA.md).
|
|
57
57
|
* Opt in to a lighter payload with `.reportOnly(['fail', 'cantTell'])`,
|
|
58
58
|
* which post-filters `checksResults` by `outcome` (applied per-frame when
|
|
59
59
|
* combined with `.frames(true)`, since `checksResults` lives at
|
|
@@ -73,12 +73,12 @@ const { A11yCoreBuilderBase } = require('@surea11y/binding-base');
|
|
|
73
73
|
* await firstFail.occurrences[0].elementHandle.screenshot({ path: 'flagged.png' });
|
|
74
74
|
*
|
|
75
75
|
* Register your own rule(s) for just this scan with
|
|
76
|
-
* `.withCustomRules([...])` (surea11y's `engineOptions.customRules`
|
|
77
|
-
* escape hatch -- see
|
|
76
|
+
* `.withCustomRules([...])` (@surea11y/core's `engineOptions.customRules`
|
|
77
|
+
* escape hatch -- see ../core/docs/ENGINE_OPTIONS.md). Pass a real,
|
|
78
78
|
* live `runInPage`/
|
|
79
79
|
* `applicability` function -- unlike the raw `.options({ customRules })`
|
|
80
80
|
* passthrough, this method converts them to the function-source string
|
|
81
|
-
* surea11y needs on this side of the page.evaluate() JSON boundary for
|
|
81
|
+
* @surea11y/core needs on this side of the page.evaluate() JSON boundary for
|
|
82
82
|
* you, so you don't have to remember to call .toString() yourself:
|
|
83
83
|
*
|
|
84
84
|
* const results = await new A11yCoreBuilder({ page })
|
|
@@ -118,23 +118,23 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
* Runs the scan and returns surea11y's native result object.
|
|
122
|
-
* @returns {Promise<object>} see
|
|
121
|
+
* Runs the scan and returns @surea11y/core's native result object.
|
|
122
|
+
* @returns {Promise<object>} see ../core/docs/OUTPUT_SCHEMA.md
|
|
123
123
|
*/
|
|
124
124
|
async analyze() {
|
|
125
125
|
const { contextSelector, engineOptions, runOnly } = this._buildEngineArgs();
|
|
126
126
|
|
|
127
127
|
// Unlike Playwright's page.evaluate(fn, arg), which only accepts a
|
|
128
128
|
// SINGLE argument (forcing a hand-built single-arg wrapper there --
|
|
129
|
-
// see surea11y
|
|
129
|
+
// see @surea11y/playwright's own A11yCoreBuilder.js for the full
|
|
130
130
|
// story), Puppeteer's page.evaluate()/frame.evaluate() is genuinely
|
|
131
131
|
// variadic: evaluate<Params extends unknown[], Func>(pageFunction: Func
|
|
132
132
|
// | string, ...args: Params) (confirmed against a real Puppeteer 25.x
|
|
133
133
|
// install's own puppeteer-core/lib/types.d.ts, on the shared abstract
|
|
134
134
|
// Realm class both Page and Frame implement). That means
|
|
135
135
|
// runa11yCoreInPage's own 4 positional args can be passed straight
|
|
136
|
-
// through with no wrapper/eval() trick needed -- see
|
|
137
|
-
// docs/INTEGRATION.md for the documented example this mirrors.
|
|
136
|
+
// through with no wrapper/eval() trick needed -- see
|
|
137
|
+
// ../core/docs/INTEGRATION.md for the documented example this mirrors.
|
|
138
138
|
const runInFrame = async (frameOrPage) => {
|
|
139
139
|
const frameUrl = this._url || (typeof frameOrPage.url === 'function' ? frameOrPage.url() : null);
|
|
140
140
|
const result = await frameOrPage.evaluate(runa11yCoreInPage, frameUrl, contextSelector, engineOptions, runOnly);
|
package/src/formatFailures.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// Re-exported from surea11y
|
|
3
|
+
// Re-exported from @surea11y/binding-base, which now holds the single
|
|
4
4
|
// canonical copy shared across every surea11y binding -- see
|
|
5
|
-
// ../
|
|
6
|
-
// ../surea11y-binding-base/README.md for the full rationale. Kept as a
|
|
5
|
+
// ../binding-base/README.md for the full rationale. Kept as a
|
|
7
6
|
// real file here (not just re-exporting straight from src/index.js) so
|
|
8
|
-
// `require('surea11y
|
|
7
|
+
// `require('@surea11y/puppeteer/src/formatFailures')` keeps working for
|
|
9
8
|
// anyone importing the submodule path directly.
|
|
10
9
|
const { formatFailures } = require('@surea11y/binding-base');
|
|
11
10
|
|