@e2e-dev/electron 0.0.1-nightly-20261130030410 → 0.1.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/video.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * to the window shown next, and the gap holds the last frame.
6
6
  */
7
7
  import { spawn } from 'node:child_process';
8
- import { existsSync, mkdirSync, rmSync } from 'node:fs';
8
+ import { existsSync, mkdirSync, rmSync, statSync } from 'node:fs';
9
9
  import path from 'node:path';
10
10
  import { EngineError } from '@e2e-dev/core/engine';
11
11
  import { answerWithin } from './budget.js';
@@ -20,6 +20,10 @@ const CLOSE_TIMEOUT_MS = 10_000;
20
20
  const STDERR_TAIL = 2_000;
21
21
  /** How long a window gets to hand over its last screen when the recording stops. */
22
22
  const LAST_SCREEN_MS = 2_000;
23
+ /** How long the end of a recording waits for a window switch, which a window that does not answer can hold up. */
24
+ const SWITCH_WAIT_MS = 2_000;
25
+ /** How long a window gets to answer the end of its screencast: a busy main process answers no DevTools call. */
26
+ const STOP_SCREENCAST_MS = 2_000;
23
27
  export class Recorder {
24
28
  ffmpeg;
25
29
  relative;
@@ -50,12 +54,18 @@ export class Recorder {
50
54
  if (this.stopped || this.source?.page === page)
51
55
  return;
52
56
  await this.source?.stop();
57
+ // The recording ended while the window before was stopped: the window shown next gets no screencast.
58
+ if (this.stopped)
59
+ return;
53
60
  this.source = undefined;
54
61
  if (page === undefined || page.isClosed())
55
62
  return;
56
63
  const { session } = page;
57
64
  if (this.encoder === undefined) {
58
65
  const { cssVisualViewport } = await session.send('Page.getLayoutMetrics');
66
+ // The recording ended while the window was asked: it gets no encoder.
67
+ if (this.stopped)
68
+ return;
59
69
  // Even sides: the encoder's pixel format halves them.
60
70
  const size = { width: Math.max(2, Math.floor(cssVisualViewport.clientWidth / 2) * 2), height: Math.max(2, Math.floor(cssVisualViewport.clientHeight / 2) * 2) };
61
71
  mkdirSync(path.dirname(this.absolute), { recursive: true });
@@ -74,9 +84,10 @@ export class Recorder {
74
84
  stop: async () => {
75
85
  off();
76
86
  page.recording = false;
77
- await session.send('Page.stopScreencast').catch(() => undefined);
87
+ await answerWithin(session.send('Page.stopScreencast'), STOP_SCREENCAST_MS);
78
88
  },
79
89
  };
90
+ const source = this.source;
80
91
  try {
81
92
  await session.send('Page.startScreencast', { format: 'jpeg', quality: JPEG_QUALITY, maxWidth: encoder.size.width, maxHeight: encoder.size.height });
82
93
  }
@@ -87,6 +98,11 @@ export class Recorder {
87
98
  this.source = undefined;
88
99
  return;
89
100
  }
101
+ // The recording ended while the screencast started: it sends no frame to an encoder that closed.
102
+ if (this.stopped && this.source !== source) {
103
+ await source.stop();
104
+ return;
105
+ }
90
106
  // A window shown again repaints nothing: the video would hold the window before it.
91
107
  await this.snap();
92
108
  }
@@ -95,24 +111,51 @@ export class Recorder {
95
111
  * ever shown.
96
112
  */
97
113
  async stop() {
98
- await this.switching;
114
+ return await this.withinCloseTime(async () => {
115
+ await this.settleSwitching();
116
+ const { source, encoder, startedAt } = this;
117
+ if (encoder === undefined || startedAt === undefined)
118
+ return [];
119
+ try {
120
+ await this.snap();
121
+ await source?.stop();
122
+ }
123
+ finally {
124
+ this.source = undefined;
125
+ await encoder.close().catch((cause) => {
126
+ // What ffmpeg wrote before it failed still plays; an empty file is no video.
127
+ if ((statSync(this.absolute, { throwIfNoEntry: false })?.size ?? 0) > 0)
128
+ return;
129
+ rmSync(this.absolute, { force: true });
130
+ throw new EngineError('ENGINE_FAILURE', `the video ${this.relative} could not be finalized: ${cause instanceof Error ? cause.message : String(cause)}`, { retryable: false, cause });
131
+ });
132
+ }
133
+ return existsSync(this.absolute) ? [{ path: this.relative, startedAt }] : [];
134
+ });
135
+ }
136
+ /**
137
+ * Waits for the window switch in progress, for at most `SWITCH_WAIT_MS`: a
138
+ * window that does not answer the switch's DevTools calls holds it up for
139
+ * good. A switch that answers later backs out (`stopped`).
140
+ */
141
+ async settleSwitching() {
142
+ await answerWithin(this.switching, SWITCH_WAIT_MS);
99
143
  this.stopped = true;
100
- const { source, encoder, startedAt } = this;
101
- if (encoder === undefined || startedAt === undefined)
102
- return [];
144
+ }
145
+ /**
146
+ * Runs the end of a recording with the encoder killed once it has had
147
+ * `CLOSE_TIMEOUT_MS`: an ffmpeg that stops reading holds a frame's write,
148
+ * and the window switch and the last snapshot that wait on it, before its
149
+ * own close would start a timer.
150
+ */
151
+ async withinCloseTime(end) {
152
+ const stuck = setTimeout(() => this.encoder?.kill(), CLOSE_TIMEOUT_MS);
103
153
  try {
104
- await this.snap();
105
- await source?.stop();
154
+ return await end();
106
155
  }
107
156
  finally {
108
- this.source = undefined;
109
- await encoder.close().catch((cause) => {
110
- if (!existsSync(this.absolute)) {
111
- throw new EngineError('ENGINE_FAILURE', `the video ${this.relative} could not be finalized: ${cause instanceof Error ? cause.message : String(cause)}`, { retryable: false, cause });
112
- }
113
- });
157
+ clearTimeout(stuck);
114
158
  }
115
- return existsSync(this.absolute) ? [{ path: this.relative, startedAt }] : [];
116
159
  }
117
160
  /**
118
161
  * Adds the shown window as it stands to the video. A screencast sends a
@@ -123,17 +166,21 @@ export class Recorder {
123
166
  const { source, encoder } = this;
124
167
  if (source === undefined || encoder === undefined || source.page.isClosed() || !this.allowed(source.page))
125
168
  return;
169
+ const { generation } = source.page;
126
170
  const screen = await answerWithin(source.page.session.send('Page.captureScreenshot', { format: 'jpeg', quality: JPEG_QUALITY }), LAST_SCREEN_MS);
127
- if (screen !== undefined)
128
- await encoder.frame(Buffer.from(screen.data, 'base64'));
171
+ // A window that loaded another document while it was captured may show what no frame may: the capture is dropped.
172
+ if (screen === undefined || source.page.generation !== generation || !this.allowed(source.page))
173
+ return;
174
+ await encoder.frame(Buffer.from(screen.data, 'base64'));
129
175
  }
130
176
  /** Ends a recording nobody collects: the file it wrote is removed. */
131
177
  async abandon() {
132
- await this.switching;
133
- this.stopped = true;
134
- await this.source?.stop();
135
- this.source = undefined;
136
- await this.encoder?.abort();
178
+ await this.withinCloseTime(async () => {
179
+ await this.settleSwitching();
180
+ await this.source?.stop();
181
+ this.source = undefined;
182
+ await this.encoder?.abort();
183
+ });
137
184
  }
138
185
  }
139
186
  /**
@@ -212,6 +259,12 @@ class FrameEncoder {
212
259
  if (code !== 0)
213
260
  throw new Error(`ffmpeg ${signal === null ? `exited with ${String(code)}` : `was killed (${signal})`}${this.stderr === '' ? '' : `: ${this.stderr.trim()}`}`);
214
261
  }
262
+ /** Kills the encoder: the frames it holds are dropped, and a write waiting on it returns. */
263
+ kill() {
264
+ this.process.kill('SIGKILL');
265
+ // Its input closes on this side too, so a write waiting for room in it returns whatever still holds the pipe.
266
+ this.process.stdin?.destroy();
267
+ }
215
268
  /** Kills the encoder and removes what it wrote. */
216
269
  async abort() {
217
270
  this.process.kill('SIGKILL');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2e-dev/electron",
3
- "version": "0.0.1-nightly-20261130030410",
3
+ "version": "0.1.0",
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.26.0-nightly-20261130030410",
46
- "e2e": "0.26.0-nightly-20261130030410",
45
+ "@e2e-dev/core": ">=0.25.1 <1",
46
+ "e2e": ">=0.25.1 <1",
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.0-nightly-20261130030410",
55
+ "@e2e-dev/core": "0.26.0",
56
56
  "@napi-rs/image": "1.16.0",
57
57
  "@types/node": "26.6.11",
58
58
  "devtools-protocol": "0.0.1756183",
59
- "e2e": "0.26.0-nightly-20261130030410",
59
+ "e2e": "0.26.0",
60
60
  "electron": "45.5.0",
61
61
  "typescript": "7.0.2",
62
62
  "vitest": "5.1.2"