@a11y-pulse/browser-adaptor 0.8.0 → 0.10.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 +25 -5
- package/dist/adaptor.d.ts +15 -1
- package/dist/adaptors/playwright.d.ts +24 -0
- package/dist/adaptors/playwright.js +85 -7
- package/dist/adaptors/playwright.js.map +1 -1
- package/dist/adaptors/puppeteer.d.ts +17 -0
- package/dist/adaptors/puppeteer.js +78 -2
- package/dist/adaptors/puppeteer.js.map +1 -1
- package/dist/chunk-GRS3X3VZ.js +198 -0
- package/dist/chunk-GRS3X3VZ.js.map +1 -0
- package/dist/{chunk-QUDMCLZ7.js → chunk-M2OOSZU3.js} +2 -1
- package/dist/chunk-M2OOSZU3.js.map +1 -0
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +76 -7
- package/dist/dom.js.map +1 -1
- package/dist/element-screenshot.d.ts +39 -0
- package/dist/get-selector.d.ts +12 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +90 -3
- package/dist/index.js.map +1 -1
- package/dist/stashed-elements.d.ts +6 -1
- package/dist/truncate-html.d.ts +4 -0
- package/package.json +5 -5
- package/dist/chunk-QUDMCLZ7.js.map +0 -1
- package/dist/chunk-WI4RV7YK.js +0 -143
- package/dist/chunk-WI4RV7YK.js.map +0 -1
package/README.md
CHANGED
|
@@ -20,10 +20,10 @@ npm install @a11y-pulse/browser-adaptor
|
|
|
20
20
|
|
|
21
21
|
| Entry | Contents |
|
|
22
22
|
| --- | --- |
|
|
23
|
-
| `@a11y-pulse/browser-adaptor` | `BrowserAdaptor`, `ElementRef`, `Rect`, `bufferedClip`, `contrastRatio`, `parseOpaqueRgb`, `relativeLuminance`, `stashedElementSelectors`, `releaseStashedElements` |
|
|
23
|
+
| `@a11y-pulse/browser-adaptor` | `BrowserAdaptor`, `ElementRef`, `Rect`, `bufferedClip`, `captureElementScreenshot`, `contrastRatio`, `parseOpaqueRgb`, `relativeLuminance`, `stashedElementHandle`, `stashedElementSelectors`, `releaseStashedElements`, and the page scripts `captureElementScreenshot` is built on |
|
|
24
24
|
| `@a11y-pulse/browser-adaptor/puppeteer` | `PuppeteerAdaptor` |
|
|
25
25
|
| `@a11y-pulse/browser-adaptor/playwright` | `PlaywrightAdaptor` |
|
|
26
|
-
| `@a11y-pulse/browser-adaptor/dom` | `getSelector`, `truncateHtml` |
|
|
26
|
+
| `@a11y-pulse/browser-adaptor/dom` | `getSelector`, `resolveSelector`, `truncateHtml` |
|
|
27
27
|
|
|
28
28
|
## Quickstart
|
|
29
29
|
|
|
@@ -56,11 +56,25 @@ interface BrowserAdaptor {
|
|
|
56
56
|
screenshotClip(clip: Rect, scale?: number): Promise<Uint8Array>;
|
|
57
57
|
readonly screenshotClipScale?: number;
|
|
58
58
|
ensureFocusReporting(): Promise<void>; // must not throw
|
|
59
|
+
takeDismissedDialogs?(): number; // optional
|
|
60
|
+
startDismissingDialogs?(): () => void; // optional
|
|
59
61
|
}
|
|
60
62
|
```
|
|
61
63
|
|
|
62
64
|
Consumers may ignore methods they do not need. `ensureFocusReporting` is best-effort and must not throw.
|
|
63
65
|
|
|
66
|
+
**Native dialogs.** An `alert`, `confirm`, `prompt` or `beforeunload` dialog blocks the page's scripts until something answers it, so a page that raises one from a focus handler would hang every later call. An adaptor should dismiss the dialogs an audit raises, and can report how many it has dismissed since the last call through the optional `takeDismissedDialogs`.
|
|
67
|
+
|
|
68
|
+
Both bundled adaptors take a `dismissDialogs` option:
|
|
69
|
+
|
|
70
|
+
| Value | When dialogs are dismissed |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `true` (default) | Only while something holds `startDismissingDialogs()`, which returns the function that stops it. A tab session holds it for as long as it runs. The rest of the time the adaptor answers nothing, so your own handler works as it would without the adaptor. A dialog that was already open when dismissing starts is closed too, so one raised earlier cannot hang a session: the Puppeteer adaptor keeps a `dialog` listener that only remembers the last dialog for this, and Playwright dismisses a dialog nothing listens for by itself. |
|
|
73
|
+
| `"always"` | From construction, for the page's lifetime. Use it when you hand the whole page over and run audits that do not tab through it (the audit runner does). |
|
|
74
|
+
| `false` | Never. You handle `dialog` events yourself. |
|
|
75
|
+
|
|
76
|
+
While it is dismissing, the adaptor answers a dialog only after every other `dialog` listener has been called, so a listener of yours that accepts or dismisses the dialog as it is raised still gets to. One that answers later, after an `await`, will find the dialog already dismissed.
|
|
77
|
+
|
|
64
78
|
## Puppeteer adaptor
|
|
65
79
|
|
|
66
80
|
`PuppeteerAdaptor` wraps a Puppeteer `Page`. Its CDP session is cached per page, so reusing a page across audit runs does not open extra sessions.
|
|
@@ -92,7 +106,7 @@ await browser.close();
|
|
|
92
106
|
|
|
93
107
|
Two differences from the Puppeteer adaptor are worth knowing about.
|
|
94
108
|
|
|
95
|
-
**`evaluate`
|
|
109
|
+
**`evaluate` and Content-Security-Policy.** Playwright's `evaluate` takes a single argument, so the adaptor packs the page function's source and its arguments into one tuple and rebuilds the function in the page with `new Function`. Where a page's Content-Security-Policy or Trusted Types policy refuses that, the adaptor falls back to having Playwright build the function through the protocol and calling it by handle, at the cost of two more round trips per call. Only if that is refused as well does it throw, with a message naming CSP as the cause rather than letting it read as a page failure. Puppeteer is unaffected, because CDP serialises the function itself.
|
|
96
110
|
|
|
97
111
|
**Screenshot scale depends on the engine.** On Chromium the adaptor screenshots over CDP, which honours `screenshotClipScale` per capture, so evidence images match Puppeteer's; it takes the same `captureBeyondViewport` option, off by default for the same reason. Firefox and WebKit expose no CDP, so the adaptor falls back to a full-page capture at the context's own `deviceScaleFactor`, which those engines take without resizing the viewport. There, create the context with a `deviceScaleFactor` matching `screenshotClipScale` (2 by default), or pass the scale you want:
|
|
98
112
|
|
|
@@ -106,9 +120,11 @@ new PlaywrightAdaptor(page, { screenshotClipScale: 1 });
|
|
|
106
120
|
import { getSelector, truncateHtml } from "@a11y-pulse/browser-adaptor/dom";
|
|
107
121
|
```
|
|
108
122
|
|
|
109
|
-
`getSelector` builds a compact selector for an element (intended to run in page context). `
|
|
123
|
+
`getSelector` builds a compact selector for an element (intended to run in page context). For an element inside an open shadow root it lists each host first, joined by ` >>> `, as in `site-footer >>> a.link`. That is deliberately not valid CSS: `document.querySelector` throws on it rather than resolving the inner part to a look-alike in the light DOM. `resolveSelector` (also a page-context function) turns any `getSelector` result back into its element, or `null`.
|
|
124
|
+
|
|
125
|
+
`truncateHtml` shortens an element's markup to its opening tag for display in results. It finds the end of the tag even when an attribute value contains a `>`, shortens long attribute values without cutting through a character reference or a surrogate pair, cuts `data:` URIs back to their media type, and replaces the `value` of a text-entry `<input>` with `[redacted]`, since that can hold whatever the page was pre-filled with for the person using it. Values that are labels or fixed choices (`submit`, `button`, `radio`, `checkbox` and the like) are kept.
|
|
110
126
|
|
|
111
|
-
A page script that collects many elements in one evaluate can leave them on `window` under a key of its own, then fetch selectors for only the ones it reports:
|
|
127
|
+
A page script that collects many elements in one evaluate can leave them on `window` under a key of its own, then fetch selectors (or, with `stashedElementHandle`, a handle) for only the ones it reports:
|
|
112
128
|
|
|
113
129
|
```js
|
|
114
130
|
import { releaseStashedElements, stashedElementSelectors } from "@a11y-pulse/browser-adaptor";
|
|
@@ -122,6 +138,10 @@ try {
|
|
|
122
138
|
}
|
|
123
139
|
```
|
|
124
140
|
|
|
141
|
+
## Element screenshots
|
|
142
|
+
|
|
143
|
+
`captureElementScreenshot(adaptor, handle, { clipBuffer, settleDelay })` screenshots an element clipped to its box plus `clipBuffer` padding. It first centres the element in the viewport if the clip would not fit there or something covers the element's centre, then waits `settleDelay` ms. The caller owns `handle`, and restores the scroll position if that matters.
|
|
144
|
+
|
|
125
145
|
## License
|
|
126
146
|
|
|
127
147
|
[MIT](./LICENSE.md). Use it however you like, including in commercial and competing products.
|
package/dist/adaptor.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type Rect = {
|
|
|
6
6
|
height: number;
|
|
7
7
|
};
|
|
8
8
|
/** A key, or a modifier and a key joined by `+`, as the adaptor's `pressKey` accepts it. */
|
|
9
|
-
export type KeyName = "Tab" | "Shift+Tab" | "Enter" | "Escape" | "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight";
|
|
9
|
+
export type KeyName = "Tab" | "Shift+Tab" | "Enter" | "Space" | "Escape" | "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight";
|
|
10
10
|
/**
|
|
11
11
|
* An element handle in the page. This type is adaptor-specific and is opaque to the audit.
|
|
12
12
|
*/
|
|
@@ -58,4 +58,18 @@ export interface BrowserAdaptor {
|
|
|
58
58
|
* This function must not throw.
|
|
59
59
|
*/
|
|
60
60
|
ensureFocusReporting(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* How many native dialogs (`alert`, `confirm`, `prompt`, `beforeunload`) the adaptor has dismissed
|
|
63
|
+
* since this was last called. A dialog blocks the page's scripts until it is answered, so an
|
|
64
|
+
* adaptor has to dismiss them itself or a page that raises one hangs the audit. Optional: an
|
|
65
|
+
* adaptor without it is taken to report none.
|
|
66
|
+
*/
|
|
67
|
+
takeDismissedDialogs?(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Dismiss native dialogs from now until the returned function is called. A tab session holds this
|
|
70
|
+
* for as long as it runs, so the adaptor need not interfere with the page's dialogs, or with a
|
|
71
|
+
* caller's own handling of them, the rest of the time. Optional: an adaptor without it is taken
|
|
72
|
+
* to deal with dialogs by itself.
|
|
73
|
+
*/
|
|
74
|
+
startDismissingDialogs?(): () => void;
|
|
61
75
|
}
|
|
@@ -17,14 +17,38 @@ export type PlaywrightAdaptorOptions = {
|
|
|
17
17
|
* page without resizing the viewport, so they ignore this.
|
|
18
18
|
*/
|
|
19
19
|
captureBeyondViewport?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to dismiss native dialogs (`alert`, `confirm`, `prompt`, `beforeunload`), and count
|
|
22
|
+
* them. Playwright dismisses dialogs by itself only while nothing listens for them, and then
|
|
23
|
+
* nothing records that one appeared.
|
|
24
|
+
*
|
|
25
|
+
* - `true`, the default: only while something has asked for it through `startDismissingDialogs`,
|
|
26
|
+
* which a tab session does for as long as it runs. Outside that the page's dialogs are the
|
|
27
|
+
* caller's to handle, and inside it a `dialog` listener of the caller's that answers a dialog
|
|
28
|
+
* as it is raised still gets to.
|
|
29
|
+
* - `"always"`: from construction, for the page's lifetime. For a caller that hands the whole
|
|
30
|
+
* page over, such as the audit runner.
|
|
31
|
+
* - `false`: never. The caller handles `dialog` events itself.
|
|
32
|
+
*/
|
|
33
|
+
dismissDialogs?: boolean | "always";
|
|
20
34
|
};
|
|
21
35
|
/** A BrowserAdaptor backed by a Playwright Page. */
|
|
22
36
|
export declare class PlaywrightAdaptor implements BrowserAdaptor {
|
|
23
37
|
private readonly page;
|
|
24
38
|
readonly screenshotClipScale: number;
|
|
25
39
|
private readonly captureBeyondViewport;
|
|
40
|
+
private readonly dismissDialogs;
|
|
26
41
|
constructor(page: Page, options?: PlaywrightAdaptorOptions);
|
|
42
|
+
startDismissingDialogs(): () => void;
|
|
43
|
+
takeDismissedDialogs(): number;
|
|
27
44
|
evaluate<T>(fn: (...args: any[]) => T | Promise<T>, ...args: unknown[]): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* The route for pages whose Content-Security-Policy forbids `new Function()`: Playwright itself
|
|
47
|
+
* turns the source into a function, through the protocol rather than in page script, and the
|
|
48
|
+
* function is then called by handle. It costs two more round trips than the packed call, so it
|
|
49
|
+
* is only taken once that one has been refused.
|
|
50
|
+
*/
|
|
51
|
+
private evaluateWithoutEval;
|
|
28
52
|
evaluateHandle(fn: () => Element | null): Promise<ElementRef>;
|
|
29
53
|
disposeRef(ref: ElementRef): Promise<void>;
|
|
30
54
|
pressTab(): Promise<void>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nextPaintScript
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-M2OOSZU3.js";
|
|
4
4
|
|
|
5
5
|
// src/adaptors/playwright.ts
|
|
6
6
|
var cdpSessions = /* @__PURE__ */ new WeakMap();
|
|
7
7
|
var focusEmulatedPages = /* @__PURE__ */ new WeakSet();
|
|
8
|
+
var dialogStates = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
var DEFAULT_SCREENSHOT_CLIP_SCALE = 2;
|
|
9
|
-
var EVAL_BLOCKED = /EvalError|unsafe-eval|Content Security Policy/i;
|
|
10
|
+
var EVAL_BLOCKED = /EvalError|unsafe-eval|Content Security Policy|Trusted ?Type|TrustedScript/i;
|
|
10
11
|
function cdpSession(page) {
|
|
11
12
|
const existing = cdpSessions.get(page);
|
|
12
13
|
if (existing) {
|
|
@@ -23,15 +24,66 @@ function isChromium(page) {
|
|
|
23
24
|
return false;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
27
|
+
function dismissDialogsOn(page) {
|
|
28
|
+
if (typeof page.on !== "function") {
|
|
29
|
+
return () => {
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
let state = dialogStates.get(page);
|
|
33
|
+
if (state === void 0) {
|
|
34
|
+
state = { count: 0, holds: 0, listener: null };
|
|
35
|
+
dialogStates.set(page, state);
|
|
36
|
+
}
|
|
37
|
+
const held = state;
|
|
38
|
+
if (held.holds++ === 0) {
|
|
39
|
+
const listener = (dialog) => {
|
|
40
|
+
held.count++;
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
dialog.dismiss().catch(() => {
|
|
43
|
+
});
|
|
44
|
+
}, 0);
|
|
45
|
+
};
|
|
46
|
+
held.listener = listener;
|
|
47
|
+
page.on("dialog", listener);
|
|
48
|
+
}
|
|
49
|
+
let released = false;
|
|
50
|
+
return () => {
|
|
51
|
+
if (released) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
released = true;
|
|
55
|
+
if (--held.holds === 0 && held.listener !== null) {
|
|
56
|
+
page.off("dialog", held.listener);
|
|
57
|
+
held.listener = null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
26
61
|
var PlaywrightAdaptor = class {
|
|
27
62
|
constructor(page, options = {}) {
|
|
28
63
|
this.page = page;
|
|
29
64
|
this.screenshotClipScale = options.screenshotClipScale ?? DEFAULT_SCREENSHOT_CLIP_SCALE;
|
|
30
65
|
this.captureBeyondViewport = options.captureBeyondViewport ?? false;
|
|
66
|
+
this.dismissDialogs = options.dismissDialogs ?? true;
|
|
67
|
+
if (this.dismissDialogs === "always") {
|
|
68
|
+
dismissDialogsOn(page);
|
|
69
|
+
}
|
|
31
70
|
}
|
|
32
71
|
page;
|
|
33
72
|
screenshotClipScale;
|
|
34
73
|
captureBeyondViewport;
|
|
74
|
+
dismissDialogs;
|
|
75
|
+
startDismissingDialogs() {
|
|
76
|
+
return this.dismissDialogs === false ? () => {
|
|
77
|
+
} : dismissDialogsOn(this.page);
|
|
78
|
+
}
|
|
79
|
+
takeDismissedDialogs() {
|
|
80
|
+
const state = dialogStates.get(this.page);
|
|
81
|
+
const count = state?.count ?? 0;
|
|
82
|
+
if (state) {
|
|
83
|
+
state.count = 0;
|
|
84
|
+
}
|
|
85
|
+
return count;
|
|
86
|
+
}
|
|
35
87
|
async evaluate(fn, ...args) {
|
|
36
88
|
try {
|
|
37
89
|
return await this.page.evaluate(
|
|
@@ -40,13 +92,39 @@ var PlaywrightAdaptor = class {
|
|
|
40
92
|
);
|
|
41
93
|
} catch (error) {
|
|
42
94
|
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
-
if (EVAL_BLOCKED.test(message)) {
|
|
95
|
+
if (!EVAL_BLOCKED.test(message)) {
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
return await this.evaluateWithoutEval(fn, args);
|
|
100
|
+
} catch (fallbackError) {
|
|
101
|
+
const fallbackMessage = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
102
|
+
if (!EVAL_BLOCKED.test(fallbackMessage)) {
|
|
103
|
+
throw fallbackError;
|
|
104
|
+
}
|
|
44
105
|
throw new Error(
|
|
45
|
-
"
|
|
46
|
-
{ cause:
|
|
106
|
+
"This page's Content-Security-Policy blocks the Playwright adaptor from building page functions. Allow 'unsafe-eval' in script-src, or use the Puppeteer adaptor.",
|
|
107
|
+
{ cause: fallbackError }
|
|
47
108
|
);
|
|
48
109
|
}
|
|
49
|
-
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The route for pages whose Content-Security-Policy forbids `new Function()`: Playwright itself
|
|
114
|
+
* turns the source into a function, through the protocol rather than in page script, and the
|
|
115
|
+
* function is then called by handle. It costs two more round trips than the packed call, so it
|
|
116
|
+
* is only taken once that one has been refused.
|
|
117
|
+
*/
|
|
118
|
+
async evaluateWithoutEval(fn, args) {
|
|
119
|
+
const handle = await this.page.evaluateHandle(`(${fn.toString()})`);
|
|
120
|
+
try {
|
|
121
|
+
return await handle.evaluate(
|
|
122
|
+
(pageFn, packed) => pageFn(...packed),
|
|
123
|
+
args
|
|
124
|
+
);
|
|
125
|
+
} finally {
|
|
126
|
+
await handle.dispose().catch(() => {
|
|
127
|
+
});
|
|
50
128
|
}
|
|
51
129
|
}
|
|
52
130
|
evaluateHandle(fn) {
|
|
@@ -65,7 +143,6 @@ var PlaywrightAdaptor = class {
|
|
|
65
143
|
await this.page.keyboard.press(key);
|
|
66
144
|
}
|
|
67
145
|
async screenshotClip(clip, scale = 1) {
|
|
68
|
-
await this.page.evaluate(nextPaintScript);
|
|
69
146
|
const session = await cdpSession(this.page);
|
|
70
147
|
if (session) {
|
|
71
148
|
const { data } = await session.send("Page.captureScreenshot", {
|
|
@@ -75,6 +152,7 @@ var PlaywrightAdaptor = class {
|
|
|
75
152
|
});
|
|
76
153
|
return Buffer.from(data, "base64");
|
|
77
154
|
}
|
|
155
|
+
await this.page.evaluate(nextPaintScript);
|
|
78
156
|
return await this.page.screenshot({
|
|
79
157
|
type: "png",
|
|
80
158
|
fullPage: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adaptors/playwright.ts"],"sourcesContent":["import type { CDPSession, JSHandle, Page } from \"playwright-core\";\nimport type { BrowserAdaptor, ElementRef, KeyName, Rect } from \"../adaptor\";\nimport { nextPaintScript } from \"../paint\";\n\n// The CDP session for each page, shared by focus emulation and clipped screenshots. A fresh adaptor\n// is created per audit run, but a page often outlives one run, so without this each run would open\n// another session that is never detached. The session is kept attached for the page's lifetime:\n// Chrome clears focus emulation when the CDP client disconnects. Resolves to null on Firefox and\n// WebKit, where Playwright offers no CDP.\nconst cdpSessions = new WeakMap<Page, Promise<CDPSession | null>>();\n\n// Pages that have had focus emulation enabled at least once.\nconst focusEmulatedPages = new WeakSet<Page>();\n\nconst DEFAULT_SCREENSHOT_CLIP_SCALE = 2;\n\nconst EVAL_BLOCKED = /EvalError|unsafe-eval|Content Security Policy/i;\n\nfunction cdpSession(page: Page): Promise<CDPSession | null> {\n\tconst existing = cdpSessions.get(page);\n\n\tif (existing) {\n\t\treturn existing;\n\t}\n\n\tconst session = page\n\t\t.context()\n\t\t.newCDPSession(page)\n\t\t.catch(() => null);\n\tcdpSessions.set(page, session);\n\n\treturn session;\n}\n\nfunction isChromium(page: Page): boolean {\n\ttry {\n\t\treturn page.context().browser()?.browserType().name() === \"chromium\";\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport type PlaywrightAdaptorOptions = {\n\t/**\n\t * Device scale factor for evidence screenshots. Defaults to 2. On Chromium any value is honoured\n\t * per capture. Elsewhere this must match the `deviceScaleFactor` the browser context was created\n\t * with, because Playwright's public screenshot API cannot rescale a single capture.\n\t */\n\tscreenshotClipScale?: number;\n\n\t/**\n\t * Let a Chromium clip capture content outside the current viewport. Defaults to false: to honour\n\t * it Chromium shrinks the emulated viewport to 1x1 and then resizes it for the clip before\n\t * restoring it, and the page observes each of those as a real resize (`resize` fires, media\n\t * queries flip to their narrowest breakpoint), which can collapse a responsive layout and blur\n\t * the focused element mid-capture. Only enable it for evidence of regions the caller cannot\n\t * scroll into view, where the page's state does not matter. Firefox and WebKit capture the full\n\t * page without resizing the viewport, so they ignore this.\n\t */\n\tcaptureBeyondViewport?: boolean;\n};\n\n/** A BrowserAdaptor backed by a Playwright Page. */\nexport class PlaywrightAdaptor implements BrowserAdaptor {\n\treadonly screenshotClipScale: number;\n\n\tprivate readonly captureBeyondViewport: boolean;\n\n\tconstructor(\n\t\tprivate readonly page: Page,\n\t\toptions: PlaywrightAdaptorOptions = {},\n\t) {\n\t\tthis.screenshotClipScale = options.screenshotClipScale ?? DEFAULT_SCREENSHOT_CLIP_SCALE;\n\t\tthis.captureBeyondViewport = options.captureBeyondViewport ?? false;\n\t}\n\n\tasync evaluate<T>(\n\t\t// biome-ignore lint/suspicious/noExplicitAny: the page-evaluated fn accepts arbitrary serialised args and element handles.\n\t\tfn: (...args: any[]) => T | Promise<T>,\n\t\t...args: unknown[]\n\t): Promise<T> {\n\t\ttry {\n\t\t\t// Playwright takes a single argument, so the function source and its args travel packed\n\t\t\t// into one tuple. Handles nested in that tuple are still resolved to live elements.\n\t\t\treturn (await this.page.evaluate(\n\t\t\t\t([source, packed]) => new Function(`return (${source})`)()(...(packed as unknown[])),\n\t\t\t\t[fn.toString(), args] as [string, unknown[]],\n\t\t\t)) as T;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\n\t\t\tif (EVAL_BLOCKED.test(message)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"The Playwright adaptor rebuilds page functions with new Function(), which this page's Content-Security-Policy blocks. Allow 'unsafe-eval' in script-src, or use the Puppeteer adaptor.\",\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tevaluateHandle(fn: () => Element | null): Promise<ElementRef> {\n\t\treturn this.page.evaluateHandle(fn);\n\t}\n\n\tasync disposeRef(ref: ElementRef): Promise<void> {\n\t\tawait (ref as JSHandle).dispose();\n\t}\n\n\tasync pressTab(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Tab\");\n\t}\n\n\tasync pressEnter(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Enter\");\n\t}\n\n\tasync pressKey(key: KeyName): Promise<void> {\n\t\tawait this.page.keyboard.press(key);\n\t}\n\n\tasync screenshotClip(clip: Rect, scale = 1): Promise<Uint8Array> {\n\t\tawait this.page.evaluate(nextPaintScript);\n\n\t\tconst session = await cdpSession(this.page);\n\n\t\tif (session) {\n\t\t\t// The public API cannot scale one capture, and its `clip` is only honoured inside the\n\t\t\t// viewport. CDP is what Puppeteer drives too, so evidence images stay pixel-comparable.\n\t\t\t//\n\t\t\t// `captureBeyondViewport: false` ensures that Chromium does not resize the viewport before\n\t\t\t// capturing the screenshot, which can trigger media queries and hide the element we are\n\t\t\t// trying to capture.\n\t\t\tconst { data } = await session.send(\"Page.captureScreenshot\", {\n\t\t\t\tformat: \"png\",\n\t\t\t\tcaptureBeyondViewport: this.captureBeyondViewport,\n\t\t\t\tclip: { ...clip, scale },\n\t\t\t});\n\n\t\t\treturn Buffer.from(data, \"base64\");\n\t\t}\n\n\t\t// Clips are document coordinates, and Playwright renders anything outside the viewport blank\n\t\t// unless the capture is full-page. Firefox and WebKit capture a full page without resizing\n\t\t// the viewport, so the page does not observe this.\n\t\treturn (await this.page.screenshot({\n\t\t\ttype: \"png\",\n\t\t\tfullPage: true,\n\t\t\tclip,\n\t\t\tscale: \"device\",\n\t\t})) as Uint8Array;\n\t}\n\n\tasync ensureFocusReporting(): Promise<void> {\n\t\t// Pages only report focus while they are the foreground tab. Since this browser instance is\n\t\t// likely running in the background, we need to enable focus emulation to get accurate results.\n\t\t//\n\t\t// Note this function does not throw if enabling emulation fails; it is a best-effort.\n\t\tconst session = await cdpSession(this.page);\n\n\t\tif (!session) {\n\t\t\t// Playwright emulates focus on Firefox and WebKit itself, so there is nothing to assert\n\t\t\t// and nothing worth warning about.\n\t\t\tif (isChromium(this.page)) {\n\t\t\t\tconsole.warn(\"Could not open a CDP session for the browser adaptor\");\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tif (focusEmulatedPages.has(this.page)) {\n\t\t\t\t// Chromium ignores a redundant enable, so re-asserting has to toggle.\n\t\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\t\tenabled: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\tenabled: true,\n\t\t\t});\n\t\t\tfocusEmulatedPages.add(this.page);\n\t\t} catch (error) {\n\t\t\tconsole.warn(\"Could not enable focus emulation for the browser adaptor\", {\n\t\t\t\terror,\n\t\t\t});\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AASA,IAAM,cAAc,oBAAI,QAA0C;AAGlE,IAAM,qBAAqB,oBAAI,QAAc;AAE7C,IAAM,gCAAgC;AAEtC,IAAM,eAAe;AAErB,SAAS,WAAW,MAAwC;AAC3D,QAAM,WAAW,YAAY,IAAI,IAAI;AAErC,MAAI,UAAU;AACb,WAAO;AAAA,EACR;AAEA,QAAM,UAAU,KACd,QAAQ,EACR,cAAc,IAAI,EAClB,MAAM,MAAM,IAAI;AAClB,cAAY,IAAI,MAAM,OAAO;AAE7B,SAAO;AACR;AAEA,SAAS,WAAW,MAAqB;AACxC,MAAI;AACH,WAAO,KAAK,QAAQ,EAAE,QAAQ,GAAG,YAAY,EAAE,KAAK,MAAM;AAAA,EAC3D,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAuBO,IAAM,oBAAN,MAAkD;AAAA,EAKxD,YACkB,MACjB,UAAoC,CAAC,GACpC;AAFgB;AAGjB,SAAK,sBAAsB,QAAQ,uBAAuB;AAC1D,SAAK,wBAAwB,QAAQ,yBAAyB;AAAA,EAC/D;AAAA,EALkB;AAAA,EALT;AAAA,EAEQ;AAAA,EAUjB,MAAM,SAEL,OACG,MACU;AACb,QAAI;AAGH,aAAQ,MAAM,KAAK,KAAK;AAAA,QACvB,CAAC,CAAC,QAAQ,MAAM,MAAM,IAAI,SAAS,WAAW,M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AM,UAAU,MAAM,WAAW,KAAK,IAAI;AAE1C,QAAI,CAAC,SAAS;AAGb,UAAI,WAAW,KAAK,IAAI,GAAG;AAC1B,gBAAQ,KAAK,sDAAsD;AAAA,MACpE;AAEA;AAAA,IACD;AAEA,QAAI;AACH,UAAI,mBAAmB,IAAI,KAAK,IAAI,GAAG;AAEtC,cAAM,QAAQ,KAAK,sCAAsC;AAAA,UACxD,SAAS;AAAA,QACV,CAAC;AAAA,MACF;AAEA,YAAM,QAAQ,KAAK,sCAAsC;AAAA,QACxD,SAAS;AAAA,MACV,CAAC;AACD,yBAAmB,IAAI,KAAK,IAAI;AAAA,IACjC,SAAS,OAAO;AACf,cAAQ,KAAK,4DAA4D;AAAA,QACxE;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/adaptors/playwright.ts"],"sourcesContent":["import type { CDPSession, Dialog, JSHandle, Page } from \"playwright-core\";\nimport type { BrowserAdaptor, ElementRef, KeyName, Rect } from \"../adaptor\";\nimport { nextPaintScript } from \"../paint\";\n\n// The CDP session for each page, shared by focus emulation and clipped screenshots. A fresh adaptor\n// is created per audit run, but a page often outlives one run, so without this each run would open\n// another session that is never detached. The session is kept attached for the page's lifetime:\n// Chrome clears focus emulation when the CDP client disconnects. Resolves to null on Firefox and\n// WebKit, where Playwright offers no CDP.\nconst cdpSessions = new WeakMap<Page, Promise<CDPSession | null>>();\n\n// Pages that have had focus emulation enabled at least once.\nconst focusEmulatedPages = new WeakSet<Page>();\n\n// Dialog dismissal per page, shared by every adaptor wrapping that page: how many dialogs were\n// dismissed and not yet reported, how many callers currently want dialogs dismissed, and the\n// listener doing it while any does.\ntype DialogState = {\n\tcount: number;\n\tholds: number;\n\tlistener: ((dialog: Dialog) => void) | null;\n};\n\nconst dialogStates = new WeakMap<Page, DialogState>();\n\nconst DEFAULT_SCREENSHOT_CLIP_SCALE = 2;\n\nconst EVAL_BLOCKED = /EvalError|unsafe-eval|Content Security Policy|Trusted ?Type|TrustedScript/i;\n\nfunction cdpSession(page: Page): Promise<CDPSession | null> {\n\tconst existing = cdpSessions.get(page);\n\n\tif (existing) {\n\t\treturn existing;\n\t}\n\n\tconst session = page\n\t\t.context()\n\t\t.newCDPSession(page)\n\t\t.catch(() => null);\n\tcdpSessions.set(page, session);\n\n\treturn session;\n}\n\nfunction isChromium(page: Page): boolean {\n\ttry {\n\t\treturn page.context().browser()?.browserType().name() === \"chromium\";\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport type PlaywrightAdaptorOptions = {\n\t/**\n\t * Device scale factor for evidence screenshots. Defaults to 2. On Chromium any value is honoured\n\t * per capture. Elsewhere this must match the `deviceScaleFactor` the browser context was created\n\t * with, because Playwright's public screenshot API cannot rescale a single capture.\n\t */\n\tscreenshotClipScale?: number;\n\n\t/**\n\t * Let a Chromium clip capture content outside the current viewport. Defaults to false: to honour\n\t * it Chromium shrinks the emulated viewport to 1x1 and then resizes it for the clip before\n\t * restoring it, and the page observes each of those as a real resize (`resize` fires, media\n\t * queries flip to their narrowest breakpoint), which can collapse a responsive layout and blur\n\t * the focused element mid-capture. Only enable it for evidence of regions the caller cannot\n\t * scroll into view, where the page's state does not matter. Firefox and WebKit capture the full\n\t * page without resizing the viewport, so they ignore this.\n\t */\n\tcaptureBeyondViewport?: boolean;\n\n\t/**\n\t * Whether to dismiss native dialogs (`alert`, `confirm`, `prompt`, `beforeunload`), and count\n\t * them. Playwright dismisses dialogs by itself only while nothing listens for them, and then\n\t * nothing records that one appeared.\n\t *\n\t * - `true`, the default: only while something has asked for it through `startDismissingDialogs`,\n\t * which a tab session does for as long as it runs. Outside that the page's dialogs are the\n\t * caller's to handle, and inside it a `dialog` listener of the caller's that answers a dialog\n\t * as it is raised still gets to.\n\t * - `\"always\"`: from construction, for the page's lifetime. For a caller that hands the whole\n\t * page over, such as the audit runner.\n\t * - `false`: never. The caller handles `dialog` events itself.\n\t */\n\tdismissDialogs?: boolean | \"always\";\n};\n\n/**\n * Dismiss the dialogs `page` raises, counting them, until the returned function is called. The\n * listener is on the page only while at least one caller holds it, so a caller's own `dialog`\n * handler has the page to itself the rest of the time.\n */\nfunction dismissDialogsOn(page: Page): () => void {\n\tif (typeof page.on !== \"function\") {\n\t\treturn () => {};\n\t}\n\n\tlet state = dialogStates.get(page);\n\n\tif (state === undefined) {\n\t\tstate = { count: 0, holds: 0, listener: null };\n\t\tdialogStates.set(page, state);\n\t}\n\n\tconst held = state;\n\n\tif (held.holds++ === 0) {\n\t\tconst listener = (dialog: Dialog): void => {\n\t\t\theld.count++;\n\n\t\t\t// Not answered until every other listener has had the dialog: one of the caller's own that\n\t\t\t// answers it as it is raised then gets to, instead of finding it already handled. The\n\t\t\t// dismissal rejects when that happened, which is as good as dismissed.\n\t\t\tsetTimeout(() => {\n\t\t\t\tdialog.dismiss().catch(() => {});\n\t\t\t}, 0);\n\t\t};\n\n\t\theld.listener = listener;\n\t\tpage.on(\"dialog\", listener);\n\t}\n\n\tlet released = false;\n\n\treturn () => {\n\t\tif (released) {\n\t\t\treturn;\n\t\t}\n\n\t\treleased = true;\n\n\t\tif (--held.holds === 0 && held.listener !== null) {\n\t\t\tpage.off(\"dialog\", held.listener);\n\t\t\theld.listener = null;\n\t\t}\n\t};\n}\n\n/** A BrowserAdaptor backed by a Playwright Page. */\nexport class PlaywrightAdaptor implements BrowserAdaptor {\n\treadonly screenshotClipScale: number;\n\n\tprivate readonly captureBeyondViewport: boolean;\n\n\tprivate readonly dismissDialogs: boolean | \"always\";\n\n\tconstructor(\n\t\tprivate readonly page: Page,\n\t\toptions: PlaywrightAdaptorOptions = {},\n\t) {\n\t\tthis.screenshotClipScale = options.screenshotClipScale ?? DEFAULT_SCREENSHOT_CLIP_SCALE;\n\t\tthis.captureBeyondViewport = options.captureBeyondViewport ?? false;\n\t\tthis.dismissDialogs = options.dismissDialogs ?? true;\n\n\t\tif (this.dismissDialogs === \"always\") {\n\t\t\tdismissDialogsOn(page);\n\t\t}\n\t}\n\n\tstartDismissingDialogs(): () => void {\n\t\treturn this.dismissDialogs === false ? () => {} : dismissDialogsOn(this.page);\n\t}\n\n\ttakeDismissedDialogs(): number {\n\t\tconst state = dialogStates.get(this.page);\n\t\tconst count = state?.count ?? 0;\n\n\t\tif (state) {\n\t\t\tstate.count = 0;\n\t\t}\n\n\t\treturn count;\n\t}\n\n\tasync evaluate<T>(\n\t\t// biome-ignore lint/suspicious/noExplicitAny: the page-evaluated fn accepts arbitrary serialised args and element handles.\n\t\tfn: (...args: any[]) => T | Promise<T>,\n\t\t...args: unknown[]\n\t): Promise<T> {\n\t\ttry {\n\t\t\t// Playwright takes a single argument, so the function source and its args travel packed\n\t\t\t// into one tuple. Handles nested in that tuple are still resolved to live elements.\n\t\t\treturn (await this.page.evaluate(\n\t\t\t\t([source, packed]) => new Function(`return (${source})`)()(...(packed as unknown[])),\n\t\t\t\t[fn.toString(), args] as [string, unknown[]],\n\t\t\t)) as T;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\n\t\t\tif (!EVAL_BLOCKED.test(message)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn await this.evaluateWithoutEval<T>(fn, args);\n\t\t\t} catch (fallbackError) {\n\t\t\t\tconst fallbackMessage =\n\t\t\t\t\tfallbackError instanceof Error ? fallbackError.message : String(fallbackError);\n\n\t\t\t\tif (!EVAL_BLOCKED.test(fallbackMessage)) {\n\t\t\t\t\tthrow fallbackError;\n\t\t\t\t}\n\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"This page's Content-Security-Policy blocks the Playwright adaptor from building page functions. Allow 'unsafe-eval' in script-src, or use the Puppeteer adaptor.\",\n\t\t\t\t\t{ cause: fallbackError },\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The route for pages whose Content-Security-Policy forbids `new Function()`: Playwright itself\n\t * turns the source into a function, through the protocol rather than in page script, and the\n\t * function is then called by handle. It costs two more round trips than the packed call, so it\n\t * is only taken once that one has been refused.\n\t */\n\tprivate async evaluateWithoutEval<T>(\n\t\t// biome-ignore lint/suspicious/noExplicitAny: the page-evaluated fn accepts arbitrary serialised args and element handles.\n\t\tfn: (...args: any[]) => T | Promise<T>,\n\t\targs: unknown[],\n\t): Promise<T> {\n\t\tconst handle = await this.page.evaluateHandle(`(${fn.toString()})`);\n\n\t\ttry {\n\t\t\treturn (await handle.evaluate(\n\t\t\t\t(pageFn, packed) => (pageFn as (...values: unknown[]) => unknown)(...(packed as unknown[])),\n\t\t\t\targs,\n\t\t\t)) as T;\n\t\t} finally {\n\t\t\tawait handle.dispose().catch(() => {});\n\t\t}\n\t}\n\n\tevaluateHandle(fn: () => Element | null): Promise<ElementRef> {\n\t\treturn this.page.evaluateHandle(fn);\n\t}\n\n\tasync disposeRef(ref: ElementRef): Promise<void> {\n\t\tawait (ref as JSHandle).dispose();\n\t}\n\n\tasync pressTab(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Tab\");\n\t}\n\n\tasync pressEnter(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Enter\");\n\t}\n\n\tasync pressKey(key: KeyName): Promise<void> {\n\t\tawait this.page.keyboard.press(key);\n\t}\n\n\tasync screenshotClip(clip: Rect, scale = 1): Promise<Uint8Array> {\n\t\tconst session = await cdpSession(this.page);\n\n\t\tif (session) {\n\t\t\t// No wait for a paint first: Chromium renders a frame of the page as it stands for every\n\t\t\t// capture it is asked for through CDP.\n\t\t\t//\n\t\t\t// The public API cannot scale one capture, and its `clip` is only honoured inside the\n\t\t\t// viewport. CDP is what Puppeteer drives too, so evidence images stay pixel-comparable.\n\t\t\t//\n\t\t\t// `captureBeyondViewport: false` ensures that Chromium does not resize the viewport before\n\t\t\t// capturing the screenshot, which can trigger media queries and hide the element we are\n\t\t\t// trying to capture.\n\t\t\tconst { data } = await session.send(\"Page.captureScreenshot\", {\n\t\t\t\tformat: \"png\",\n\t\t\t\tcaptureBeyondViewport: this.captureBeyondViewport,\n\t\t\t\tclip: { ...clip, scale },\n\t\t\t});\n\n\t\t\treturn Buffer.from(data, \"base64\");\n\t\t}\n\n\t\tawait this.page.evaluate(nextPaintScript);\n\n\t\t// Clips are document coordinates, and Playwright renders anything outside the viewport blank\n\t\t// unless the capture is full-page. Firefox and WebKit capture a full page without resizing\n\t\t// the viewport, so the page does not observe this.\n\t\treturn (await this.page.screenshot({\n\t\t\ttype: \"png\",\n\t\t\tfullPage: true,\n\t\t\tclip,\n\t\t\tscale: \"device\",\n\t\t})) as Uint8Array;\n\t}\n\n\tasync ensureFocusReporting(): Promise<void> {\n\t\t// Pages only report focus while they are the foreground tab. Since this browser instance is\n\t\t// likely running in the background, we need to enable focus emulation to get accurate results.\n\t\t//\n\t\t// Note this function does not throw if enabling emulation fails; it is a best-effort.\n\t\tconst session = await cdpSession(this.page);\n\n\t\tif (!session) {\n\t\t\t// Playwright emulates focus on Firefox and WebKit itself, so there is nothing to assert\n\t\t\t// and nothing worth warning about.\n\t\t\tif (isChromium(this.page)) {\n\t\t\t\tconsole.warn(\"Could not open a CDP session for the browser adaptor\");\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tif (focusEmulatedPages.has(this.page)) {\n\t\t\t\t// Chromium ignores a redundant enable, so re-asserting has to toggle.\n\t\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\t\tenabled: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\tenabled: true,\n\t\t\t});\n\t\t\tfocusEmulatedPages.add(this.page);\n\t\t} catch (error) {\n\t\t\tconsole.warn(\"Could not enable focus emulation for the browser adaptor\", {\n\t\t\t\terror,\n\t\t\t});\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AASA,IAAM,cAAc,oBAAI,QAA0C;AAGlE,IAAM,qBAAqB,oBAAI,QAAc;AAW7C,IAAM,eAAe,oBAAI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AM,uBAAsC;AAK3C,UAAM,UAAU,MAAM,WAAW,KAAK,IAAI;AAE1C,QAAI,CAAC,SAAS;AAGb,UAAI,WAAW,KAAK,IAAI,GAAG;AAC1B,gBAAQ,KAAK,sDAAsD;AAAA,MACpE;AAEA;AAAA,IACD;AAEA,QAAI;AACH,UAAI,mBAAmB,IAAI,KAAK,IAAI,GAAG;AAEtC,cAAM,QAAQ,KAAK,sCAAsC;AAAA,UACxD,SAAS;AAAA,QACV,CAAC;AAAA,MACF;AAEA,YAAM,QAAQ,KAAK,sCAAsC;AAAA,QACxD,SAAS;AAAA,MACV,CAAC;AACD,yBAAmB,IAAI,KAAK,IAAI;AAAA,IACjC,SAAS,OAAO;AACf,cAAQ,KAAK,4DAA4D;AAAA,QACxE;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD;AACD;","names":[]}
|
|
@@ -17,6 +17,20 @@ export type PuppeteerAdaptorOptions = {
|
|
|
17
17
|
* scroll into view, where the page's state does not matter.
|
|
18
18
|
*/
|
|
19
19
|
captureBeyondViewport?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to dismiss native dialogs (`alert`, `confirm`, `prompt`, `beforeunload`), and count
|
|
22
|
+
* them. A dialog blocks the page until something answers it, so an unanswered one hangs every
|
|
23
|
+
* later call.
|
|
24
|
+
*
|
|
25
|
+
* - `true`, the default: only while something has asked for it through `startDismissingDialogs`,
|
|
26
|
+
* which a tab session does for as long as it runs. Outside that the page's dialogs are the
|
|
27
|
+
* caller's to handle, and inside it a `dialog` listener of the caller's that answers a dialog
|
|
28
|
+
* as it is raised still gets to.
|
|
29
|
+
* - `"always"`: from construction, for the page's lifetime. For a caller that hands the whole
|
|
30
|
+
* page over, such as the audit runner.
|
|
31
|
+
* - `false`: never. The caller handles `dialog` events itself.
|
|
32
|
+
*/
|
|
33
|
+
dismissDialogs?: boolean | "always";
|
|
20
34
|
};
|
|
21
35
|
/** A BrowserAdaptor backed by a Puppeteer Page. */
|
|
22
36
|
export declare class PuppeteerAdaptor implements BrowserAdaptor {
|
|
@@ -24,7 +38,10 @@ export declare class PuppeteerAdaptor implements BrowserAdaptor {
|
|
|
24
38
|
readonly screenshotClipScale: number;
|
|
25
39
|
private readonly optimizeForSpeed;
|
|
26
40
|
private readonly captureBeyondViewport;
|
|
41
|
+
private readonly dismissDialogs;
|
|
27
42
|
constructor(page: Page, options?: PuppeteerAdaptorOptions);
|
|
43
|
+
startDismissingDialogs(): () => void;
|
|
44
|
+
takeDismissedDialogs(): number;
|
|
28
45
|
evaluate<T>(fn: (...args: any[]) => T | Promise<T>, ...args: unknown[]): Promise<T>;
|
|
29
46
|
evaluateHandle(fn: () => Element | null): Promise<ElementRef>;
|
|
30
47
|
disposeRef(ref: ElementRef): Promise<void>;
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nextPaintScript
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-M2OOSZU3.js";
|
|
4
4
|
|
|
5
5
|
// src/adaptors/puppeteer.ts
|
|
6
6
|
var cdpSessions = /* @__PURE__ */ new WeakMap();
|
|
7
7
|
var focusEmulatedPages = /* @__PURE__ */ new WeakSet();
|
|
8
|
+
function dialogStateOf(page) {
|
|
9
|
+
let state = dialogStates.get(page);
|
|
10
|
+
if (state === void 0) {
|
|
11
|
+
state = { count: 0, holds: 0, listener: null, watching: false, last: null };
|
|
12
|
+
dialogStates.set(page, state);
|
|
13
|
+
}
|
|
14
|
+
return state;
|
|
15
|
+
}
|
|
16
|
+
function watchDialogsOn(page) {
|
|
17
|
+
if (typeof page.on !== "function") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const state = dialogStateOf(page);
|
|
21
|
+
if (state.watching) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
state.watching = true;
|
|
25
|
+
page.on("dialog", (dialog) => {
|
|
26
|
+
state.last = dialog;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var dialogStates = /* @__PURE__ */ new WeakMap();
|
|
8
30
|
var DEFAULT_SCREENSHOT_CLIP_SCALE = 2;
|
|
9
31
|
function cdpSession(page) {
|
|
10
32
|
const existing = cdpSessions.get(page);
|
|
@@ -15,17 +37,71 @@ function cdpSession(page) {
|
|
|
15
37
|
cdpSessions.set(page, session);
|
|
16
38
|
return session;
|
|
17
39
|
}
|
|
40
|
+
function dismissDialogsOn(page) {
|
|
41
|
+
if (typeof page.on !== "function") {
|
|
42
|
+
return () => {
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const held = dialogStateOf(page);
|
|
46
|
+
if (held.holds++ === 0) {
|
|
47
|
+
const earlier = held.last;
|
|
48
|
+
held.last = null;
|
|
49
|
+
if (earlier !== null) {
|
|
50
|
+
Promise.resolve().then(() => earlier.dismiss()).catch(() => {
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const listener = (dialog) => {
|
|
54
|
+
held.count++;
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
dialog.dismiss().catch(() => {
|
|
57
|
+
});
|
|
58
|
+
}, 0);
|
|
59
|
+
};
|
|
60
|
+
held.listener = listener;
|
|
61
|
+
page.on("dialog", listener);
|
|
62
|
+
}
|
|
63
|
+
let released = false;
|
|
64
|
+
return () => {
|
|
65
|
+
if (released) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
released = true;
|
|
69
|
+
if (--held.holds === 0 && held.listener !== null) {
|
|
70
|
+
page.off("dialog", held.listener);
|
|
71
|
+
held.listener = null;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
18
75
|
var PuppeteerAdaptor = class {
|
|
19
76
|
constructor(page, options = {}) {
|
|
20
77
|
this.page = page;
|
|
21
78
|
this.screenshotClipScale = options.screenshotClipScale ?? DEFAULT_SCREENSHOT_CLIP_SCALE;
|
|
22
79
|
this.optimizeForSpeed = options.optimizeForSpeed ?? true;
|
|
23
80
|
this.captureBeyondViewport = options.captureBeyondViewport ?? false;
|
|
81
|
+
this.dismissDialogs = options.dismissDialogs ?? true;
|
|
82
|
+
if (this.dismissDialogs === "always") {
|
|
83
|
+
dismissDialogsOn(page);
|
|
84
|
+
} else if (this.dismissDialogs) {
|
|
85
|
+
watchDialogsOn(page);
|
|
86
|
+
}
|
|
24
87
|
}
|
|
25
88
|
page;
|
|
26
89
|
screenshotClipScale;
|
|
27
90
|
optimizeForSpeed;
|
|
28
91
|
captureBeyondViewport;
|
|
92
|
+
dismissDialogs;
|
|
93
|
+
startDismissingDialogs() {
|
|
94
|
+
return this.dismissDialogs === false ? () => {
|
|
95
|
+
} : dismissDialogsOn(this.page);
|
|
96
|
+
}
|
|
97
|
+
takeDismissedDialogs() {
|
|
98
|
+
const state = dialogStates.get(this.page);
|
|
99
|
+
const count = state?.count ?? 0;
|
|
100
|
+
if (state) {
|
|
101
|
+
state.count = 0;
|
|
102
|
+
}
|
|
103
|
+
return count;
|
|
104
|
+
}
|
|
29
105
|
evaluate(fn, ...args) {
|
|
30
106
|
return this.page.evaluate(fn, ...args);
|
|
31
107
|
}
|
|
@@ -57,9 +133,9 @@ var PuppeteerAdaptor = class {
|
|
|
57
133
|
}
|
|
58
134
|
}
|
|
59
135
|
async screenshotClip(clip, scale = 1) {
|
|
60
|
-
await this.page.evaluate(nextPaintScript);
|
|
61
136
|
const session = await cdpSession(this.page);
|
|
62
137
|
if (!session) {
|
|
138
|
+
await this.page.evaluate(nextPaintScript);
|
|
63
139
|
return await this.page.screenshot({
|
|
64
140
|
type: "png",
|
|
65
141
|
optimizeForSpeed: this.optimizeForSpeed,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adaptors/puppeteer.ts"],"sourcesContent":["import type { CDPSession, JSHandle, KeyInput, Page } from \"puppeteer\";\nimport type { BrowserAdaptor, ElementRef, KeyName, Rect } from \"../adaptor\";\nimport { nextPaintScript } from \"../paint\";\n\n// Keep track of the CDP session for each page so that we can reuse it. The session is kept\n// attached for the page's lifetime: Chrome clears focus emulation when the CDP client disconnects.\n// Resolves to null when a session cannot be opened, so the failure is not retried on every call.\nconst cdpSessions = new WeakMap<Page, Promise<CDPSession | null>>();\n\n// Pages that have had focus emulation enabled at least once.\nconst focusEmulatedPages = new WeakSet<Page>();\n\nconst DEFAULT_SCREENSHOT_CLIP_SCALE = 2;\n\nfunction cdpSession(page: Page): Promise<CDPSession | null> {\n\tconst existing = cdpSessions.get(page);\n\n\tif (existing) {\n\t\treturn existing;\n\t}\n\n\tconst session = page.createCDPSession().catch(() => null);\n\tcdpSessions.set(page, session);\n\n\treturn session;\n}\n\nexport type PuppeteerAdaptorOptions = {\n\t/** Device scale factor for evidence screenshots. Defaults to 2, applied per capture. */\n\tscreenshotClipScale?: number;\n\n\t/**\n\t * Trade PNG compression for capture speed. Defaults to true, which roughly doubles the encoded\n\t * size of each capture without changing a single pixel.\n\t */\n\toptimizeForSpeed?: boolean;\n\n\t/**\n\t * Let a clip capture content outside the current viewport. Defaults to false: to honour it\n\t * Chromium shrinks the emulated viewport to 1x1 and then resizes it for the clip before\n\t * restoring it, and the page observes each of those as a real resize (`resize` fires, media\n\t * queries flip to their narrowest breakpoint), which can collapse a responsive layout and blur\n\t * the focused element mid-capture. Only enable it for evidence of regions the caller cannot\n\t * scroll into view, where the page's state does not matter.\n\t */\n\tcaptureBeyondViewport?: boolean;\n};\n\n/** A BrowserAdaptor backed by a Puppeteer Page. */\nexport class PuppeteerAdaptor implements BrowserAdaptor {\n\treadonly screenshotClipScale: number;\n\n\tprivate readonly optimizeForSpeed: boolean;\n\n\tprivate readonly captureBeyondViewport: boolean;\n\n\tconstructor(\n\t\tprivate readonly page: Page,\n\t\toptions: PuppeteerAdaptorOptions = {},\n\t) {\n\t\tthis.screenshotClipScale = options.screenshotClipScale ?? DEFAULT_SCREENSHOT_CLIP_SCALE;\n\t\tthis.optimizeForSpeed = options.optimizeForSpeed ?? true;\n\t\tthis.captureBeyondViewport = options.captureBeyondViewport ?? false;\n\t}\n\n\tevaluate<T>(\n\t\t// biome-ignore lint/suspicious/noExplicitAny: the page-evaluated fn accepts arbitrary serialised args and element handles.\n\t\tfn: (...args: any[]) => T | Promise<T>,\n\t\t...args: unknown[]\n\t): Promise<T> {\n\t\t// Puppeteer resolves any JSHandle passed as an arg to the live element.\n\t\treturn this.page.evaluate(fn as never, ...(args as never[])) as Promise<T>;\n\t}\n\n\tevaluateHandle(fn: () => Element | null): Promise<ElementRef> {\n\t\treturn this.page.evaluateHandle(fn);\n\t}\n\n\tasync disposeRef(ref: ElementRef): Promise<void> {\n\t\tawait (ref as JSHandle).dispose();\n\t}\n\n\tasync pressTab(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Tab\");\n\t}\n\n\tasync pressEnter(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Enter\");\n\t}\n\n\tasync pressKey(key: KeyName): Promise<void> {\n\t\tconst { keyboard } = this.page;\n\t\t// Puppeteer has no syntax for a combination, so modifiers are held down by hand.\n\t\tconst modifiers = key.split(\"+\") as KeyInput[];\n\t\tconst name = modifiers.pop()!;\n\n\t\tfor (const modifier of modifiers) {\n\t\t\tawait keyboard.down(modifier);\n\t\t}\n\n\t\ttry {\n\t\t\tawait keyboard.press(name);\n\t\t} finally {\n\t\t\tfor (const modifier of modifiers) {\n\t\t\t\tawait keyboard.up(modifier);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync screenshotClip(clip: Rect, scale = 1): Promise<Uint8Array> {\n\t\tawait this.page.evaluate(nextPaintScript);\n\n\t\tconst session = await cdpSession(this.page);\n\n\t\tif (!session) {\n\t\t\t// Without CDP the public API is all there is. With captureBeyondViewport off it intersects\n\t\t\t// the clip with the viewport, so a clip that does not fit comes back smaller than asked\n\t\t\t// for, with a shifted origin.\n\t\t\treturn (await this.page.screenshot({\n\t\t\t\ttype: \"png\",\n\t\t\t\toptimizeForSpeed: this.optimizeForSpeed,\n\t\t\t\tcaptureBeyondViewport: this.captureBeyondViewport,\n\t\t\t\tclip: { ...clip, scale },\n\t\t\t})) as Uint8Array;\n\t\t}\n\n\t\t// Straight to CDP rather than page.screenshot(): with captureBeyondViewport off, Puppeteer\n\t\t// intersects the clip with the visual viewport and silently moves the origin that callers\n\t\t// align element rects against. Keeping captureBeyondViewport off ensures that Chromium does\n\t\t// not resize the viewport, which can trigger media queries and hide the element we are\n\t\t// trying to capture.\n\t\tconst { data } = await session.send(\"Page.captureScreenshot\", {\n\t\t\tformat: \"png\",\n\t\t\toptimizeForSpeed: this.optimizeForSpeed,\n\t\t\tcaptureBeyondViewport: this.captureBeyondViewport,\n\t\t\tclip: { ...clip, scale },\n\t\t});\n\n\t\treturn Buffer.from(data, \"base64\");\n\t}\n\n\tasync ensureFocusReporting(): Promise<void> {\n\t\t// Pages only report focus while they are the foreground tab. Since this browser instance is\n\t\t// likely running in the background, we need to enable focus emulation to get accurate results.\n\t\t//\n\t\t// Note this function does not throw if enabling emulation fails; it is a best-effort.\n\t\ttry {\n\t\t\tconst session = await cdpSession(this.page);\n\n\t\t\tif (!session) {\n\t\t\t\tthrow new Error(\"Could not open a CDP session\");\n\t\t\t}\n\n\t\t\tif (focusEmulatedPages.has(this.page)) {\n\t\t\t\t// Chromium ignores a redundant enable, so re-asserting has to toggle.\n\t\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\t\tenabled: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\tenabled: true,\n\t\t\t});\n\t\t\tfocusEmulatedPages.add(this.page);\n\t\t} catch (error) {\n\t\t\tconsole.warn(\"Could not enable focus emulation for the browser adaptor\", {\n\t\t\t\terror,\n\t\t\t});\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AAOA,IAAM,cAAc,oBAAI,QAA0C;AAGlE,IAAM,qBAAqB,oBAAI,QAAc;AAE7C,IAAM,gCAAgC;AAEtC,SAAS,WAAW,MAAwC;AAC3D,QAAM,WAAW,YAAY,IAAI,IAAI;AAErC,M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AM,UAAU,MAAM,WAAW,KAAK,IAAI;AAE1C,QAAI,CAAC,SAAS;AAIb,aAAQ,MAAM,KAAK,KAAK,WAAW;AAAA,QAClC,MAAM;AAAA,QACN,kBAAkB,KAAK;AAAA,QACvB,uBAAuB,KAAK;AAAA,QAC5B,MAAM,EAAE,GAAG,MAAM,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AAOA,UAAM,EAAE,KAAK,IAAI,MAAM,QAAQ,KAAK,0BAA0B;AAAA,MAC7D,QAAQ;AAAA,MACR,kBAAkB,KAAK;AAAA,MACvB,uBAAuB,KAAK;AAAA,MAC5B,MAAM,EAAE,GAAG,MAAM,MAAM;AAAA,IACxB,CAAC;AAED,WAAO,OAAO,KAAK,MAAM,QAAQ;AAAA,EAClC;AAAA,EAEA,MAAM,uBAAsC;AAK3C,QAAI;AACH,YAAM,UAAU,MAAM,WAAW,KAAK,IAAI;AAE1C,UAAI,CAAC,SAAS;AACb,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAC/C;AAEA,UAAI,mBAAmB,IAAI,KAAK,IAAI,GAAG;AAEtC,cAAM,QAAQ,KAAK,sCAAsC;AAAA,UACxD,SAAS;AAAA,QACV,CAAC;AAAA,MACF;AAEA,YAAM,QAAQ,KAAK,sCAAsC;AAAA,QACxD,SAAS;AAAA,MACV,CAAC;AACD,yBAAmB,IAAI,KAAK,IAAI;AAAA,IACjC,SAAS,OAAO;AACf,cAAQ,KAAK,4DAA4D;AAAA,QACxE;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/adaptors/puppeteer.ts"],"sourcesContent":["import type { CDPSession, Dialog, JSHandle, KeyInput, Page } from \"puppeteer\";\nimport type { BrowserAdaptor, ElementRef, KeyName, Rect } from \"../adaptor\";\nimport { nextPaintScript } from \"../paint\";\n\n// Keep track of the CDP session for each page so that we can reuse it. The session is kept\n// attached for the page's lifetime: Chrome clears focus emulation when the CDP client disconnects.\n// Resolves to null when a session cannot be opened, so the failure is not retried on every call.\nconst cdpSessions = new WeakMap<Page, Promise<CDPSession | null>>();\n\n// Pages that have had focus emulation enabled at least once.\nconst focusEmulatedPages = new WeakSet<Page>();\n\n// Dialog dismissal per page, shared by every adaptor wrapping that page: how many dialogs were\n// dismissed and not yet reported, how many callers currently want dialogs dismissed, the listener\n// doing it while any does, and the last dialog the page raised, which may still be open.\ntype DialogState = {\n\tcount: number;\n\tholds: number;\n\tlistener: ((dialog: Dialog) => void) | null;\n\twatching: boolean;\n\tlast: Dialog | null;\n};\n\nfunction dialogStateOf(page: Page): DialogState {\n\tlet state = dialogStates.get(page);\n\n\tif (state === undefined) {\n\t\tstate = { count: 0, holds: 0, listener: null, watching: false, last: null };\n\t\tdialogStates.set(page, state);\n\t}\n\n\treturn state;\n}\n\n/**\n * Remember the last dialog `page` raised, without answering it. Puppeteer leaves a dialog nobody\n * answers open, and an open dialog blocks every call to the page, so whoever starts dismissing\n * dialogs later has to be able to close one that was raised before they started. Watching answers\n * nothing, so the caller's own `dialog` handler is unaffected.\n */\nfunction watchDialogsOn(page: Page): void {\n\tif (typeof page.on !== \"function\") {\n\t\treturn;\n\t}\n\n\tconst state = dialogStateOf(page);\n\n\tif (state.watching) {\n\t\treturn;\n\t}\n\n\tstate.watching = true;\n\tpage.on(\"dialog\", (dialog: Dialog) => {\n\t\tstate.last = dialog;\n\t});\n}\n\nconst dialogStates = new WeakMap<Page, DialogState>();\n\nconst DEFAULT_SCREENSHOT_CLIP_SCALE = 2;\n\nfunction cdpSession(page: Page): Promise<CDPSession | null> {\n\tconst existing = cdpSessions.get(page);\n\n\tif (existing) {\n\t\treturn existing;\n\t}\n\n\tconst session = page.createCDPSession().catch(() => null);\n\tcdpSessions.set(page, session);\n\n\treturn session;\n}\n\nexport type PuppeteerAdaptorOptions = {\n\t/** Device scale factor for evidence screenshots. Defaults to 2, applied per capture. */\n\tscreenshotClipScale?: number;\n\n\t/**\n\t * Trade PNG compression for capture speed. Defaults to true, which roughly doubles the encoded\n\t * size of each capture without changing a single pixel.\n\t */\n\toptimizeForSpeed?: boolean;\n\n\t/**\n\t * Let a clip capture content outside the current viewport. Defaults to false: to honour it\n\t * Chromium shrinks the emulated viewport to 1x1 and then resizes it for the clip before\n\t * restoring it, and the page observes each of those as a real resize (`resize` fires, media\n\t * queries flip to their narrowest breakpoint), which can collapse a responsive layout and blur\n\t * the focused element mid-capture. Only enable it for evidence of regions the caller cannot\n\t * scroll into view, where the page's state does not matter.\n\t */\n\tcaptureBeyondViewport?: boolean;\n\n\t/**\n\t * Whether to dismiss native dialogs (`alert`, `confirm`, `prompt`, `beforeunload`), and count\n\t * them. A dialog blocks the page until something answers it, so an unanswered one hangs every\n\t * later call.\n\t *\n\t * - `true`, the default: only while something has asked for it through `startDismissingDialogs`,\n\t * which a tab session does for as long as it runs. Outside that the page's dialogs are the\n\t * caller's to handle, and inside it a `dialog` listener of the caller's that answers a dialog\n\t * as it is raised still gets to.\n\t * - `\"always\"`: from construction, for the page's lifetime. For a caller that hands the whole\n\t * page over, such as the audit runner.\n\t * - `false`: never. The caller handles `dialog` events itself.\n\t */\n\tdismissDialogs?: boolean | \"always\";\n};\n\n/**\n * Dismiss the dialogs `page` raises, counting them, until the returned function is called. The\n * listener is on the page only while at least one caller holds it, so a caller's own `dialog`\n * handler has the page to itself the rest of the time.\n */\nfunction dismissDialogsOn(page: Page): () => void {\n\tif (typeof page.on !== \"function\") {\n\t\treturn () => {};\n\t}\n\n\tconst held = dialogStateOf(page);\n\n\tif (held.holds++ === 0) {\n\t\t// A dialog raised before anyone was dismissing them may still be open, blocking the page.\n\t\t// Dismissing one that was answered since rejects, which is fine. It is not counted: it\n\t\t// predates whatever is starting now.\n\t\tconst earlier = held.last;\n\t\theld.last = null;\n\n\t\tif (earlier !== null) {\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() => earlier.dismiss())\n\t\t\t\t.catch(() => {});\n\t\t}\n\n\t\tconst listener = (dialog: Dialog): void => {\n\t\t\theld.count++;\n\n\t\t\t// Not answered until every other listener has had the dialog: one of the caller's own that\n\t\t\t// answers it as it is raised then gets to, instead of finding it already handled. The\n\t\t\t// dismissal rejects when that happened, which is as good as dismissed.\n\t\t\tsetTimeout(() => {\n\t\t\t\tdialog.dismiss().catch(() => {});\n\t\t\t}, 0);\n\t\t};\n\n\t\theld.listener = listener;\n\t\tpage.on(\"dialog\", listener);\n\t}\n\n\tlet released = false;\n\n\treturn () => {\n\t\tif (released) {\n\t\t\treturn;\n\t\t}\n\n\t\treleased = true;\n\n\t\tif (--held.holds === 0 && held.listener !== null) {\n\t\t\tpage.off(\"dialog\", held.listener);\n\t\t\theld.listener = null;\n\t\t}\n\t};\n}\n\n/** A BrowserAdaptor backed by a Puppeteer Page. */\nexport class PuppeteerAdaptor implements BrowserAdaptor {\n\treadonly screenshotClipScale: number;\n\n\tprivate readonly optimizeForSpeed: boolean;\n\n\tprivate readonly captureBeyondViewport: boolean;\n\n\tprivate readonly dismissDialogs: boolean | \"always\";\n\n\tconstructor(\n\t\tprivate readonly page: Page,\n\t\toptions: PuppeteerAdaptorOptions = {},\n\t) {\n\t\tthis.screenshotClipScale = options.screenshotClipScale ?? DEFAULT_SCREENSHOT_CLIP_SCALE;\n\t\tthis.optimizeForSpeed = options.optimizeForSpeed ?? true;\n\t\tthis.captureBeyondViewport = options.captureBeyondViewport ?? false;\n\t\tthis.dismissDialogs = options.dismissDialogs ?? true;\n\n\t\tif (this.dismissDialogs === \"always\") {\n\t\t\tdismissDialogsOn(page);\n\t\t} else if (this.dismissDialogs) {\n\t\t\twatchDialogsOn(page);\n\t\t}\n\t}\n\n\tstartDismissingDialogs(): () => void {\n\t\treturn this.dismissDialogs === false ? () => {} : dismissDialogsOn(this.page);\n\t}\n\n\ttakeDismissedDialogs(): number {\n\t\tconst state = dialogStates.get(this.page);\n\t\tconst count = state?.count ?? 0;\n\n\t\tif (state) {\n\t\t\tstate.count = 0;\n\t\t}\n\n\t\treturn count;\n\t}\n\n\tevaluate<T>(\n\t\t// biome-ignore lint/suspicious/noExplicitAny: the page-evaluated fn accepts arbitrary serialised args and element handles.\n\t\tfn: (...args: any[]) => T | Promise<T>,\n\t\t...args: unknown[]\n\t): Promise<T> {\n\t\t// Puppeteer resolves any JSHandle passed as an arg to the live element.\n\t\treturn this.page.evaluate(fn as never, ...(args as never[])) as Promise<T>;\n\t}\n\n\tevaluateHandle(fn: () => Element | null): Promise<ElementRef> {\n\t\treturn this.page.evaluateHandle(fn);\n\t}\n\n\tasync disposeRef(ref: ElementRef): Promise<void> {\n\t\tawait (ref as JSHandle).dispose();\n\t}\n\n\tasync pressTab(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Tab\");\n\t}\n\n\tasync pressEnter(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Enter\");\n\t}\n\n\tasync pressKey(key: KeyName): Promise<void> {\n\t\tconst { keyboard } = this.page;\n\t\t// Puppeteer has no syntax for a combination, so modifiers are held down by hand.\n\t\tconst modifiers = key.split(\"+\") as KeyInput[];\n\t\tconst name = modifiers.pop()!;\n\n\t\tfor (const modifier of modifiers) {\n\t\t\tawait keyboard.down(modifier);\n\t\t}\n\n\t\ttry {\n\t\t\tawait keyboard.press(name);\n\t\t} finally {\n\t\t\tfor (const modifier of modifiers) {\n\t\t\t\tawait keyboard.up(modifier);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync screenshotClip(clip: Rect, scale = 1): Promise<Uint8Array> {\n\t\tconst session = await cdpSession(this.page);\n\n\t\tif (!session) {\n\t\t\tawait this.page.evaluate(nextPaintScript);\n\n\t\t\t// Without CDP the public API is all there is. With captureBeyondViewport off it intersects\n\t\t\t// the clip with the viewport, so a clip that does not fit comes back smaller than asked\n\t\t\t// for, with a shifted origin.\n\t\t\treturn (await this.page.screenshot({\n\t\t\t\ttype: \"png\",\n\t\t\t\toptimizeForSpeed: this.optimizeForSpeed,\n\t\t\t\tcaptureBeyondViewport: this.captureBeyondViewport,\n\t\t\t\tclip: { ...clip, scale },\n\t\t\t})) as Uint8Array;\n\t\t}\n\n\t\t// No wait for a paint first: Chromium renders a frame of the page as it stands for every\n\t\t// capture it is asked for through CDP.\n\t\t//\n\t\t// Straight to CDP rather than page.screenshot(): with captureBeyondViewport off, Puppeteer\n\t\t// intersects the clip with the visual viewport and silently moves the origin that callers\n\t\t// align element rects against. Keeping captureBeyondViewport off ensures that Chromium does\n\t\t// not resize the viewport, which can trigger media queries and hide the element we are\n\t\t// trying to capture.\n\t\tconst { data } = await session.send(\"Page.captureScreenshot\", {\n\t\t\tformat: \"png\",\n\t\t\toptimizeForSpeed: this.optimizeForSpeed,\n\t\t\tcaptureBeyondViewport: this.captureBeyondViewport,\n\t\t\tclip: { ...clip, scale },\n\t\t});\n\n\t\treturn Buffer.from(data, \"base64\");\n\t}\n\n\tasync ensureFocusReporting(): Promise<void> {\n\t\t// Pages only report focus while they are the foreground tab. Since this browser instance is\n\t\t// likely running in the background, we need to enable focus emulation to get accurate results.\n\t\t//\n\t\t// Note this function does not throw if enabling emulation fails; it is a best-effort.\n\t\ttry {\n\t\t\tconst session = await cdpSession(this.page);\n\n\t\t\tif (!session) {\n\t\t\t\tthrow new Error(\"Could not open a CDP session\");\n\t\t\t}\n\n\t\t\tif (focusEmulatedPages.has(this.page)) {\n\t\t\t\t// Chromium ignores a redundant enable, so re-asserting has to toggle.\n\t\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\t\tenabled: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait session.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\tenabled: true,\n\t\t\t});\n\t\t\tfocusEmulatedPages.add(this.page);\n\t\t} catch (error) {\n\t\t\tconsole.warn(\"Could not enable focus emulation for the browser adaptor\", {\n\t\t\t\terror,\n\t\t\t});\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AAOA,IAAM,cAAc,oBAAI,QAA0C;AAGlE,IAAM,qBAAqB,oBAAI,QAAc;AAa7C,S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