@surea11y/puppeteer 1.5.0 → 1.6.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 +40 -9
- package/package.json +3 -3
- package/src/A11yCoreBuilder.d.ts +1 -1
- package/src/A11yCoreBuilder.js +94 -20
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ A Puppeteer binding for [`@surea11y/core`](https://github.com/SureA11y/core) —
|
|
|
8
8
|
npm install @surea11y/core @surea11y/puppeteer puppeteer
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
`@surea11y/core` 1.
|
|
11
|
+
`@surea11y/core` 1.15.0 or later, the engine, comes with the binding as a regular dependency, so a project that doesn't list it still works. List it in your own `package.json` too, as the line above does: your project and the binding then share one copy, so whatever you do with core directly, writing a SARIF log or an HTML report (`@surea11y/core/sarif`, `/report`), reading the rule catalogue or keeping a baseline, reads results with the same core that produced them. When your core can't match the binding's range, as with a linked checkout (`file:../core`) or a fork, add `"overrides": { "@surea11y/core": "$@surea11y/core" }` beside it.
|
|
12
12
|
|
|
13
13
|
**Coming in 2.0:** core becomes a peer dependency, so the binding will no longer install it for you, and the `overrides` entry is no longer needed. Add `@surea11y/core` to your `package.json` now and 2.0 needs no change.
|
|
14
14
|
|
|
@@ -40,7 +40,7 @@ await browser.close();
|
|
|
40
40
|
|
|
41
41
|
`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.12.0"`); quote it in a bug report.
|
|
42
42
|
|
|
43
|
-
From 1.
|
|
43
|
+
From 1.6.0 this package needs `@surea11y/core` 1.15.0 or later, which it installs with it (see [Install](#install)). Core's rules and messages change between its releases; see [What changes with `@surea11y/core` 1.15](#what-changes-with-surea11ycore-115) below and core's [changelog](https://github.com/SureA11y/core/blob/main/CHANGELOG.md).
|
|
44
44
|
|
|
45
45
|
Also see `examples/basic-scan.js` for a runnable script (`npm run example -- <url>`).
|
|
46
46
|
|
|
@@ -109,7 +109,7 @@ assert.ok(
|
|
|
109
109
|
);
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
`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; a custom rule you excluded yourself with `.disableRules()` is not a gap),
|
|
112
|
+
`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; a custom rule you excluded yourself with `.disableRules()` is not a gap), 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)), and each profile a scan of several did not run (`'profile-not-run'`, from `results.engine.profilesNotRun`, `@surea11y/core` 1.15 and later; 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.
|
|
113
113
|
|
|
114
114
|
That warning is the right default for a test run. A project that already handles gaps itself can take them over with `.logger(fn)`: `fn(gap, result)` is called once per gap, with the gap as `getScanGaps()` gives it and the result of the frame it came from, instead of `console.warn`. A scanning service that shows gaps to its users, say, can send them once to its own structured log, rather than also printing a loose line on the server's console for every scan:
|
|
115
115
|
|
|
@@ -188,9 +188,11 @@ const messages = [results.topFrame, ...results.frames].map((frame) =>
|
|
|
188
188
|
);
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
`.include()` scopes the top frame only: each sub-frame is scanned whole, as `@surea11y/core`'s own `runa11yCoreAcrossFrames` does. The selectors are written against the top document, and since core 1.10.0 a selector that matches nothing scans nothing, so passing them on would leave most frames unscanned. `.exclude()` and every other option apply in every frame. A sub-frame that can't be scanned (detached, navigated away, sandboxed) becomes a `{ url, error }` entry; an [engine error](#errors) rejects the whole `analyze()` from the top frame instead, since it would fail in every frame.
|
|
191
|
+
`.include()` scopes the top frame only: each sub-frame inside its roots is scanned whole, as `@surea11y/core`'s own `runa11yCoreAcrossFrames` does. The selectors are written against the top document, and since core 1.10.0 a selector that matches nothing scans nothing, so passing them on would leave most frames unscanned. `.exclude()` and every other option apply in every frame. Sub-frames are scanned up to four at a time, each result in its frame's place in `page.frames()`; with `.screenshots()` they go one at a time, since taking an element's picture scrolls the page. A sub-frame that can't be scanned (detached, navigated away, sandboxed) becomes a `{ url, error }` entry; an [engine error](#errors) rejects the whole `analyze()` from the top frame instead, since it would fail in every frame.
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
Which frames are scanned, and how, also follows `runa11yCoreAcrossFrames` (`@surea11y/binding-base` 1.7.0 and later). A frame the page doesn't show, or that an open modal dialog covers, unless `.options({ includeHiddenElements: true })`, a frame in content `.exclude()` leaves out, a frame of the top page outside the `.include()` roots, a frame in a shadow root with `.options({ includeShadowDom: false })`, and a frame whose document shows nothing (an empty `about:blank`) are left out of `results.frames`, with the frames inside them. A frame under `aria-hidden="true"` is scanned as aria-hidden content, where names and roles don't apply and contrast, focus and keyboard still do, and one under `inert` only for how it looks; a frame inside one is read the same way (`@surea11y/core` 1.15 and later). The elements around a frame are read through slots and shadow hosts, as the accessibility tree reads them. Each sub-frame's result is named by its own `url`; a `url` given to the constructor names the top frame only.
|
|
194
|
+
|
|
195
|
+
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 from the automation process (CDP in Chrome, WebDriver BiDi in Firefox), 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.
|
|
194
196
|
|
|
195
197
|
`@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.
|
|
196
198
|
|
|
@@ -500,6 +502,24 @@ results.engine.profile; // 'acme-web-2026'
|
|
|
500
502
|
results.rulesResults.filter((r) => r.meta && r.meta.standard === 'Acme web policy');
|
|
501
503
|
```
|
|
502
504
|
|
|
505
|
+
**Several profiles at once.** `.options({ profile })` also takes a list, a pack's profile beside WCAG's or another pack's (`@surea11y/core` 1.15 and later). Each profile judges the page as it would alone, and the result reads as one profile with the rules of all, in the top frame and in each frame with `.frames(true)`:
|
|
506
|
+
|
|
507
|
+
```js
|
|
508
|
+
const waiAria = require('@surea11y/pack-wai-aria');
|
|
509
|
+
|
|
510
|
+
const results = await new A11yCoreBuilder({ page })
|
|
511
|
+
.withPacks(waiAria)
|
|
512
|
+
.options({ profile: ['wcag22-aa', 'wai-aria-1.2'] })
|
|
513
|
+
.analyze();
|
|
514
|
+
|
|
515
|
+
results.engine.profiles; // ['wcag22-aa', 'wai-aria-1.2']
|
|
516
|
+
// A rule both run is one check: its outcome is the worst, and its verdicts
|
|
517
|
+
// say what each profile makes of it.
|
|
518
|
+
results.checksResults.find((c) => c.ruleId === 'aria-allowed-attr').verdicts;
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
A profile that didn't run is in `results.engine.profilesNotRun`, with why, and `getScanGaps()` reports it as `'profile-not-run'`. Core's [`OUTPUT_SCHEMA.md`](https://github.com/SureA11y/core/blob/main/docs/OUTPUT_SCHEMA.md#several-profiles) has the whole result.
|
|
522
|
+
|
|
503
523
|
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.
|
|
504
524
|
|
|
505
525
|
**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.
|
|
@@ -508,7 +528,7 @@ A pack's own rules appear in `checksResults` like core's, with ids that start wi
|
|
|
508
528
|
|
|
509
529
|
### Style sheets from another origin
|
|
510
530
|
|
|
511
|
-
A page's script can't read the rules of a style sheet served from another origin (a CDN, a fonts service), so a check that reads the CSS, such as `css-orientation-lock`, can't tell whether it holds an orientation lock and asks about it. With `@surea11y/core` 1.14.0 or later, `.analyze()` asks the page which sheets it can't read, fetches them from Node (without the browser's cookies), and gives core their text, which it then checks. It's on by default
|
|
531
|
+
A page's script can't read the rules of a style sheet served from another origin (a CDN, a fonts service), so a check that reads the CSS, such as `css-orientation-lock`, can't tell whether it holds an orientation lock and asks about it. With `@surea11y/core` 1.14.0 or later, `.analyze()` asks the page which sheets it can't read, fetches them from Node (without the browser's cookies), and gives core their text, which it then checks. It's on by default; each request is given up after five seconds, and a sheet that can't be fetched leaves the check asking as before. To send no request but the page's own:
|
|
512
532
|
|
|
513
533
|
```js
|
|
514
534
|
await new A11yCoreBuilder({ page }).fetchStyleSheets(false).analyze();
|
|
@@ -544,7 +564,18 @@ try {
|
|
|
544
564
|
|
|
545
565
|
## TypeScript
|
|
546
566
|
|
|
547
|
-
`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`, `ScanNote` and `EngineErrorCode` come from `@surea11y/binding-base`, and so do the types of `withWcag()` and `wcagLevel()` (`WcagVersion`, `WcagLevelInput`), of `plannedChecks()`/`plannedCriteria()` (`PlannedCheck`, `PlannedCriterion`) of `withPacks()`, which takes a pack made with `definePack` (`PackLike`), and of `.screenshots()` (`ScreenshotOptions`, and `OccurrenceScreenshot` for an occurrence's `screenshot`). `A11yCoreBuilder.installInternalsHook(page)`, `installListenerHook(page)`, `installLiveRegionHook(page)` and `announcements(page)` are typed as static methods, the last resolving to `LocatedAnnouncement[] | null` (from `@surea11y/binding-base`). 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.
|
|
567
|
+
`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`, `ScanNote` and `EngineErrorCode` come from `@surea11y/binding-base`, and so do the types of `withWcag()` and `wcagLevel()` (`WcagVersion`, `WcagLevelInput`), of `plannedChecks()`/`plannedCriteria()` (`PlannedCheck`, `PlannedCriterion`), of `withPacks()`, which takes a pack made with `definePack` (`PackLike`), and of `.screenshots()` (`ScreenshotOptions`, and `OccurrenceScreenshot` for an occurrence's `screenshot`). `A11yCoreBuilder.installInternalsHook(page)`, `installListenerHook(page)`, `installLiveRegionHook(page)` and `announcements(page)` are typed as static methods, the last resolving to `LocatedAnnouncement[] | null` (from `@surea11y/binding-base`). 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`, and one for `'profile-not-run'`, which carries `profile`. `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.
|
|
568
|
+
|
|
569
|
+
## What changes with `@surea11y/core` 1.15
|
|
570
|
+
|
|
571
|
+
With `@surea11y/core` 1.15.0, what a scan through this binding shows differently (core's [`CHANGELOG.md`](https://github.com/SureA11y/core/blob/main/CHANGELOG.md) has the full list):
|
|
572
|
+
|
|
573
|
+
- **WCAG fails only where WCAG fails.** Where only WAI-ARIA or the HTML content model is broken (an attribute the role doesn't support, an unnamed grid or dialog, a heading in a list), the ARIA and HTML structure rules now ask (`cantTell`, uncertainty `spec-only`) instead of failing. The findings keep their reason codes, so baselines still match, and a gate on `fail` no longer fails on them.
|
|
574
|
+
- **Frames are read as the browser reads them.** A framed document is no page of its own, so its title, language, viewport and landmark rules are `notApplicable`; a frame under `aria-hidden` or `inert` is read as such, one behind an open modal dialog is left out, and one in a shadow root is read through its host ([more](#scanning-every-frame-including-cross-origin-iframes)).
|
|
575
|
+
- **Several profiles at once.** `.options({ profile: ['wcag22-aa', 'wai-aria-1.2'] })`, with the packs that bring them, judges the page by each; a profile that can't run is a `profile-not-run` gap ([more](#scanning-with-packs-standards-checklists-and-your-own-rules)).
|
|
576
|
+
- **A picture in the state the finding was made in.** A `text-spacing-content-loss` finding is also pictured with the spacing applied ([more](#a-picture-of-each-failing-element)).
|
|
577
|
+
- **How to check by hand.** Core's procedures say how a person assesses each criterion, and its HTML report lists what a scan leaves to a person.
|
|
578
|
+
- **Roles follow WAI-ARIA more closely:** `role="text"` names no role, and an image with a presentational role and a global ARIA attribute keeps its role, so it fails without `alt`.
|
|
548
579
|
|
|
549
580
|
## What changes with `@surea11y/core` 1.14
|
|
550
581
|
|
|
@@ -564,7 +595,7 @@ With `@surea11y/core` 1.14.0, what a scan through this binding shows differently
|
|
|
564
595
|
|
|
565
596
|
## What changes with `@surea11y/core` 1.12
|
|
566
597
|
|
|
567
|
-
|
|
598
|
+
From 1.4.0 this package needs `@surea11y/core` 1.12.0. What a scan through this binding shows differently (core's [`CHANGELOG.md`](https://github.com/SureA11y/core/blob/main/CHANGELOG.md) has the full list):
|
|
568
599
|
|
|
569
600
|
- **An empty heading now fails an unscoped scan.** `empty-heading` used to ask about a heading with no accessible name; it now fails it. It's a best practice, so it runs in a scan that selects nothing and with `.withBestPractices()`, not under `.withWcag()`, tags or a profile. A gate on a page with `<h2></h2>` that asserted no failures now fails: fix the heading, or scan a WCAG target.
|
|
570
601
|
- **Scans that pick rules report their criteria.** `.withRules('img-alt-present')`, a non-WCAG tag or `.withBestPractices()` now fill `rulesResults` with the WCAG criteria those rules belong to, where it was empty. A criterion whose other rules weren't selected is `cantTell` (`reasonCode` `composite.rollup.cantTell.notSelectedChild`), and each check's `rollupIds` names the criteria it was added for. `.wcagLevel()` keeps those criteria to a level.
|
|
@@ -590,7 +621,7 @@ The binding passes rule IDs, tags and options through to the engine, so these sh
|
|
|
590
621
|
|
|
591
622
|
## Relationship to `@surea11y/playwright`
|
|
592
623
|
|
|
593
|
-
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
|
|
624
|
+
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 mostly a swap of `puppeteer.launch()`/`playwright.chromium.launch()`. The differences follow the drivers: the hooks are installed on a page, since Puppeteer runs a script before a page's own only through `page.evaluateOnNewDocument()`, style sheets from another origin are fetched without the browser's cookies, in Firefox Puppeteer can't emulate forced colors or a color scheme, and `.frames(true)` scans up to four sub-frames at a time. `analyze()`'s injection call is also simpler here, since Puppeteer's `page.evaluate()` is genuinely variadic and doesn't need the wrapper/`eval()` trick Playwright's single-argument `evaluate()` requires.
|
|
594
625
|
|
|
595
626
|
## Building another framework binding?
|
|
596
627
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surea11y/puppeteer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Accessibility (a11y, WCAG) checks for Puppeteer scripts and tests: scan the live page with new A11yCoreBuilder({ page }).analyze() and get only proven violations, with findings that need human review listed separately.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"LICENSE"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@surea11y/binding-base": "^1.
|
|
49
|
-
"@surea11y/core": "^1.
|
|
48
|
+
"@surea11y/binding-base": "^1.7.0",
|
|
49
|
+
"@surea11y/core": "^1.15.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"puppeteer": ">=22.0.0"
|
package/src/A11yCoreBuilder.d.ts
CHANGED
|
@@ -263,7 +263,7 @@ export class A11yCoreBuilder {
|
|
|
263
263
|
/**
|
|
264
264
|
* Runs the scan. Returns { topFrame, frames } instead of a single result
|
|
265
265
|
* when .frames(true) was used; include() then scopes the top frame only,
|
|
266
|
-
* and each sub-frame is scanned whole. Rejects with an EngineError for
|
|
266
|
+
* and each sub-frame inside its roots is scanned whole. Rejects with an EngineError for
|
|
267
267
|
* input the engine cannot use, with its `code`: 'INVALID_RUN_ONLY'
|
|
268
268
|
* (withRules()/withTags() named no rule or tag it knows),
|
|
269
269
|
* 'INVALID_CONTEXT_SELECTOR' (an include() selector the browser can't
|
package/src/A11yCoreBuilder.js
CHANGED
|
@@ -3,18 +3,48 @@
|
|
|
3
3
|
const core = require('@surea11y/core');
|
|
4
4
|
|
|
5
5
|
const { runa11yCoreInPage, internalsHookScript } = core;
|
|
6
|
+
const bindingBase = require('@surea11y/binding-base');
|
|
6
7
|
const {
|
|
7
8
|
A11yCoreBuilderBase,
|
|
8
9
|
createInPageScan,
|
|
9
10
|
rethrowEngineError,
|
|
10
|
-
queryOccurrenceElement
|
|
11
|
-
|
|
11
|
+
queryOccurrenceElement,
|
|
12
|
+
// How .frames(true) reads each frame (binding-base 1.7 and later).
|
|
13
|
+
readFrameElement,
|
|
14
|
+
isFrameDocumentEmpty,
|
|
15
|
+
frameReadingOptions
|
|
16
|
+
} = bindingBase;
|
|
17
|
+
const frameEngineOptions = bindingBase.frameEngineOptions || ((engineOptions) => engineOptions);
|
|
18
|
+
// What a frame is under, with what the frames around it are under
|
|
19
|
+
// (binding-base 1.7 and later; aria-hidden and inert alike).
|
|
20
|
+
const inheritFrameReading = bindingBase.inheritFrameReading || ((above, reading) => ({
|
|
21
|
+
ariaHidden: !!((above && above.ariaHidden) || (reading && reading.ariaHidden)),
|
|
22
|
+
inert: !!((above && above.inert) || (reading && reading.inert))
|
|
23
|
+
}));
|
|
12
24
|
|
|
13
25
|
// core's scan, wrapped so an engine error keeps its `code` across
|
|
14
26
|
// page.evaluate(), which keeps only an error's message. Built once; it is
|
|
15
27
|
// self-contained, so Puppeteer serializes it as it did runa11yCoreInPage.
|
|
16
28
|
const inPageScan = createInPageScan(runa11yCoreInPage);
|
|
17
29
|
|
|
30
|
+
// How many sub-frames a .frames(true) scan runs at once.
|
|
31
|
+
const FRAME_CONCURRENCY = 4;
|
|
32
|
+
|
|
33
|
+
/** Maps `items` through async `fn`, at most `limit` at a time, keeping their order. */
|
|
34
|
+
async function mapInBatches(items, limit, fn) {
|
|
35
|
+
const out = new Array(items.length);
|
|
36
|
+
let next = 0;
|
|
37
|
+
const worker = async () => {
|
|
38
|
+
while (next < items.length) {
|
|
39
|
+
const i = next;
|
|
40
|
+
next += 1;
|
|
41
|
+
out[i] = await fn(items[i]);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
18
48
|
/**
|
|
19
49
|
* Puppeteer binding for surea11y -- scans a real, already-rendered page.
|
|
20
50
|
*
|
|
@@ -53,7 +83,7 @@ const inPageScan = createInPageScan(runa11yCoreInPage);
|
|
|
53
83
|
* // results.frames -- array of the same native result shape, one per sub-frame
|
|
54
84
|
*
|
|
55
85
|
* Unlike script-injection-based accessibility engines (which need a
|
|
56
|
-
* postMessage-based protocol
|
|
86
|
+
* postMessage-based protocol to reach cross-origin
|
|
57
87
|
* iframes, since they're injected as a plain <script> and are fully subject
|
|
58
88
|
* to the browser's same-origin policy), this doesn't need any @surea11y/core
|
|
59
89
|
* engine support: Puppeteer drives every frame
|
|
@@ -231,17 +261,21 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
231
261
|
// An engine error (INVALID_RUN_ONLY, INVALID_CONTEXT_SELECTOR) comes
|
|
232
262
|
// back as a plain object and is thrown here as an EngineError with its
|
|
233
263
|
// `code`; any other error in the page rejects evaluate() as before.
|
|
234
|
-
|
|
235
|
-
|
|
264
|
+
// url() names the top page only; a frame is named by its own address.
|
|
265
|
+
const top = this._page.mainFrame ? this._page.mainFrame() : null;
|
|
266
|
+
const runInFrame = async (frameOrPage, frameContextSelector, frameOptions = engineOptions) => {
|
|
267
|
+
const isTop = frameOrPage === this._page || frameOrPage === top;
|
|
268
|
+
const ownUrl = typeof frameOrPage.url === 'function' ? frameOrPage.url() : null;
|
|
269
|
+
const frameUrl = isTop ? this._url || ownUrl : ownUrl;
|
|
236
270
|
if (packScript) await frameOrPage.evaluate(packScript);
|
|
237
271
|
// The text of the style sheets the frame can't read, fetched from Node
|
|
238
272
|
// (binding-base 1.6.0 and core 1.14.0; nothing with older ones).
|
|
239
|
-
const
|
|
273
|
+
const scanOptions =
|
|
240
274
|
typeof this._styleSheetEngineOptions === 'function'
|
|
241
|
-
? await this._styleSheetEngineOptions(frameOrPage,
|
|
242
|
-
:
|
|
275
|
+
? await this._styleSheetEngineOptions(frameOrPage, frameOptions)
|
|
276
|
+
: frameOptions;
|
|
243
277
|
const result = rethrowEngineError(
|
|
244
|
-
await frameOrPage.evaluate(inPageScan, frameUrl, frameContextSelector,
|
|
278
|
+
await frameOrPage.evaluate(inPageScan, frameUrl, frameContextSelector, scanOptions, runOnly)
|
|
245
279
|
);
|
|
246
280
|
this._warnScanGaps(result, '@surea11y/puppeteer');
|
|
247
281
|
// Right after the frame's scan, before reportOnly(): nothing unless
|
|
@@ -269,29 +303,69 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
269
303
|
// it's already covered by topFrame above, so callers don't have to
|
|
270
304
|
// de-duplicate it themselves out of the frames array.
|
|
271
305
|
const subFrames = this._page.frames().filter((f) => f !== mainFrame);
|
|
272
|
-
|
|
273
|
-
|
|
306
|
+
// include() scopes the top frame only: each sub-frame is scanned whole,
|
|
307
|
+
// as core's own runa11yCoreAcrossFrames does. The selectors were written
|
|
308
|
+
// against the top document, and since core 1.10.0 a selector that
|
|
309
|
+
// matches nothing scans nothing, so passing them on would leave most
|
|
310
|
+
// frames unscanned.
|
|
311
|
+
// Each frame read as core's own scan across frames reads it
|
|
312
|
+
// (binding-base's frames helpers, 1.7 and later): one the page doesn't
|
|
313
|
+
// show, that is excluded or outside include()'s roots, or that shows
|
|
314
|
+
// nothing is left out; one under aria-hidden is scanned as aria-hidden.
|
|
315
|
+
// A frame inside one inherits how it is read.
|
|
316
|
+
const readings = new Map();
|
|
317
|
+
const readingOf = (frame) => {
|
|
318
|
+
if (!readings.has(frame)) readings.set(frame, this._readFrame(frame, mainFrame, readingOf, engineOptions, contextSelector));
|
|
319
|
+
return readings.get(frame);
|
|
320
|
+
};
|
|
321
|
+
const scanFrame = async (frame) => {
|
|
274
322
|
try {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
// selector that matches nothing scans nothing, so passing them on
|
|
279
|
-
// would leave most frames unscanned.
|
|
280
|
-
frames.push(this._applyReportOnly(await runInFrame(frame, null)));
|
|
323
|
+
const reading = await readingOf(frame);
|
|
324
|
+
if (reading.skipped) return null;
|
|
325
|
+
return this._applyReportOnly(await runInFrame(frame, null, frameEngineOptions(engineOptions, reading)));
|
|
281
326
|
} catch (e) {
|
|
282
327
|
// A frame can detach/navigate away mid-scan, or be a sandboxed
|
|
283
328
|
// frame the browser blocks scripting in -- don't let one bad frame
|
|
284
329
|
// abort the whole multi-frame scan; report it and keep going.
|
|
285
|
-
|
|
330
|
+
return {
|
|
286
331
|
url: (typeof frame.url === 'function' ? frame.url() : null),
|
|
287
332
|
error: (e && e.message) || String(e)
|
|
288
|
-
}
|
|
333
|
+
};
|
|
289
334
|
}
|
|
290
|
-
}
|
|
335
|
+
};
|
|
336
|
+
// Frames are scanned a few at a time, each result in the frame's place
|
|
337
|
+
// in page.frames(): a page of 50 small frames took 18 s one by one.
|
|
338
|
+
// Element pictures scroll the page, so with .screenshots() they go one
|
|
339
|
+
// at a time, as before.
|
|
340
|
+
const frames = (await mapInBatches(subFrames, this._screenshots ? 1 : FRAME_CONCURRENCY, scanFrame))
|
|
341
|
+
.filter(Boolean);
|
|
291
342
|
|
|
292
343
|
return { topFrame, frames };
|
|
293
344
|
}
|
|
294
345
|
|
|
346
|
+
/**
|
|
347
|
+
* How a sub-frame is read: `{ skipped }`, `{ ariaHidden }` or `{}`, from
|
|
348
|
+
* its element in its parent frame and its own document, as core's scan
|
|
349
|
+
* across frames reads it. Without binding-base's frames helpers, every
|
|
350
|
+
* frame is scanned as before.
|
|
351
|
+
*/
|
|
352
|
+
async _readFrame(frame, mainFrame, readingOf, engineOptions, contextSelector) {
|
|
353
|
+
if (typeof readFrameElement !== 'function') return {};
|
|
354
|
+
const parent = frame.parentFrame && frame.parentFrame();
|
|
355
|
+
const above = parent && parent !== mainFrame ? await readingOf(parent) : {};
|
|
356
|
+
if (above.skipped) return above;
|
|
357
|
+
let own = {};
|
|
358
|
+
try {
|
|
359
|
+
const handle = await frame.frameElement();
|
|
360
|
+
own = await handle.evaluate(readFrameElement, frameReadingOptions(engineOptions, contextSelector, parent === mainFrame));
|
|
361
|
+
await handle.dispose().catch(() => {});
|
|
362
|
+
if (!own.skipped && (await frame.evaluate(isFrameDocumentEmpty))) own = { skipped: 'empty' };
|
|
363
|
+
} catch (e) {
|
|
364
|
+
own = {};
|
|
365
|
+
}
|
|
366
|
+
return own.skipped ? own : inheritFrameReading(above, own);
|
|
367
|
+
}
|
|
368
|
+
|
|
295
369
|
/**
|
|
296
370
|
* Resolves each fail/cantTell occurrence to a live ElementHandle, scoped
|
|
297
371
|
* to frameOrPage's own document (a Puppeteer Page and Frame both expose
|