@surea11y/puppeteer 1.4.1 → 1.4.2
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 +45 -6
- package/package.json +2 -2
- package/src/A11yCoreBuilder.d.ts +31 -3
- package/src/A11yCoreBuilder.js +57 -2
package/README.md
CHANGED
|
@@ -5,12 +5,12 @@ A Puppeteer binding for [`@surea11y/core`](https://github.com/SureA11y/core) —
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @surea11y/puppeteer puppeteer
|
|
8
|
+
npm install @surea11y/core @surea11y/puppeteer puppeteer
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
`@surea11y/core` 1.12.0 or later, the engine, comes with
|
|
11
|
+
`@surea11y/core` 1.12.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
|
|
|
15
15
|
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.
|
|
16
16
|
|
|
@@ -85,7 +85,7 @@ Each of the four takes a string or an array of strings. Anything else, such as `
|
|
|
85
85
|
|
|
86
86
|
`.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.
|
|
87
87
|
|
|
88
|
-
**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()`/`.includeMode()`/`.wcagLevel()`/`.logger()` are the exception: each call replaces the previous value instead of merging with it.
|
|
88
|
+
**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()`/`.screenshots()`/`.withWcag()`/`.withBestPractices()`/`.includeMode()`/`.wcagLevel()`/`.logger()` are the exception: each call replaces the previous value instead of merging with it.
|
|
89
89
|
|
|
90
90
|
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.
|
|
91
91
|
|
|
@@ -220,6 +220,37 @@ This resolves the occurrence to an `ElementHandle` instead of leaving you to re-
|
|
|
220
220
|
|
|
221
221
|
Each `ElementHandle` holds a browser-side reference until garbage collected or explicitly disposed — for a scan with many violations that you're keeping around a while (rather than using immediately, as above), call `occurrence.elementHandle.dispose()` when you're done with it, per [Puppeteer's own `ElementHandle` guidance](https://pptr.dev/api/puppeteer.elementhandle).
|
|
222
222
|
|
|
223
|
+
### A picture of each failing element
|
|
224
|
+
|
|
225
|
+
Opt in with `.screenshots()`, and each occurrence the scan flags gets a `screenshot` field: a picture of the element, with a box drawn around it, or the reason there is none.
|
|
226
|
+
|
|
227
|
+
```js
|
|
228
|
+
const results = await new A11yCoreBuilder({ page })
|
|
229
|
+
.screenshots({ dir: 'a11y-shots', padding: 16 })
|
|
230
|
+
.analyze();
|
|
231
|
+
|
|
232
|
+
const [first] = results.checksResults.filter((r) => r.outcome === 'fail');
|
|
233
|
+
first.occurrences[0].screenshot;
|
|
234
|
+
// { path: 'a11y-shots/element-3f9a1c07.png', box: { x: 20, y: 20, width: 120, height: 40 } }
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
| Option | Default | |
|
|
238
|
+
|---|---|---|
|
|
239
|
+
| `dir` | none | Write each picture there. Without it, each comes back as `{ buffer, box }`, a PNG for you to store your own way. |
|
|
240
|
+
| `outcomes` | `['fail']` | Which occurrences to picture. For contrast, `['fail', 'cantTell']` shows the background the engine couldn't judge. |
|
|
241
|
+
| `padding` | `0` | CSS pixels of context around the element. |
|
|
242
|
+
| `highlight` | `true` | Draw a box around the element, over the page; the element itself is never restyled. |
|
|
243
|
+
| `max` | `50` | At most this many pictures per scan, frames included. |
|
|
244
|
+
|
|
245
|
+
- **One picture per element.** Several rules can flag the same element; it's pictured once, and each of their occurrences carries the same `screenshot`. A file is named after where the element is, so it keeps its name from run to run, and `formatFailures()` names it under each finding (` screenshot: a11y-shots/element-3f9a1c07.png`).
|
|
246
|
+
- **`box`** is where the element shows in the picture, in CSS pixels; the PNG is larger by the device pixel ratio. `cropped: true` says only part of it shows, as for an element taller than the viewport, which is pictured from its top-left corner.
|
|
247
|
+
- **No picture, and why**: `{ skipped }` with `'no-element'` (no selector, or nothing matches it any more), `'page-level'` (a finding about the whole page, on `<html>`, `<head>` or `<body>`), `'not-rendered'` (such as `display: none`), `'zero-size'`, `'off-screen'` (such as `left: -9999px`), `'max-reached'`, or `'capture-failed'` with the browser's `error`. A failed picture never fails the scan.
|
|
248
|
+
- **The page is put back.** Each element is scrolled into view for its picture, and afterwards every scroll position is restored and the box removed, also when a picture fails. Something drawn over the element, such as a sticky header, shows as it does on screen.
|
|
249
|
+
- **Frames.** With `.frames(true)`, an element in an `<iframe>`, cross-origin ones included, is pictured on the page as it shows there.
|
|
250
|
+
- **Off by default.** Pictures of real pages can hold personal data, and they end up as CI artifacts.
|
|
251
|
+
|
|
252
|
+
The pictures are taken right after each frame's scan, before `.reportOnly()` trims the result, and combine with `.elementRef(true)`. Focus, hover, animations or content that loads late can still differ from what the scan saw. An option it can't use throws a `TypeError` with `code: 'INVALID_ENGINE_OPTIONS'` at the call, and so does `.analyze()` with `options({ output: { includeSelector: false } })`, since each element is found by its selector. Works in Chrome and Firefox.
|
|
253
|
+
|
|
223
254
|
### Web components: the internals hook
|
|
224
255
|
|
|
225
256
|
Many web components keep their `ElementInternals` in a private field and name themselves, set their states or give themselves a role through it:
|
|
@@ -321,6 +352,14 @@ results.engine.profile; // 'en301549-v4.1.1'
|
|
|
321
352
|
|
|
322
353
|
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.
|
|
323
354
|
|
|
355
|
+
Install a published pack in your project, beside core and this package:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
npm install @surea11y/core @surea11y/puppeteer puppeteer @acme/a11y-policy
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Your project, this package and the pack then share one copy of core, so the core that checks the pack is the one that runs it. With two copies, a scan can skip the pack (see "When a pack doesn't run" below).
|
|
362
|
+
|
|
324
363
|
`.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 })`:
|
|
325
364
|
|
|
326
365
|
```js
|
|
@@ -342,7 +381,7 @@ A pack's own rules appear in `checksResults` like core's, with ids that start wi
|
|
|
342
381
|
|
|
343
382
|
**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.
|
|
344
383
|
|
|
345
|
-
**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.
|
|
384
|
+
**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.
|
|
346
385
|
|
|
347
386
|
### Element addressing beyond a CSS selector
|
|
348
387
|
|
|
@@ -374,7 +413,7 @@ try {
|
|
|
374
413
|
|
|
375
414
|
## TypeScript
|
|
376
415
|
|
|
377
|
-
`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`)
|
|
416
|
+
`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)` is typed as a static method. 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.
|
|
378
417
|
|
|
379
418
|
## What changes with `@surea11y/core` 1.12
|
|
380
419
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surea11y/puppeteer",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
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,7 +45,7 @@
|
|
|
45
45
|
"LICENSE"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@surea11y/binding-base": "^1.
|
|
48
|
+
"@surea11y/binding-base": "^1.5.0",
|
|
49
49
|
"@surea11y/core": "^1.12.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
package/src/A11yCoreBuilder.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import type * as Core from '@surea11y/core';
|
|
|
4
4
|
// The result shapes are @surea11y/core's own types (shipped since core
|
|
5
5
|
// 1.9.0, checked there against real scan results), re-exported under the
|
|
6
6
|
// names this file has always used. The binding adds `elementHandle` to an
|
|
7
|
-
// occurrence when .elementRef(true) is used,
|
|
7
|
+
// occurrence when .elementRef(true) is used, `screenshot` when
|
|
8
|
+
// .screenshots() is, and the { topFrame, frames }
|
|
8
9
|
// shape of a .frames(true) scan. See core's docs/OUTPUT_SCHEMA.md for what
|
|
9
10
|
// each field means.
|
|
10
11
|
|
|
@@ -44,9 +45,23 @@ export type {
|
|
|
44
45
|
OccurrenceLocation,
|
|
45
46
|
PackLike,
|
|
46
47
|
WcagVersion,
|
|
47
|
-
WcagLevel
|
|
48
|
+
WcagLevel,
|
|
49
|
+
ScreenshotOptions,
|
|
50
|
+
ScreenshotSkip,
|
|
51
|
+
ScreenshotBox,
|
|
52
|
+
OccurrenceScreenshot
|
|
53
|
+
} from '@surea11y/binding-base';
|
|
54
|
+
import type {
|
|
55
|
+
PackLike,
|
|
56
|
+
WcagVersion,
|
|
57
|
+
WcagLevelInput,
|
|
58
|
+
ScanGap,
|
|
59
|
+
ScanNote,
|
|
60
|
+
PlannedCheck,
|
|
61
|
+
PlannedCriterion,
|
|
62
|
+
ScreenshotOptions,
|
|
63
|
+
OccurrenceScreenshot
|
|
48
64
|
} from '@surea11y/binding-base';
|
|
49
|
-
import type { PackLike, WcagVersion, WcagLevelInput, ScanGap, ScanNote, PlannedCheck, PlannedCriterion } from '@surea11y/binding-base';
|
|
50
65
|
|
|
51
66
|
export type Category = Core.RuleMeta['category'];
|
|
52
67
|
export type LocaleResolutionReason = Core.LocaleResolution['reason'];
|
|
@@ -61,6 +76,12 @@ export interface Occurrence extends Core.Occurrence {
|
|
|
61
76
|
* A11yCoreBuilder#elementRef.
|
|
62
77
|
*/
|
|
63
78
|
elementHandle?: ElementHandle | null;
|
|
79
|
+
/**
|
|
80
|
+
* Only present when `.screenshots()` was used and this occurrence's own
|
|
81
|
+
* outcome is one it pictures: the picture, or why there is none. The
|
|
82
|
+
* occurrences about the same element share one object.
|
|
83
|
+
*/
|
|
84
|
+
screenshot?: OccurrenceScreenshot;
|
|
64
85
|
}
|
|
65
86
|
|
|
66
87
|
export interface CheckResult extends Omit<Core.CheckResult, 'occurrences'> {
|
|
@@ -182,6 +203,13 @@ export class A11yCoreBuilder {
|
|
|
182
203
|
frames(enabled?: boolean): this;
|
|
183
204
|
/** Opt in to resolving each fail/cantTell occurrence's selector to a live ElementHandle. */
|
|
184
205
|
elementRef(enabled?: boolean): this;
|
|
206
|
+
/**
|
|
207
|
+
* Opt in to a picture of each element the scan flags, on its occurrences'
|
|
208
|
+
* `screenshot` field: a Buffer, or a file in `dir`. `false` turns them
|
|
209
|
+
* off. Throws a TypeError with code 'INVALID_ENGINE_OPTIONS' for an option
|
|
210
|
+
* it can't use.
|
|
211
|
+
*/
|
|
212
|
+
screenshots(options?: ScreenshotOptions | boolean): this;
|
|
185
213
|
/** The rules this scan will run, worked out in Node with no page (@surea11y/core 1.12.0 and later). */
|
|
186
214
|
plannedChecks(): PlannedCheck[];
|
|
187
215
|
/** The criteria this scan will report in rulesResults, worked out in Node with no page. */
|
package/src/A11yCoreBuilder.js
CHANGED
|
@@ -82,6 +82,19 @@ const inPageScan = createInPageScan(runa11yCoreInPage);
|
|
|
82
82
|
* const [firstFail] = results.checksResults.filter(r => r.outcome === 'fail');
|
|
83
83
|
* await firstFail.occurrences[0].elementHandle.screenshot({ path: 'flagged.png' });
|
|
84
84
|
*
|
|
85
|
+
* Or let the scan take a picture of each element it flags, with
|
|
86
|
+
* `.screenshots()` (@surea11y/binding-base's, see its README): each
|
|
87
|
+
* occurrence gets a `screenshot` field, the picture (a Buffer, or a file in
|
|
88
|
+
* `dir`) or why there is none. The element is scrolled into view and marked
|
|
89
|
+
* with a box drawn over the page, and the page is put back afterwards; in
|
|
90
|
+
* every frame with `.frames(true)`, including cross-origin ones:
|
|
91
|
+
*
|
|
92
|
+
* const results = await new A11yCoreBuilder({ page })
|
|
93
|
+
* .screenshots({ dir: 'a11y-shots', padding: 16 })
|
|
94
|
+
* .analyze();
|
|
95
|
+
* // results.checksResults[i].occurrences[j].screenshot
|
|
96
|
+
* // -> { path: 'a11y-shots/element-3f9a1c07.png', box: { x, y, width, height } }
|
|
97
|
+
*
|
|
85
98
|
* Register your own rule(s) for just this scan with
|
|
86
99
|
* `.withCustomRules([...])` (@surea11y/core's `engineOptions.customRules`
|
|
87
100
|
* escape hatch -- see ../core/docs/ENGINE_OPTIONS.md). Pass a real,
|
|
@@ -110,8 +123,8 @@ const inPageScan = createInPageScan(runa11yCoreInPage);
|
|
|
110
123
|
* top of the first scan's scope rather than replacing it (intentional for
|
|
111
124
|
* "call include() several times for one scan" -- see above -- but a footgun
|
|
112
125
|
* if you hold one instance across multiple assertions).
|
|
113
|
-
* reportOnly()/frames()/elementRef() are the exception: each
|
|
114
|
-
* the previous value rather than merging with it.
|
|
126
|
+
* reportOnly()/frames()/elementRef()/screenshots() are the exception: each
|
|
127
|
+
* call replaces the previous value rather than merging with it.
|
|
115
128
|
*/
|
|
116
129
|
class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
117
130
|
/**
|
|
@@ -176,6 +189,9 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
176
189
|
await frameOrPage.evaluate(inPageScan, frameUrl, frameContextSelector, engineOptions, runOnly)
|
|
177
190
|
);
|
|
178
191
|
this._warnScanGaps(result, '@surea11y/puppeteer');
|
|
192
|
+
// Right after the frame's scan, before reportOnly(): nothing unless
|
|
193
|
+
// .screenshots() was called.
|
|
194
|
+
if (this._screenshots) await this._screenshotFrame(frameOrPage, result);
|
|
179
195
|
return this._elementRef ? this._attachElementRefs(frameOrPage, result) : result;
|
|
180
196
|
};
|
|
181
197
|
|
|
@@ -223,6 +239,45 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
|
|
|
223
239
|
* Mutates and returns the same result object -- it's a fresh object from
|
|
224
240
|
* this scan, not shared external state.
|
|
225
241
|
*/
|
|
242
|
+
/**
|
|
243
|
+
* binding-base's screenshots step for one scanned frame (or the page),
|
|
244
|
+
* with the <iframe>s leading to it: each frame's frameElement(), a handle
|
|
245
|
+
* in its parent, disposed afterwards.
|
|
246
|
+
*/
|
|
247
|
+
async _screenshotFrame(frameOrPage, result) {
|
|
248
|
+
const framePath = [];
|
|
249
|
+
const parentOf = (f) => (typeof f.parentFrame === 'function' ? f.parentFrame() : null);
|
|
250
|
+
for (let f = frameOrPage; parentOf(f); f = parentOf(f)) {
|
|
251
|
+
// null when the frame detached after its scan: binding-base fails
|
|
252
|
+
// that frame's pictures.
|
|
253
|
+
const iframe = await f.frameElement().catch(() => null);
|
|
254
|
+
framePath.unshift({ frame: parentOf(f), iframe });
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
await this._captureScreenshots(result, frameOrPage, framePath);
|
|
258
|
+
} finally {
|
|
259
|
+
await Promise.all(framePath.map((step) => (step.iframe ? step.iframe.dispose().catch(() => {}) : null)));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** For binding-base's screenshots step: runs `fn(...args)` in the frame. */
|
|
264
|
+
_evaluateInFrame(frameOrPage, fn, args) {
|
|
265
|
+
return frameOrPage.evaluate(fn, ...args);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* For binding-base's screenshots step: a PNG of `box`, CSS pixels in the
|
|
270
|
+
* viewport. Puppeteer's clip is relative to the document, so the box is
|
|
271
|
+
* moved by the page's scroll; captureBeyondViewport: false keeps Chrome
|
|
272
|
+
* from laying the page out again for the picture, as the default would.
|
|
273
|
+
*/
|
|
274
|
+
_captureBox(box, view) {
|
|
275
|
+
return this._page.screenshot({
|
|
276
|
+
clip: { x: box.x + view.scroll.x, y: box.y + view.scroll.y, width: box.width, height: box.height },
|
|
277
|
+
captureBeyondViewport: false
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
226
281
|
async _attachElementRefs(frameOrPage, result) {
|
|
227
282
|
if (!Array.isArray(result.checksResults)) return result;
|
|
228
283
|
for (const check of result.checksResults) {
|