@surea11y/playwright 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 CHANGED
@@ -9,7 +9,7 @@ npm install @surea11y/core @surea11y/playwright playwright
9
9
  npx playwright install chromium # every test launches a real browser -- npm install alone doesn't fetch it
10
10
  ```
11
11
 
12
- `@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
+ `@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.
13
13
 
14
14
  **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.
15
15
 
@@ -39,7 +39,7 @@ await browser.close();
39
39
 
40
40
  `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.
41
41
 
42
- Every result says which `@surea11y/core` release produced it, in `results.engine.version` (for example `"1.12.0"`): quote it in a bug report, and compare it when two runs disagree. From 1.4.0 this package needs `@surea11y/core` 1.12.0 or later; see [What changes with `@surea11y/core` 1.12](#what-changes-with-surea11ycore-112).
42
+ Every result says which `@surea11y/core` release produced it, in `results.engine.version` (for example `"1.12.0"`): quote it in a bug report, and compare it when two runs disagree. From 1.6.0 this package needs `@surea11y/core` 1.15.0 or later, and from 1.5.0 it needed 1.14.0 or later; see [What changes with `@surea11y/core` 1.15](#what-changes-with-surea11ycore-115) and [What changes with `@surea11y/core` 1.14](#what-changes-with-surea11ycore-114).
43
43
 
44
44
  Also see `examples/basic-scan.js` for a runnable script (`npm run example -- <url>`).
45
45
 
@@ -99,7 +99,7 @@ const gaps = getScanGaps(results);
99
99
  // message: 'Nothing was scanned: the scan scope matched no element ("#main").' }]
100
100
  ```
101
101
 
102
- Each gap has a `kind`: `'context-not-found'` (nothing was scanned), `'context-partly-not-found'` (some of several selectors matched nothing), `'custom-rule-skipped'` (a custom rule the engine could not run, one per rule, from `results.skippedCustomRules`; one you excluded yourself with `.disableRules()` is not a gap), or `'pack-skipped'` (a pack that did not run, one per pack, from `results.skippedPacks`; see [Scanning with packs](#scanning-with-packs-standards-checklists-and-your-own-rules)).
102
+ Each gap has a `kind`: `'context-not-found'` (nothing was scanned), `'context-partly-not-found'` (some of several selectors matched nothing), `'custom-rule-skipped'` (a custom rule the engine could not run, one per rule, from `results.skippedCustomRules`; one you excluded yourself with `.disableRules()` is not a gap), `'pack-skipped'` (a pack that did not run, one per pack, from `results.skippedPacks`; see [Scanning with packs](#scanning-with-packs-standards-checklists-and-your-own-rules)), or `'profile-not-run'` (a profile a scan of several did not run, one per profile, from `results.engine.profilesNotRun`; `@surea11y/core` 1.15 and later).
103
103
 
104
104
  `.analyze()` also prints each gap with `console.warn`, once per scanned frame, prefixed with the frame's URL, for example `@surea11y/playwright (https://example.com/): Nothing was scanned: the scan scope matched no element ("#main").` The engine warns too, but in the page's console, which a Playwright run doesn't show. The warning doesn't fail anything: to fail a test on a gap, assert on `getScanGaps(results)` as below.
105
105
 
@@ -159,9 +159,9 @@ test('page has no accessibility violations', async ({ page }) => {
159
159
  });
160
160
  ```
161
161
 
162
- To also fail when the scan left something out (an `.include()` that matched nothing, a custom rule or a pack that didn't run), assert on `getScanGaps(results)` too: `expect(getScanGaps(results), formatFailures(results)).toEqual([])`.
162
+ To also fail when the scan left something out (an `.include()` that matched nothing, a custom rule, a pack or a profile that didn't run), assert on `getScanGaps(results)` too: `expect(getScanGaps(results), formatFailures(results)).toEqual([])`.
163
163
 
164
- See `examples/playwright-test-example.spec.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.
164
+ See `examples/playwright-test-example.spec.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, and one gating a page on a pack's checklist.
165
165
 
166
166
  ### Failing only on serious problems
167
167
 
@@ -209,7 +209,7 @@ for (const frame of results.frames) {
209
209
  }
210
210
  ```
211
211
 
212
- 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 engine support at all — Playwright drives every frame via CDP at the automation-process level, so cross-origin `frame.evaluate()` already just works. Default off, so plain `.analyze()` is unaffected unless you opt in.
212
+ 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 engine support at all — Playwright drives every frame from the automation process, through its own browser protocol, so cross-origin `frame.evaluate()` already just works. Default off, so plain `.analyze()` is unaffected unless you opt in.
213
213
 
214
214
  `results.frames` is a flat list of every sub-frame, however deeply nested. A frame that couldn't be scanned (it detached or navigated away mid-scan, or is sandboxed against scripts) is an entry `{ url, error }` instead of a result, so check for `error` before reading `checksResults`.
215
215
 
@@ -223,7 +223,9 @@ const results = await new A11yCoreBuilder({ page }).frames(true).analyze();
223
223
  fs.writeFileSync('a11y.sarif', renderSarifReport(results));
224
224
  ```
225
225
 
226
- `.include()` scopes the top frame only: each sub-frame is scanned whole, as `@surea11y/core`'s own `runa11yCoreAcrossFrames` does. (A sub-frame rarely holds the element the top frame's selector names, and since core 1.10.0 a selector that matches nothing scans nothing.) `.exclude()` applies in every frame. An `EngineError` (above) rejects the whole scan, since the top frame is scanned first with the same rule and tag lists.
226
+ `.include()` scopes the top frame only: each sub-frame inside its roots is scanned whole, as `@surea11y/core`'s own `runa11yCoreAcrossFrames` does. (A sub-frame rarely holds the element the top frame's selector names, and since core 1.10.0 a selector that matches nothing scans nothing.) `.exclude()` applies in every frame. An `EngineError` (above) rejects the whole scan, since the top frame is scanned first with the same rule and tag lists.
227
+
228
+ 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.
227
229
 
228
230
  ### Trimming the result to just violations
229
231
 
@@ -526,6 +528,24 @@ results.engine.profile; // 'acme-web-2026'
526
528
  results.rulesResults.filter((r) => r.meta && r.meta.standard === 'Acme web policy');
527
529
  ```
528
530
 
531
+ **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)`:
532
+
533
+ ```js
534
+ const waiAria = require('@surea11y/pack-wai-aria');
535
+
536
+ const results = await new A11yCoreBuilder({ page })
537
+ .withPacks(waiAria)
538
+ .options({ profile: ['wcag22-aa', 'wai-aria-1.2'] })
539
+ .analyze();
540
+
541
+ results.engine.profiles; // ['wcag22-aa', 'wai-aria-1.2']
542
+ // A rule both run is one check: its outcome is the worst, and its verdicts
543
+ // say what each profile makes of it.
544
+ results.checksResults.find((c) => c.ruleId === 'aria-allowed-attr').verdicts;
545
+ ```
546
+
547
+ 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.
548
+
529
549
  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.
530
550
 
531
551
  **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/playwright-test-example.spec.js`](./examples/playwright-test-example.spec.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.
@@ -534,7 +554,7 @@ A pack's own rules appear in `checksResults` like core's, with ids that start wi
534
554
 
535
555
  ### Style sheets from another origin
536
556
 
537
- 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 with the page's own request API (so the page's cookies go with them), and gives core their text, which it then checks. It's on by default, as axe fetches such sheets; 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:
557
+ 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 with the page's own request API (so the page's cookies go with them), 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:
538
558
 
539
559
  ```js
540
560
  await new A11yCoreBuilder({ page }).fetchStyleSheets(false).analyze();
@@ -546,7 +566,18 @@ Every occurrence already carries `selector` and (with `.elementRef(true)`, above
546
566
 
547
567
  ## TypeScript
548
568
 
549
- `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 and the result (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result types are built on the ones `@surea11y/core` ships, so they carry every field the engine returns (`engine.version`, `engine.environment`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors`, `margin`, ...); this package adds `elementHandle`, `screenshot` (`OccurrenceScreenshot`) and the `.frames(true)` shape. `EngineError`/`EngineErrorCode`, `getScanGaps()`/`ScanGap`, `getScanNotes()`/`ScanNote` and `formatOccurrenceLocation()` are typed too, and so are `withWcag()` and `wcagLevel()` (`WcagVersion`, `WcagLevelInput`), `plannedChecks()`/`plannedCriteria()` (`PlannedCheck`, `PlannedCriterion`), the static `installInternalsHook()`, `installListenerHook()` and `installLiveRegionHook()` (each taking a `Page` or a `BrowserContext`) and `announcements(page)`, which resolves to `LocatedAnnouncement[] | null`, `formatFailures()`'s review groups (`ReviewGroup`) and `howToCheck` option, `withPacks()`, which takes a pack made with `definePack` (`PackLike`), and `.screenshots()` (`ScreenshotOptions`). 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. `playwright` is a `peerDependencies` entry (not just `devDependencies`) since the class's `page` argument and `Occurrence#elementHandle` both come from it — consumers need their own `playwright` install for the types to resolve, same as they already do to construct a `Page` in the first place.
569
+ `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 and the result (`A11yCoreResult`, `CheckResult`, `Occurrence`, `CompositeResult`, etc.). The result types are built on the ones `@surea11y/core` ships, so they carry every field the engine returns (`engine.version`, `engine.environment`, `contextMatch`, `skippedCustomRules`, `shadowHostSelectors`, `margin`, ...); this package adds `elementHandle`, `screenshot` (`OccurrenceScreenshot`) and the `.frames(true)` shape. `EngineError`/`EngineErrorCode`, `getScanGaps()`/`ScanGap`, `getScanNotes()`/`ScanNote` and `formatOccurrenceLocation()` are typed too, and so are `withWcag()` and `wcagLevel()` (`WcagVersion`, `WcagLevelInput`), `plannedChecks()`/`plannedCriteria()` (`PlannedCheck`, `PlannedCriterion`), the static `installInternalsHook()`, `installListenerHook()` and `installLiveRegionHook()` (each taking a `Page` or a `BrowserContext`) and `announcements(page)`, which resolves to `LocatedAnnouncement[] | null`, `formatFailures()`'s review groups (`ReviewGroup`) and `howToCheck` option, `withPacks()`, which takes a pack made with `definePack` (`PackLike`), and `.screenshots()` (`ScreenshotOptions`). 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. `playwright` is a `peerDependencies` entry (not just `devDependencies`) since the class's `page` argument and `Occurrence#elementHandle` both come from it — consumers need their own `playwright` install for the types to resolve, same as they already do to construct a `Page` in the first place.
570
+
571
+ ## What changes with `@surea11y/core` 1.15
572
+
573
+ 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):
574
+
575
+ - **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.
576
+ - **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)).
577
+ - **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)).
578
+ - **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)).
579
+ - **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.
580
+ - **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`.
550
581
 
551
582
  ## What changes with `@surea11y/core` 1.14
552
583
 
@@ -565,7 +596,7 @@ With `@surea11y/core` 1.14.0, what a scan through this binding shows differently
565
596
 
566
597
  ## What changes with `@surea11y/core` 1.12
567
598
 
568
- This release 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):
599
+ 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):
569
600
 
570
601
  - **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.
571
602
  - **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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surea11y/playwright",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Accessibility (a11y, WCAG) checks for Playwright 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",
@@ -46,8 +46,8 @@
46
46
  "LICENSE"
47
47
  ],
48
48
  "dependencies": {
49
- "@surea11y/binding-base": "^1.6.0",
50
- "@surea11y/core": "^1.14.0"
49
+ "@surea11y/binding-base": "^1.7.0",
50
+ "@surea11y/core": "^1.15.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "playwright": ">=1.0.0"
@@ -211,7 +211,7 @@ export class A11yCoreBuilder {
211
211
  withTags(tags: string | string[]): this;
212
212
  /** Never run rules carrying any of these tags (applied after withTags). */
213
213
  disableTags(tags: string | string[]): this;
214
- /** Only run these specific rule IDs (accepts with or without the prefix). */
214
+ /** Only run these specific rule IDs (accepts with or without the `a11ycore-` prefix). */
215
215
  withRules(ruleIds: string | string[]): this;
216
216
  /** Never run these specific rule IDs (applied after withRules). */
217
217
  disableRules(ruleIds: string | string[]): this;
@@ -335,8 +335,9 @@ export function getGatingFailures(
335
335
  * pass over as clean: an include() scope that matched no element
336
336
  * (`context-not-found`, nothing was scanned), some include() selectors that
337
337
  * matched nothing (`context-partly-not-found`), each custom rule that did
338
- * not run (`custom-rule-skipped`), and each pack that did not run
339
- * (`pack-skipped`). Each gap has a `message`. Throws a
338
+ * not run (`custom-rule-skipped`), each pack that did not run
339
+ * (`pack-skipped`), and each profile a scan of several did not run
340
+ * (`profile-not-run`). Each gap has a `message`. Throws a
340
341
  * TypeError for a frames(true) result: call it on `topFrame` and on each
341
342
  * scanned frame.
342
343
  */
@@ -347,8 +348,10 @@ export type { ScanGap, OccurrenceLocation } from '@surea11y/binding-base';
347
348
  * How the page was scanned, which a gap doesn't cover: `forced-colors` when
348
349
  * the page was shown in forced colors, `internals-hook` when the scan
349
350
  * asked about web components it could have read with the internals hook,
350
- * and `listener-hook` when it asked about click or pointer handlers whose
351
- * keyboard equivalent the listener hook would have let it see.
351
+ * `listener-hook` when it asked about click or pointer handlers whose
352
+ * keyboard equivalent the listener hook would have let it see, and
353
+ * `live-region-hook` when it judged live regions the live-region hook would
354
+ * have let it see.
352
355
  */
353
356
  export { getScanNotes } from '@surea11y/binding-base';
354
357
  export type { ScanNote } from '@surea11y/binding-base';
@@ -3,12 +3,24 @@
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
- } = require('@surea11y/binding-base');
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
  // Playwright's page.evaluate(fn, arg) (and frame.evaluate(fn, arg), same
14
26
  // signature) only accepts ONE arg value -- page.evaluate(fn, a, b, c, d)
@@ -82,10 +94,11 @@ const findOccurrenceElement = eval(`(args) => {
82
94
  * // results.topFrame -- same shape as the single-frame case above
83
95
  * // results.frames -- array of the same native result shape, one per sub-frame
84
96
  *
85
- * include() scopes the top frame only; every sub-frame is scanned whole.
97
+ * include() scopes the top frame only; every sub-frame inside its roots is
98
+ * scanned whole, and a hidden, excluded or empty frame is left out.
86
99
  *
87
100
  * Unlike script-injection-based accessibility engines (which need a
88
- * postMessage-based protocol, runPartial/finishRun, to reach cross-origin
101
+ * postMessage-based protocol to reach cross-origin
89
102
  * iframes, since they're injected as a plain <script> and are fully subject
90
103
  * to the browser's same-origin policy), this doesn't need any @surea11y/core
91
104
  * engine support: Playwright
@@ -257,19 +270,23 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
257
270
 
258
271
  // A Playwright Page and a Frame both expose the same .evaluate(fn, arg)
259
272
  // and .url() shape, so this works unchanged for either.
260
- const runInFrame = async (frameOrPage, frameContextSelector) => {
261
- const frameUrl = this._url || (typeof frameOrPage.url === 'function' ? frameOrPage.url() : null);
273
+ // url() names the top page only; a frame is named by its own address.
274
+ const top = this._page.mainFrame ? this._page.mainFrame() : null;
275
+ const runInFrame = async (frameOrPage, frameContextSelector, frameOptions = engineOptions) => {
276
+ const isTop = frameOrPage === this._page || frameOrPage === top;
277
+ const ownUrl = typeof frameOrPage.url === 'function' ? frameOrPage.url() : null;
278
+ const frameUrl = isTop ? this._url || ownUrl : ownUrl;
262
279
  if (packScript) await frameOrPage.evaluate(packScript);
263
280
  // The text of the style sheets the frame can't read, fetched from Node
264
281
  // (binding-base 1.6.0 and core 1.14.0; nothing with older ones).
265
- const frameEngineOptions =
282
+ const scanOptions =
266
283
  typeof this._styleSheetEngineOptions === 'function'
267
- ? await this._styleSheetEngineOptions(frameOrPage, engineOptions)
268
- : engineOptions;
284
+ ? await this._styleSheetEngineOptions(frameOrPage, frameOptions)
285
+ : frameOptions;
269
286
  const result = rethrowEngineError(await frameOrPage.evaluate(scanInPage, {
270
287
  url: frameUrl,
271
288
  contextSelector: frameContextSelector,
272
- engineOptions: frameEngineOptions,
289
+ engineOptions: scanOptions,
273
290
  runOnly
274
291
  }));
275
292
  this._warnScanGaps(result, '@surea11y/playwright');
@@ -304,10 +321,22 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
304
321
  // passing the top frame's selector on would leave out every frame that
305
322
  // doesn't happen to contain the same element (before 1.10.0 such a frame
306
323
  // was silently scanned whole). exclude() still applies in every frame.
324
+ // Each frame read as core's own scan across frames reads it
325
+ // (binding-base's frames helpers, 1.7 and later): one the page doesn't
326
+ // show, that is excluded or outside include()'s roots, or that shows
327
+ // nothing is left out; one under aria-hidden is scanned as aria-hidden.
328
+ // A frame inside one inherits how it is read.
329
+ const readings = new Map();
330
+ const readingOf = (frame) => {
331
+ if (!readings.has(frame)) readings.set(frame, this._readFrame(frame, mainFrame, readingOf, engineOptions, contextSelector));
332
+ return readings.get(frame);
333
+ };
307
334
  const frames = [];
308
335
  for (const frame of subFrames) {
309
336
  try {
310
- frames.push(this._applyReportOnly(await runInFrame(frame, null)));
337
+ const reading = await readingOf(frame);
338
+ if (reading.skipped) continue;
339
+ frames.push(this._applyReportOnly(await runInFrame(frame, null, frameEngineOptions(engineOptions, reading))));
311
340
  } catch (e) {
312
341
  // A frame can detach/navigate away mid-scan, or be a sandboxed
313
342
  // frame the browser blocks scripting in -- don't let one bad frame
@@ -322,6 +351,29 @@ class A11yCoreBuilder extends A11yCoreBuilderBase {
322
351
  return { topFrame, frames };
323
352
  }
324
353
 
354
+ /**
355
+ * How a sub-frame is read: `{ skipped }`, `{ ariaHidden }` or `{}`, from
356
+ * its element in its parent frame and its own document, as core's scan
357
+ * across frames reads it. Without binding-base's frames helpers, every
358
+ * frame is scanned as before.
359
+ */
360
+ async _readFrame(frame, mainFrame, readingOf, engineOptions, contextSelector) {
361
+ if (typeof readFrameElement !== 'function') return {};
362
+ const parent = frame.parentFrame && frame.parentFrame();
363
+ const above = parent && parent !== mainFrame ? await readingOf(parent) : {};
364
+ if (above.skipped) return above;
365
+ let own = {};
366
+ try {
367
+ const handle = await frame.frameElement();
368
+ own = await handle.evaluate(readFrameElement, frameReadingOptions(engineOptions, contextSelector, parent === mainFrame));
369
+ await handle.dispose().catch(() => {});
370
+ if (!own.skipped && (await frame.evaluate(isFrameDocumentEmpty))) own = { skipped: 'empty' };
371
+ } catch (e) {
372
+ own = {};
373
+ }
374
+ return own.skipped ? own : inheritFrameReading(above, own);
375
+ }
376
+
325
377
  /**
326
378
  * The driver steps .conditions() scans need: the viewport's width with
327
379
  * page.setViewportSize() (its height kept) and the color scheme with