@app-studio/qa-browser-darwin-arm64 0.10.0 → 0.10.2
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/bin/lightpanda +2 -2
- package/bin/lightpanda-build.json +4 -4
- package/bin/lightpanda-capture.mjs +46 -12
- package/bin/source.tar.gz +0 -0
- package/package.json +1 -1
package/bin/lightpanda
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/lightpanda
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 89076504 bytes
|
|
4
|
+
sha256: cedfc473368639c152d598de4f5a2461b4e731909ad5dc6036ff207e3021e698
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"webm",
|
|
12
12
|
"gif"
|
|
13
13
|
],
|
|
14
|
-
"build": "
|
|
14
|
+
"build": "release-fast",
|
|
15
15
|
"source": {
|
|
16
16
|
"commit": "56e32da6e2929daa88fe41e2544daae95720f0be",
|
|
17
17
|
"dirty": true
|
|
18
18
|
},
|
|
19
19
|
"files": {
|
|
20
|
-
"lightpanda": "
|
|
21
|
-
"lightpanda-capture.mjs": "
|
|
20
|
+
"lightpanda": "cedfc473368639c152d598de4f5a2461b4e731909ad5dc6036ff207e3021e698",
|
|
21
|
+
"lightpanda-capture.mjs": "4674247178fe8cb209f11984b770d612b7c86bfc5140568c66cc8cc6fa406a9f",
|
|
22
22
|
"LICENSE": "8486a10c4393cee1c25392769ddd3b2d6c242d6ec7928e1414efff7dfb2f07ef",
|
|
23
|
-
"source.tar.gz": "
|
|
23
|
+
"source.tar.gz": "25dafa7849027afbe5c3df5a51bb320e10f5adae1ecd4b31ec1ac13c4daffaf8"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -15,10 +15,19 @@ const sleep = (ms, signal) => new Promise(resolve => {
|
|
|
15
15
|
signal?.addEventListener('abort', done, { once: true });
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
async function bounded(task, milliseconds, operation) {
|
|
19
|
+
let timer;
|
|
20
|
+
try {
|
|
21
|
+
return await Promise.race([task, new Promise((_, reject) => {
|
|
22
|
+
timer = setTimeout(() => reject(new Error(`${operation} timed out after ${milliseconds}ms`)), milliseconds);
|
|
23
|
+
})]);
|
|
24
|
+
} finally { clearTimeout(timer); }
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
async function capture(cdp, fullPage = false) {
|
|
19
|
-
const { data } = await cdp.send('Page.captureScreenshot', {
|
|
28
|
+
const { data } = await bounded(cdp.send('Page.captureScreenshot', {
|
|
20
29
|
format: 'png', captureBeyondViewport: fullPage,
|
|
21
|
-
});
|
|
30
|
+
}), 3000, 'Native frame capture');
|
|
22
31
|
const png = Buffer.from(data, 'base64');
|
|
23
32
|
if (png.length < 24 || !png.subarray(0, 8).equals(Buffer.from('89504e470d0a1a0a', 'hex'))) {
|
|
24
33
|
throw new Error('The browser returned an invalid PNG');
|
|
@@ -37,7 +46,10 @@ export async function screenshot(cdp, { path, fullPage = true }) {
|
|
|
37
46
|
* Sample the native viewport into MP4, WebM or GIF. Only one CDP capture and one
|
|
38
47
|
* encoder write run at a time. Missed intervals hold the preceding image,
|
|
39
48
|
* preserving wall-clock duration without building a queue of PNGs.
|
|
40
|
-
*
|
|
49
|
+
* Completion or abort appends one final viewport sample before bounded
|
|
50
|
+
* finalization, so the last encoded frame represents the completed run. This
|
|
51
|
+
* adds at most one frame period to the clip. A stalled owned encoder is
|
|
52
|
+
* terminated; the caller's browser page remains open.
|
|
41
53
|
*/
|
|
42
54
|
export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg = 'ffmpeg', signal } = {}) {
|
|
43
55
|
if (!Number.isFinite(fps) || fps < 1 || fps > 60) throw new Error('fps must be between 1 and 60');
|
|
@@ -74,12 +86,34 @@ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg =
|
|
|
74
86
|
encoder.once('error', error => { spawnError = error; });
|
|
75
87
|
encoder.once('close', code => resolve(code));
|
|
76
88
|
});
|
|
77
|
-
const write = png => new Promise((resolve, reject) =>
|
|
89
|
+
const write = png => bounded(new Promise((resolve, reject) =>
|
|
90
|
+
encoder.stdin.write(png, error => error ? reject(error) : resolve())
|
|
91
|
+
), 2000, 'FFmpeg input');
|
|
92
|
+
const terminate = async () => {
|
|
93
|
+
encoder.stdin.destroy();
|
|
94
|
+
if (encoder.exitCode === null && encoder.signalCode === null) encoder.kill('SIGTERM');
|
|
95
|
+
try { await bounded(closed, 1000, 'FFmpeg shutdown'); }
|
|
96
|
+
catch {
|
|
97
|
+
encoder.kill('SIGKILL');
|
|
98
|
+
await bounded(closed, 1000, 'FFmpeg forced shutdown').catch(() => {
|
|
99
|
+
// Do not retain Node handles if the OS has not reaped the killed child.
|
|
100
|
+
encoder.stderr.destroy();
|
|
101
|
+
encoder.unref();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
78
105
|
const started = performance.now();
|
|
79
106
|
const period = 1000 / fps;
|
|
80
107
|
const total = Math.ceil(duration * fps);
|
|
81
108
|
let frames = 0;
|
|
82
109
|
let previous = first;
|
|
110
|
+
const sample = async () => {
|
|
111
|
+
const png = await capture(cdp);
|
|
112
|
+
if (png.readUInt32BE(16) !== width || png.readUInt32BE(20) !== height) {
|
|
113
|
+
throw new Error('The viewport size changed during recording');
|
|
114
|
+
}
|
|
115
|
+
return png;
|
|
116
|
+
};
|
|
83
117
|
try {
|
|
84
118
|
while (frames < total && (frames === 0 || !signal?.aborted)) {
|
|
85
119
|
await write(previous);
|
|
@@ -87,25 +121,25 @@ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg =
|
|
|
87
121
|
if (frames === total) break;
|
|
88
122
|
await sleep(started + frames * period - performance.now(), signal);
|
|
89
123
|
if (signal?.aborted) break;
|
|
90
|
-
const current = await
|
|
91
|
-
if (current.readUInt32BE(16) !== width || current.readUInt32BE(20) !== height) {
|
|
92
|
-
throw new Error('The viewport size changed during recording');
|
|
93
|
-
}
|
|
124
|
+
const current = await sample();
|
|
94
125
|
const due = Math.min(total, Math.floor((performance.now() - started) / period));
|
|
95
126
|
// Repeat the previous sample for intervals spent capturing/encoding.
|
|
96
127
|
while (frames < due && !signal?.aborted) { await write(previous); frames++; }
|
|
97
128
|
previous = current;
|
|
98
129
|
}
|
|
130
|
+
// Abort may arrive between low-FPS samples or during an in-flight capture.
|
|
131
|
+
// Capture after sampling stops, while the caller still owns the open page;
|
|
132
|
+
// serialize this final sample through the same bounded encoder write.
|
|
133
|
+
await write(await sample());
|
|
134
|
+
frames++;
|
|
99
135
|
encoder.stdin.end();
|
|
100
|
-
const code = await closed;
|
|
136
|
+
const code = await bounded(closed, 5000, 'FFmpeg finalization');
|
|
101
137
|
if (code !== 0) throw new Error(spawnError?.message ?? `FFmpeg exited with ${code}: ${diagnostics.trim()}`);
|
|
102
138
|
// Publish only a finalized file. link() fails if the destination exists.
|
|
103
139
|
await link(output, resolve(path));
|
|
104
140
|
return { frames, duration: frames / fps, width, height };
|
|
105
141
|
} catch (error) {
|
|
106
|
-
|
|
107
|
-
encoder.kill();
|
|
108
|
-
await closed;
|
|
142
|
+
await terminate();
|
|
109
143
|
if (spawnError) throw new Error(`Cannot start FFmpeg: ${spawnError.message}`, { cause: error });
|
|
110
144
|
throw error;
|
|
111
145
|
} finally {
|
package/bin/source.tar.gz
CHANGED
|
Binary file
|