@e2e-dev/electron 0.1.1 → 0.1.2-nightly-20261203030525

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/.build.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.1.1"}
1
+ {"version":"0.1.2-nightly-20261203030525"}
package/dist/capture.d.ts CHANGED
@@ -1,21 +1,31 @@
1
1
  /**
2
- * Pixels: screenshots with every password field and nested document painted
3
- * over, withheld when the window holds one no mask reaches.
2
+ * Pixels: screenshots of the viewport or the whole page with every password
3
+ * field and nested document painted over, withheld when the window holds one
4
+ * no mask reaches.
4
5
  */
5
- import { type EngineSnapshot } from '@e2e-dev/core/engine';
6
+ import { type EngineScreenshotOptions, type EngineSnapshot } from '@e2e-dev/core/engine';
6
7
  import type { DevTools } from './devtools.ts';
7
8
  import { type RawRead } from './locate.ts';
8
9
  import type { AppWindow } from './windows.ts';
9
- /** Adds the pixels to an observation of a read window, or leaves them out when they are withheld. */
10
- export declare function withPixels(devtools: DevTools, raw: RawRead, snapshot: EngineSnapshot): Promise<EngineSnapshot>;
11
10
  /**
12
- * `app.screenshot(label)`: the window with its masks painted over, written
13
- * under the attempt's artifacts as `screenshots/<n>-<label>.png`. Refused
14
- * with `POLICY_DENIED` when the capture is withheld, when `refused` says why
15
- * the window is not one to capture, or when the window loaded another
16
- * document while the capture waited its turn: the pixels are of the document
17
- * `refused` approved, or none are kept.
11
+ * What a capture covers: the window's viewport when undefined, else the whole
12
+ * page, cut to the options' clip when there is one.
18
13
  */
19
- export declare function screenshotFile(devtools: DevTools, window: AppWindow, artifactsDir: string, name: string, refused: () => string | undefined): Promise<string>;
14
+ type Region = EngineScreenshotOptions | undefined;
15
+ /** Adds the pixels of the viewport, or with `fullPage` of the whole page, to an observation of a read window, or leaves them out when they are withheld. */
16
+ export declare function withPixels(devtools: DevTools, raw: RawRead, snapshot: EngineSnapshot, { fullPage }?: {
17
+ readonly fullPage?: boolean;
18
+ }): Promise<EngineSnapshot>;
19
+ /**
20
+ * `app.screenshot(label)`: the window's viewport, or the whole page the
21
+ * region asks for, with its masks painted over, written under the attempt's
22
+ * artifacts as `screenshots/<n>-<label>.png`. Refused with `POLICY_DENIED`
23
+ * when the capture is withheld, when `refused` says why the window is not
24
+ * one to capture, or when the window loaded another document while the
25
+ * capture waited its turn: the pixels are of the document `refused`
26
+ * approved, or none are kept.
27
+ */
28
+ export declare function screenshotFile(devtools: DevTools, window: AppWindow, artifactsDir: string, name: string, refused: () => string | undefined, region?: Region): Promise<string>;
20
29
  /** A screenshot's file name: its number in the attempt and a label that cannot turn into a path (letters, digits, dashes). */
21
30
  export declare function screenshotName(counter: number, label: string | undefined): string;
31
+ export {};
package/dist/capture.js CHANGED
@@ -1,10 +1,11 @@
1
1
  /**
2
- * Pixels: screenshots with every password field and nested document painted
3
- * over, withheld when the window holds one no mask reaches.
2
+ * Pixels: screenshots of the viewport or the whole page with every password
3
+ * field and nested document painted over, withheld when the window holds one
4
+ * no mask reaches.
4
5
  */
5
6
  import { mkdirSync, writeFileSync } from 'node:fs';
6
7
  import path from 'node:path';
7
- import { ConfigurationError, readPngSize } from '@e2e-dev/core/engine';
8
+ import { ConfigurationError, readPngSize, TestError } from '@e2e-dev/core/engine';
8
9
  import { pixelRatio, placeMasks, removeMasks } from './in-page/masks.js';
9
10
  import { viewportSize } from './in-page/node-ops.js';
10
11
  import { inDocument } from './locate.js';
@@ -32,14 +33,14 @@ function outOfReach(count) {
32
33
  * capture runs, inside a closed shadow root or beside the masks already
33
34
  * placed, so the document is read again before the pixels go out.
34
35
  */
35
- function maskedCapture(devtools, window, unmaskableBefore, scale) {
36
+ function maskedCapture(devtools, window, unmaskableBefore, scale, region) {
36
37
  // One capture of a page at a time: the masks are the page's, and a second capture would take the first one's away.
37
- const turn = (captures.get(window.page) ?? Promise.resolve()).then(() => captureUnderMasks(devtools, window, unmaskableBefore, scale));
38
+ const turn = (captures.get(window.page) ?? Promise.resolve()).then(() => captureUnderMasks(devtools, window, unmaskableBefore, scale, region));
38
39
  captures.set(window.page, turn.catch(() => undefined));
39
40
  return turn;
40
41
  }
41
42
  const captures = new WeakMap();
42
- async function captureUnderMasks(devtools, window, unmaskableBefore, scale) {
43
+ async function captureUnderMasks(devtools, window, unmaskableBefore, scale, region) {
43
44
  const { page } = window;
44
45
  if (unmaskableBefore === undefined)
45
46
  return { masked: (await page.evaluate(removeMasks, MASKED_SELECTOR)).count, withheld: UNREAD };
@@ -47,10 +48,10 @@ async function captureUnderMasks(devtools, window, unmaskableBefore, scale) {
47
48
  return { masked: (await page.evaluate(removeMasks, MASKED_SELECTOR)).count, withheld: outOfReach(unmaskableBefore) };
48
49
  const placed = await page.evaluate(placeMasks, MASKED_SELECTOR);
49
50
  const { count: masked } = placed;
50
- let image;
51
+ let shot;
51
52
  let after;
52
53
  try {
53
- image = await captureViewport(window, scale);
54
+ shot = region === undefined ? await captureViewport(window, scale) : await capturePage(window, scale, region);
54
55
  }
55
56
  finally {
56
57
  // The masks never outlive the capture, whatever became of it.
@@ -73,7 +74,7 @@ async function captureUnderMasks(devtools, window, unmaskableBefore, scale) {
73
74
  if (after.boxes !== placed.boxes) {
74
75
  return { masked, withheld: 'a password field or nested document moved while the screenshot was taken, out from under its mask, so the screenshot is withheld' };
75
76
  }
76
- return { masked, image };
77
+ return { masked, ...shot };
77
78
  }
78
79
  /** The window's viewport as a PNG: one image pixel per CSS pixel, or per device pixel. */
79
80
  async function captureViewport(window, scale) {
@@ -87,36 +88,83 @@ async function captureViewport(window, scale) {
87
88
  clip = { x: scrolled.pageX, y: scrolled.pageY, width, height, scale: 1 / ratio };
88
89
  }
89
90
  const { data } = await page.captured(() => page.session.send('Page.captureScreenshot', { format: 'png', ...(clip === undefined ? {} : { clip }) }));
90
- return Buffer.from(data, 'base64');
91
+ return { image: Buffer.from(data, 'base64') };
91
92
  }
92
- /** Adds the pixels to an observation of a read window, or leaves them out when they are withheld. */
93
- export async function withPixels(devtools, raw, snapshot) {
93
+ /**
94
+ * The window's whole page as a PNG, cut to the region's clip: Chromium paints
95
+ * past the viewport without scrolling or resizing the window. A fixed
96
+ * element, the masks among them, lands where it shows at the current scroll,
97
+ * the same place in the page as the element it covers.
98
+ */
99
+ async function capturePage(window, scale, region) {
100
+ const { page } = window;
101
+ const [{ cssContentSize: content, cssVisualViewport: scrolled }, ratio] = await Promise.all([page.session.send('Page.getLayoutMetrics'), page.evaluate(pixelRatio)]);
102
+ const whole = { x: 0, y: 0, width: Math.ceil(content.width), height: Math.ceil(content.height) };
103
+ let kept = whole;
104
+ if (region.clip !== undefined) {
105
+ const inside = overlap(region.clip, whole);
106
+ const { x, y, width, height } = region.clip;
107
+ if (inside === undefined)
108
+ throw new TestError('INVALID_ARGUMENT', `screenshot clip { x: ${x}, y: ${y}, width: ${width}, height: ${height} } is outside the ${whole.width}x${whole.height} page`);
109
+ kept = inside;
110
+ }
111
+ // Past this many image pixels on a side, Chromium repeats the start of the page instead of painting the rest.
112
+ const output = { width: kept.width * (scale === 'css' ? 1 : ratio), height: kept.height * (scale === 'css' ? 1 : ratio) };
113
+ if (Math.max(output.width, output.height) > MAX_CAPTURE_PIXELS) {
114
+ throw new ConfigurationError('UNSUPPORTED_CAPABILITY', `a ${Math.ceil(output.width)}x${Math.ceil(output.height)} capture is past the ${MAX_CAPTURE_PIXELS} pixels on a side Electron paints in one screenshot; capture a clip of the page`);
115
+ }
116
+ // The clip is read in the page's zoomed pixels, and `devicePixelRatio` counts the zoom too.
117
+ const zoom = scrolled.zoom ?? 1;
118
+ const clip = { x: kept.x * zoom, y: kept.y * zoom, width: kept.width * zoom, height: kept.height * zoom, scale: scale === 'css' ? 1 / ratio : 1 };
119
+ const { data } = await page.captured(() => page.session.send('Page.captureScreenshot', { format: 'png', clip, captureBeyondViewport: true }));
120
+ return { image: Buffer.from(data, 'base64'), page: { width: kept.width, scroll: { x: scrolled.pageX, y: scrolled.pageY } } };
121
+ }
122
+ /** The most pixels on a side one `Page.captureScreenshot` paints; Chromium's limit for a single compositor frame. */
123
+ const MAX_CAPTURE_PIXELS = 16_384;
124
+ /** The part of `box` inside `bounds`; undefined when none of it is. */
125
+ function overlap(box, bounds) {
126
+ const x = Math.max(box.x, bounds.x);
127
+ const y = Math.max(box.y, bounds.y);
128
+ const width = Math.min(box.x + box.width, bounds.x + bounds.width) - x;
129
+ const height = Math.min(box.y + box.height, bounds.y + bounds.height) - y;
130
+ return width > 0 && height > 0 ? { x, y, width, height } : undefined;
131
+ }
132
+ /** Adds the pixels of the viewport, or with `fullPage` of the whole page, to an observation of a read window, or leaves them out when they are withheld. */
133
+ export async function withPixels(devtools, raw, snapshot, { fullPage = false } = {}) {
94
134
  // The pixels are of the document the snapshot describes, or the observation is taken again.
95
- const capture = await inDocument(raw.window, raw.generation, () => maskedCapture(devtools, raw.window, raw.dom.unmaskableCount(), 'css'));
135
+ const capture = await inDocument(raw.window, raw.generation, () => maskedCapture(devtools, raw.window, raw.dom.unmaskableCount(), 'css', fullPage ? { fullPage: true } : undefined));
96
136
  if ('withheld' in capture)
97
137
  return { ...snapshot, maskedRegionCount: capture.masked };
98
138
  const data = new Uint8Array(capture.image);
99
- const { width: css } = await raw.window.page.evaluate(viewportSize);
100
139
  const size = readPngSize(data);
101
140
  if (size === undefined)
102
141
  throw new Error('the window capture is not a PNG');
103
- const pixels = { data, mediaType: 'image/png', width: size.width, height: size.height, scale: css > 0 ? size.width / css : 1 };
142
+ const css = capture.page?.width ?? (await raw.window.page.evaluate(viewportSize)).width;
143
+ const pixels = {
144
+ data,
145
+ mediaType: 'image/png',
146
+ width: size.width,
147
+ height: size.height,
148
+ scale: css > 0 ? size.width / css : 1,
149
+ ...(capture.page === undefined ? {} : { scroll: capture.page.scroll }),
150
+ };
104
151
  return { ...snapshot, pixels, maskedRegionCount: capture.masked };
105
152
  }
106
153
  /**
107
- * `app.screenshot(label)`: the window with its masks painted over, written
108
- * under the attempt's artifacts as `screenshots/<n>-<label>.png`. Refused
109
- * with `POLICY_DENIED` when the capture is withheld, when `refused` says why
110
- * the window is not one to capture, or when the window loaded another
111
- * document while the capture waited its turn: the pixels are of the document
112
- * `refused` approved, or none are kept.
154
+ * `app.screenshot(label)`: the window's viewport, or the whole page the
155
+ * region asks for, with its masks painted over, written under the attempt's
156
+ * artifacts as `screenshots/<n>-<label>.png`. Refused with `POLICY_DENIED`
157
+ * when the capture is withheld, when `refused` says why the window is not
158
+ * one to capture, or when the window loaded another document while the
159
+ * capture waited its turn: the pixels are of the document `refused`
160
+ * approved, or none are kept.
113
161
  */
114
- export async function screenshotFile(devtools, window, artifactsDir, name, refused) {
162
+ export async function screenshotFile(devtools, window, artifactsDir, name, refused, region) {
115
163
  const before = refused();
116
164
  if (before !== undefined)
117
165
  throw new ConfigurationError('POLICY_DENIED', before);
118
166
  const generation = window.page.generation;
119
- const capture = await maskedCapture(devtools, window, await unmaskable(devtools, window), 'device');
167
+ const capture = await maskedCapture(devtools, window, await unmaskable(devtools, window), 'device', region);
120
168
  if ('withheld' in capture)
121
169
  throw new ConfigurationError('POLICY_DENIED', capture.withheld);
122
170
  if (window.page.generation !== generation)
package/dist/engine.js CHANGED
@@ -41,6 +41,8 @@ export function electron(options = {}) {
41
41
  perform: (ref, action, operation) => surface.perform(ref, action, operation),
42
42
  actions: [...LOCATOR_ACTION_KINDS, 'blur', 'multiTap', 'setInputFilePayloads'],
43
43
  tapModifiers: true,
44
+ // Chromium paints the whole page past the viewport, and the masks with it.
45
+ fullPageScreenshots: true,
44
46
  performAt: (point, action, operation) => surface.performAt(point, action, operation),
45
47
  pointerActions: POINTER_ACTION_KINDS,
46
48
  keyboard: {
@@ -57,7 +59,7 @@ export function electron(options = {}) {
57
59
  closeTab: (index, operation) => surface.closeTab(index, operation),
58
60
  },
59
61
  artifacts: {
60
- screenshot: (label, operation) => surface.screenshot(label, operation),
62
+ screenshot: (label, operation, screenshotOptions) => surface.screenshot(label, operation, screenshotOptions),
61
63
  startVideo: (operation) => surface.startVideo(operation),
62
64
  stopVideo: () => surface.stopVideo(),
63
65
  },
package/dist/surface.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * (options, executable), the attempt's (its user-data directory and
11
11
  * artifacts), and the running app's (`AppProcess` and `Windows`).
12
12
  */
13
- import type { ComputedStyleProperty, ComputedStyleValues, ViewportIntersection, VideoSegment, EngineAttemptContext, EngineCleanupContext, EngineDoctorCheck, EngineDoctorInfo, EngineInitInfo, EngineObserveOptions, EnginePrepareInfo, EngineSnapshot, LocatorAction, LocatorExpression, NodeRef, OperationContext, PointerAction, SemanticNode, ViewportPoint } from '@e2e-dev/core/engine';
13
+ import type { ComputedStyleProperty, ComputedStyleValues, ViewportIntersection, VideoSegment, EngineAttemptContext, EngineCleanupContext, EngineDoctorCheck, EngineDoctorInfo, EngineInitInfo, EngineObserveOptions, EngineScreenshotOptions, EnginePrepareInfo, EngineSnapshot, LocatorAction, LocatorExpression, NodeRef, OperationContext, PointerAction, SemanticNode, ViewportPoint } from '@e2e-dev/core/engine';
14
14
  import { type LaunchExtra } from './app-process.ts';
15
15
  import { Budget } from './budget.ts';
16
16
  import { type DialogHandler } from './dialogs.ts';
@@ -163,7 +163,8 @@ export declare class ElectronSurface {
163
163
  readonly absolutePath: string;
164
164
  readonly suggestedFilename: string;
165
165
  }>;
166
- screenshot(label: string | undefined, operation: OperationContext): Promise<string>;
166
+ /** The window's viewport, or with `options` its whole page, cut to their clip. */
167
+ screenshot(label: string | undefined, operation: OperationContext, options?: EngineScreenshotOptions): Promise<string>;
167
168
  /** Starts a recording: of the shown window now, and of each one shown after it, through a relaunch too. */
168
169
  startVideo(operation: OperationContext): Promise<void>;
169
170
  stopVideo(): Promise<readonly VideoSegment[]>;
package/dist/surface.js CHANGED
@@ -261,7 +261,7 @@ export class ElectronSurface {
261
261
  if (left !== undefined)
262
262
  throw new ConfigurationError('POLICY_DENIED', left);
263
263
  const snapshot = projectRead(raw, 'tree', this.projection());
264
- return options?.pixels === true ? await withPixels(this.devtools, raw, snapshot) : snapshot;
264
+ return options?.pixels === true ? await withPixels(this.devtools, raw, snapshot, { fullPage: options.fullPage === true }) : snapshot;
265
265
  });
266
266
  }
267
267
  async locate(expression, operation) {
@@ -680,14 +680,15 @@ export class ElectronSurface {
680
680
  return { path: relative, absolutePath: absolute, suggestedFilename: finished.filename };
681
681
  }
682
682
  // --- pixels ---
683
- async screenshot(label, operation) {
683
+ /** The window's viewport, or with `options` its whole page, cut to their clip. */
684
+ async screenshot(label, operation, options) {
684
685
  const window = this.requireWindow();
685
686
  const attempt = this.attempt;
686
687
  if (attempt === undefined)
687
688
  throw invalidState('a screenshot is taken inside a test');
688
689
  return await withBudget(operation, 'screenshot', async () => {
689
690
  this.artifactCounter += 1;
690
- return await screenshotFile(this.devtools, window, attempt.artifactsDir, screenshotName(this.artifactCounter, label), () => this.leftApp(window));
691
+ return await screenshotFile(this.devtools, window, attempt.artifactsDir, screenshotName(this.artifactCounter, label), () => this.leftApp(window), options);
691
692
  });
692
693
  }
693
694
  // --- video ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2e-dev/electron",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-nightly-20261203030525",
4
4
  "description": "Electron engine for e2e agentic end-to-end testing: launches an Electron app and drives its windows through Chromium's accessibility tree",
5
5
  "keywords": [
6
6
  "e2e",
@@ -42,8 +42,8 @@
42
42
  "NOTICE"
43
43
  ],
44
44
  "peerDependencies": {
45
- "@e2e-dev/core": ">=0.25.1 <1",
46
- "e2e": ">=0.25.1 <1",
45
+ "@e2e-dev/core": "0.26.2-nightly-20261203030525",
46
+ "e2e": "0.26.2-nightly-20261203030525",
47
47
  "electron": "*"
48
48
  },
49
49
  "peerDependenciesMeta": {
@@ -52,11 +52,11 @@
52
52
  }
53
53
  },
54
54
  "devDependencies": {
55
- "@e2e-dev/core": "0.26.1",
55
+ "@e2e-dev/core": "0.26.2-nightly-20261203030525",
56
56
  "@napi-rs/image": "1.16.0",
57
57
  "@types/node": "26.6.11",
58
58
  "devtools-protocol": "0.0.1758431",
59
- "e2e": "0.26.1",
59
+ "e2e": "0.26.2-nightly-20261203030525",
60
60
  "electron": "45.5.0",
61
61
  "typescript": "7.0.2",
62
62
  "vitest": "5.1.2"