@a11y-pulse/browser-adaptor 0.5.0 → 0.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/dist/adaptor.d.ts +6 -0
- package/dist/adaptors/playwright.d.ts +2 -1
- package/dist/adaptors/playwright.js +3 -0
- package/dist/adaptors/playwright.js.map +1 -1
- package/dist/adaptors/puppeteer.d.ts +2 -1
- package/dist/adaptors/puppeteer.js +15 -0
- package/dist/adaptors/puppeteer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +4 -4
package/dist/adaptor.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type Rect = {
|
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
7
7
|
};
|
|
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";
|
|
8
10
|
/**
|
|
9
11
|
* An element handle in the page. This type is adaptor-specific and is opaque to the audit.
|
|
10
12
|
*/
|
|
@@ -34,6 +36,10 @@ export interface BrowserAdaptor {
|
|
|
34
36
|
* Press the enter key
|
|
35
37
|
*/
|
|
36
38
|
pressEnter(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Press `key` with any modifier it names held down
|
|
41
|
+
*/
|
|
42
|
+
pressKey(key: KeyName): Promise<void>;
|
|
37
43
|
/**
|
|
38
44
|
* Screenshot a clipped region of the page defined by `clip`, in document coordinates. `scale` is
|
|
39
45
|
* the device scale factor (bitmap pixels per CSS pixel), multiplied against whatever
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Page } from "playwright-core";
|
|
2
|
-
import type { BrowserAdaptor, ElementRef, Rect } from "../adaptor";
|
|
2
|
+
import type { BrowserAdaptor, ElementRef, KeyName, Rect } from "../adaptor";
|
|
3
3
|
export type PlaywrightAdaptorOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Device scale factor for evidence screenshots. Defaults to 2. On Chromium any value is honoured
|
|
@@ -29,6 +29,7 @@ export declare class PlaywrightAdaptor implements BrowserAdaptor {
|
|
|
29
29
|
disposeRef(ref: ElementRef): Promise<void>;
|
|
30
30
|
pressTab(): Promise<void>;
|
|
31
31
|
pressEnter(): Promise<void>;
|
|
32
|
+
pressKey(key: KeyName): Promise<void>;
|
|
32
33
|
screenshotClip(clip: Rect, scale?: number): Promise<Uint8Array>;
|
|
33
34
|
ensureFocusReporting(): Promise<void>;
|
|
34
35
|
}
|
|
@@ -61,6 +61,9 @@ var PlaywrightAdaptor = class {
|
|
|
61
61
|
async pressEnter() {
|
|
62
62
|
await this.page.keyboard.press("Enter");
|
|
63
63
|
}
|
|
64
|
+
async pressKey(key) {
|
|
65
|
+
await this.page.keyboard.press(key);
|
|
66
|
+
}
|
|
64
67
|
async screenshotClip(clip, scale = 1) {
|
|
65
68
|
await this.page.evaluate(nextPaintScript);
|
|
66
69
|
const session = await cdpSession(this.page);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adaptors/playwright.ts"],"sourcesContent":["import type { CDPSession, JSHandle, Page } from \"playwright-core\";\nimport type { BrowserAdaptor, ElementRef, 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 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,Y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M,aAA4B;AACjC,UAAM,KAAK,KAAK,SAAS,MAAM,OAAO;AAAA,EACvC;AAAA,EAEA,MAAM,eAAe,MAAY,QAAQ,GAAwB;AAChE,UAAM,KAAK,KAAK,SAAS,eAAe;AAExC,UAAM,UAAU,MAAM,WAAW,KAAK,IAAI;AAE1C,QAAI,SAAS;AAOZ,YAAM,EAAE,KAAK,IAAI,MAAM,QAAQ,KAAK,0BAA0B;AAAA,QAC7D,QAAQ;AAAA,QACR,uBAAuB,KAAK;AAAA,QAC5B,MAAM,EAAE,GAAG,MAAM,MAAM;AAAA,MACxB,CAAC;AAED,aAAO,OAAO,KAAK,MAAM,QAAQ;AAAA,IAClC;AAKA,WAAQ,MAAM,KAAK,KAAK,WAAW;AAAA,MAClC,MAAM;AAAA,MACN,UAAU;AAAA,MACV;AAAA,MACA,OAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAEA,MAAM,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":[]}
|
|
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,MAAM,GAAG,EAAE,EAAE,GAAI,MAAoB;AAAA,QACnF,CAAC,GAAG,SAAS,GAAG,IAAI;AA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K,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,5 +1,5 @@
|
|
|
1
1
|
import type { Page } from "puppeteer";
|
|
2
|
-
import type { BrowserAdaptor, ElementRef, Rect } from "../adaptor";
|
|
2
|
+
import type { BrowserAdaptor, ElementRef, KeyName, Rect } from "../adaptor";
|
|
3
3
|
export type PuppeteerAdaptorOptions = {
|
|
4
4
|
/** Device scale factor for evidence screenshots. Defaults to 2, applied per capture. */
|
|
5
5
|
screenshotClipScale?: number;
|
|
@@ -30,6 +30,7 @@ export declare class PuppeteerAdaptor implements BrowserAdaptor {
|
|
|
30
30
|
disposeRef(ref: ElementRef): Promise<void>;
|
|
31
31
|
pressTab(): Promise<void>;
|
|
32
32
|
pressEnter(): Promise<void>;
|
|
33
|
+
pressKey(key: KeyName): Promise<void>;
|
|
33
34
|
screenshotClip(clip: Rect, scale?: number): Promise<Uint8Array>;
|
|
34
35
|
ensureFocusReporting(): Promise<void>;
|
|
35
36
|
}
|
|
@@ -41,6 +41,21 @@ var PuppeteerAdaptor = class {
|
|
|
41
41
|
async pressEnter() {
|
|
42
42
|
await this.page.keyboard.press("Enter");
|
|
43
43
|
}
|
|
44
|
+
async pressKey(key) {
|
|
45
|
+
const { keyboard } = this.page;
|
|
46
|
+
const modifiers = key.split("+");
|
|
47
|
+
const name = modifiers.pop();
|
|
48
|
+
for (const modifier of modifiers) {
|
|
49
|
+
await keyboard.down(modifier);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
await keyboard.press(name);
|
|
53
|
+
} finally {
|
|
54
|
+
for (const modifier of modifiers) {
|
|
55
|
+
await keyboard.up(modifier);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
44
59
|
async screenshotClip(clip, scale = 1) {
|
|
45
60
|
await this.page.evaluate(nextPaintScript);
|
|
46
61
|
const session = await cdpSession(this.page);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adaptors/puppeteer.ts"],"sourcesContent":["import type { CDPSession, JSHandle, Page } from \"puppeteer\";\nimport type { BrowserAdaptor, ElementRef, 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 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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AA,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, 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,MAAI,UAAU;AACb,WAAO;AAAA,EACR;AAEA,QAAM,UAAU,KAAK,iBAAiB,EAAE,MAAM,MAAM,IAAI;AACxD,cAAY,IAAI,MAAM,OAAO;AAE7B,SAAO;AACR;AAwBO,IAAM,mBAAN,MAAiD;AAAA,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,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":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { BrowserAdaptor, ElementRef, Rect } from "./adaptor";
|
|
1
|
+
export type { BrowserAdaptor, ElementRef, KeyName, Rect } from "./adaptor";
|
|
2
2
|
export { bufferedClip } from "./clip";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a11y-pulse/browser-adaptor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Shared browser adaptor primitives and DOM helpers for A11y Pulse accessibility audits.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"playwright-core": ">=1.40",
|
|
69
|
-
"puppeteer": "^25.
|
|
69
|
+
"puppeteer": "^25.12.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"playwright-core": {
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"happy-dom": "^
|
|
80
|
+
"happy-dom": "^21.0.1",
|
|
81
81
|
"playwright-core": "^1.63.0",
|
|
82
|
-
"puppeteer": "^25.
|
|
82
|
+
"puppeteer": "^25.12.0"
|
|
83
83
|
}
|
|
84
84
|
}
|