screw-bugs 0.1.10 → 0.1.12
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 +68 -28
- package/dist/browser-playwright/launch.d.ts +4 -0
- package/dist/browser-playwright/launch.js +83 -6
- package/dist/browser-playwright/page.d.ts +39 -2
- package/dist/browser-playwright/page.js +80 -3
- package/dist/browser-playwright/recorder.d.ts +79 -17
- package/dist/browser-playwright/recorder.js +193 -34
- package/dist/browser-playwright/sign-in.js +36 -5
- package/dist/build-info.json +3 -3
- package/dist/cli/commands.js +4 -4
- package/dist/cli/doctor.d.ts +6 -1
- package/dist/cli/doctor.js +50 -2
- package/dist/cli/mcp.js +9 -3
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, FileSystem } from 'effect';
|
|
1
|
+
import { type Cause, Effect, FileSystem } from 'effect';
|
|
2
2
|
import { ChildProcessSpawner } from 'effect/process';
|
|
3
3
|
import type { Page } from 'playwright-core';
|
|
4
4
|
/**
|
|
@@ -44,21 +44,72 @@ export interface FrameSize {
|
|
|
44
44
|
readonly width: number;
|
|
45
45
|
readonly height: number;
|
|
46
46
|
}
|
|
47
|
+
/** `1280×800`. */
|
|
48
|
+
export declare const sizeText: (size: FrameSize) => string;
|
|
49
|
+
declare const RecordingFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
50
|
+
readonly _tag: "RecordingFailed";
|
|
51
|
+
} & Readonly<A>;
|
|
52
|
+
/**
|
|
53
|
+
* Why a session's video could not be recorded, by what went wrong, so `doctor` can tell them
|
|
54
|
+
* apart: the browser's frames were all left out for their size (`frames_rejected`), the tab sent
|
|
55
|
+
* none (`no_frames`), ffmpeg could not start or encode (`encoder`), or the video could not be
|
|
56
|
+
* written or read back (`output`).
|
|
57
|
+
*/
|
|
58
|
+
export declare class RecordingFailed extends RecordingFailed_base<{
|
|
59
|
+
readonly reason: 'frames_rejected' | 'no_frames' | 'encoder' | 'output';
|
|
60
|
+
readonly message: string;
|
|
61
|
+
readonly cause?: unknown;
|
|
62
|
+
}> {
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* What the recorder says when every frame the browser sent was left out for its size: the last
|
|
66
|
+
* such size, against the video's. A window smaller than the viewport (a headless window on
|
|
67
|
+
* macOS whose contents lost the toolbar's height) sends frames cut short.
|
|
68
|
+
*/
|
|
69
|
+
export declare const rejectedFramesText: (observed: FrameSize | undefined, count: number, video: FrameSize) => string;
|
|
47
70
|
/** A JPEG's size, from its first start-of-frame segment; undefined when it has none. */
|
|
48
71
|
export declare const jpegSize: (bytes: Uint8Array) => FrameSize | undefined;
|
|
49
|
-
/**
|
|
50
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Whether a frame of `frame`'s size shows the page whole in a video of `video`'s: the video's
|
|
74
|
+
* size, a little smaller or a pixel larger; or, from a window wider or taller than the viewport
|
|
75
|
+
* (`window`, see `windowFrames`), up to the window's size, the viewport in its top left corner,
|
|
76
|
+
* which the video crops. A frame larger than the window (a device-pixel capture's, in a browser at
|
|
77
|
+
* 1x) is never one.
|
|
78
|
+
*/
|
|
79
|
+
export declare const fits: (frame: FrameSize, video: FrameSize, window?: FrameSize) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The most a window of `window`'s size lets in once a frame of `first`'s size was kept: as tall as
|
|
82
|
+
* that frame and a pixel, no more than the window, and as wide as the window. The window's height
|
|
83
|
+
* can count room its contents do not have (macOS keeps a toolbar's: 1280×887 for 1280×800 of
|
|
84
|
+
* contents), and a full-page screenshot makes the screencast send one frame the size of the page,
|
|
85
|
+
* whose top left corner is the page's, not the viewport's: within the window's size, the video
|
|
86
|
+
* would show it cropped, and keep showing it until the page paints again. The first kept frame is
|
|
87
|
+
* as tall as the window's contents: the session waits for it (`Recorder.ready`) before any step,
|
|
88
|
+
* and frames from before the window was fit are shorter than the video, never kept. Its width is
|
|
89
|
+
* not bounded the same way: a phone's frames in a window wider than it (Chrome 158 on macOS) are
|
|
90
|
+
* the window's width at first and the viewport's after a navigation, and either may come first.
|
|
91
|
+
*/
|
|
92
|
+
export declare const firstBound: (first: FrameSize, window: FrameSize | undefined) => {
|
|
93
|
+
width: number;
|
|
94
|
+
height: number;
|
|
95
|
+
} | undefined;
|
|
51
96
|
/**
|
|
52
97
|
* Which frames go on the video, and where: a frame's time on the video is its paint time (epoch
|
|
53
98
|
* ms) after the first kept frame's, so the video starts at its first frame, as Playwright's does.
|
|
99
|
+
* `window` is as for `fits` until a frame is kept; from then on the frames it lets in are at most
|
|
100
|
+
* as tall as that first frame and a pixel (`firstBound`).
|
|
54
101
|
*/
|
|
55
|
-
export declare const frameGate: (video: FrameSize) => {
|
|
102
|
+
export declare const frameGate: (video: FrameSize, window?: FrameSize) => {
|
|
56
103
|
/** A screenshot starts being taken `at`; call the result when it was taken. */
|
|
57
104
|
hold: (at: number) => (end: number) => void;
|
|
58
105
|
/**
|
|
59
106
|
* The frame's time on the video in ms when it is kept, else undefined: when it does not fit
|
|
60
|
-
* (`size` undefined is a frame that could not be read)
|
|
61
|
-
* taken
|
|
107
|
+
* (`size` undefined is a frame that could not be read) or was painted while a screenshot was
|
|
108
|
+
* taken. Frames come in the order the page painted them, but not always stamped so: Chrome
|
|
109
|
+
* stamps the frame a screencast sends when it starts (again, `startRecorder`) with when it
|
|
110
|
+
* started, which can be before the last frame it sent was stamped. A frame stamped at or
|
|
111
|
+
* before the last kept one goes a millisecond after it, so the video's frames only go forward
|
|
112
|
+
* and the latest is always the page's latest state.
|
|
62
113
|
*/
|
|
63
114
|
admit: (size: FrameSize | undefined, timestamp: number) => number | undefined;
|
|
64
115
|
/** When the first kept frame was painted, in epoch ms. */
|
|
@@ -101,7 +152,10 @@ export declare const ffmpegArgs: (size: FrameSize, file: string) => ReadonlyArra
|
|
|
101
152
|
export interface Recorder {
|
|
102
153
|
/** When the first frame on the video was painted, in epoch ms; waits for it. */
|
|
103
154
|
readonly firstFrame: Effect.Effect<number>;
|
|
104
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Runs `effect` (a screenshot) keeping the frames painted meanwhile off the video, then starts
|
|
157
|
+
* the screencast again, so the page as it is after it comes too.
|
|
158
|
+
*/
|
|
105
159
|
readonly hold: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
106
160
|
/**
|
|
107
161
|
* Ends the video and saves it at its path: why it could not be, else undefined. Call once the
|
|
@@ -113,27 +167,34 @@ export interface Recorder {
|
|
|
113
167
|
* writes, for at most `READY_TIMEOUT_MS`; fails when ffmpeg has ended instead, or has not
|
|
114
168
|
* opened it by then (no frame came, or it is stuck).
|
|
115
169
|
*/
|
|
116
|
-
readonly ready: Effect.Effect<void,
|
|
117
|
-
/**
|
|
170
|
+
readonly ready: Effect.Effect<void, RecordingFailed>;
|
|
171
|
+
/**
|
|
172
|
+
* Why the video stopped being recorded before `finish`: ffmpeg ended early, or the screencast
|
|
173
|
+
* could not be started again on a tab still open.
|
|
174
|
+
*/
|
|
118
175
|
readonly stopped: Effect.Effect<string | undefined>;
|
|
119
176
|
}
|
|
177
|
+
/** The kind of problem a session's close gave about its video (`finish`, or its timeout). */
|
|
178
|
+
export declare const videoProblemReason: (problem: string) => RecordingFailed['reason'];
|
|
120
179
|
/**
|
|
121
180
|
* Records `page`'s video into `file` (a `.webm`) with the ffmpeg at `ffmpeg`, at `size` (see
|
|
122
|
-
* `videoSize`). Written to a file beside it first and
|
|
123
|
-
* process dies leaves no half-written video where a
|
|
124
|
-
* the screencast cannot start; with the scope, ffmpeg
|
|
181
|
+
* `videoSize`), from frames up to `window` (see `fits`). Written to a file beside it first and
|
|
182
|
+
* moved there by `finish`, so a run whose process dies leaves no half-written video where a
|
|
183
|
+
* video is looked for. Fails when ffmpeg or the screencast cannot start; with the scope, ffmpeg
|
|
184
|
+
* and the screencast are stopped.
|
|
125
185
|
*/
|
|
126
186
|
export declare const startRecorder: (page: Page, options: {
|
|
127
187
|
readonly ffmpeg: string;
|
|
128
188
|
readonly file: string;
|
|
129
189
|
readonly size: FrameSize;
|
|
190
|
+
readonly window?: FrameSize | undefined;
|
|
130
191
|
}) => Effect.Effect<{
|
|
131
192
|
firstFrame: Effect.Effect<number, never, never>;
|
|
132
193
|
hold: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
133
194
|
finish: Effect.Effect<string | undefined, never, never>;
|
|
134
|
-
ready: Effect.Effect<undefined,
|
|
195
|
+
ready: Effect.Effect<undefined, RecordingFailed, never>;
|
|
135
196
|
stopped: Effect.Effect<string | undefined, never, never>;
|
|
136
|
-
},
|
|
197
|
+
}, RecordingFailed, ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | import("effect/Scope").Scope>;
|
|
137
198
|
/**
|
|
138
199
|
* How a session with a video at `path` (in the folder `dir`, made when missing) is recorded with
|
|
139
200
|
* the ffmpeg at `ffmpeg`, on the platform this runs on.
|
|
@@ -144,11 +205,12 @@ export declare const videoRecording: (video: {
|
|
|
144
205
|
readonly ffmpeg: string;
|
|
145
206
|
}) => Effect.Effect<{
|
|
146
207
|
path: string;
|
|
147
|
-
record: (page: Page, size: FrameSize) => Effect.Effect<{
|
|
208
|
+
record: (page: Page, size: FrameSize, window?: FrameSize) => Effect.Effect<{
|
|
148
209
|
firstFrame: Effect.Effect<number, never, never>;
|
|
149
210
|
hold: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
150
211
|
finish: Effect.Effect<string | undefined, never, never>;
|
|
151
|
-
ready: Effect.Effect<undefined,
|
|
212
|
+
ready: Effect.Effect<undefined, RecordingFailed, never>;
|
|
152
213
|
stopped: Effect.Effect<string | undefined, never, never>;
|
|
153
|
-
},
|
|
214
|
+
}, RecordingFailed, import("effect/Scope").Scope>;
|
|
154
215
|
}, never, ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem>;
|
|
216
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Clock, Deferred, Effect, Exit, FileSystem, Queue, Stream } from 'effect';
|
|
1
|
+
import { Clock, Data, Deferred, Effect, Exit, FileSystem, Queue, Stream } from 'effect';
|
|
2
2
|
import { ChildProcess, ChildProcessSpawner } from 'effect/process';
|
|
3
3
|
/**
|
|
4
4
|
* A session's video, recorded by screw-bugs itself rather than by Playwright's `recordVideo`:
|
|
@@ -43,6 +43,25 @@ export const BACKLOG_FRAMES = 10 * VIDEO_FPS;
|
|
|
43
43
|
export const READY_TIMEOUT_MS = 3_000;
|
|
44
44
|
/** How often whether it has is looked at. */
|
|
45
45
|
const READY_POLL = '50 millis';
|
|
46
|
+
/** `1280×800`. */
|
|
47
|
+
export const sizeText = (size) => `${size.width}×${size.height}`;
|
|
48
|
+
/**
|
|
49
|
+
* Why a session's video could not be recorded, by what went wrong, so `doctor` can tell them
|
|
50
|
+
* apart: the browser's frames were all left out for their size (`frames_rejected`), the tab sent
|
|
51
|
+
* none (`no_frames`), ffmpeg could not start or encode (`encoder`), or the video could not be
|
|
52
|
+
* written or read back (`output`).
|
|
53
|
+
*/
|
|
54
|
+
export class RecordingFailed extends Data.TaggedError('RecordingFailed') {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* What the recorder says when every frame the browser sent was left out for its size: the last
|
|
58
|
+
* such size, against the video's. A window smaller than the viewport (a headless window on
|
|
59
|
+
* macOS whose contents lost the toolbar's height) sends frames cut short.
|
|
60
|
+
*/
|
|
61
|
+
export const rejectedFramesText = (observed, count, video) => observed === undefined
|
|
62
|
+
? `the browser sent ${count} frame${count === 1 ? '' : 's'} that could not be read, so ffmpeg got none.`
|
|
63
|
+
: `the browser sent ${sizeText(observed)} frames, but the video needs ${sizeText(video)} ` +
|
|
64
|
+
`(${count} frame${count === 1 ? '' : 's'} left out), so ffmpeg got none.`;
|
|
46
65
|
/** A JPEG's size, from its first start-of-frame segment; undefined when it has none. */
|
|
47
66
|
export const jpegSize = (bytes) => {
|
|
48
67
|
if (bytes[0] !== 0xff || bytes[1] !== 0xd8)
|
|
@@ -73,16 +92,40 @@ export const jpegSize = (bytes) => {
|
|
|
73
92
|
}
|
|
74
93
|
return undefined;
|
|
75
94
|
};
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Whether a frame of `frame`'s size shows the page whole in a video of `video`'s: the video's
|
|
97
|
+
* size, a little smaller or a pixel larger; or, from a window wider or taller than the viewport
|
|
98
|
+
* (`window`, see `windowFrames`), up to the window's size, the viewport in its top left corner,
|
|
99
|
+
* which the video crops. A frame larger than the window (a device-pixel capture's, in a browser at
|
|
100
|
+
* 1x) is never one.
|
|
101
|
+
*/
|
|
102
|
+
export const fits = (frame, video, window) => frame.width <= Math.max(video.width + 1, window?.width ?? 0) &&
|
|
103
|
+
frame.height <= Math.max(video.height + 1, window?.height ?? 0) &&
|
|
79
104
|
frame.width >= video.width - FRAME_SLACK &&
|
|
80
105
|
frame.height >= video.height - FRAME_SLACK;
|
|
106
|
+
/**
|
|
107
|
+
* The most a window of `window`'s size lets in once a frame of `first`'s size was kept: as tall as
|
|
108
|
+
* that frame and a pixel, no more than the window, and as wide as the window. The window's height
|
|
109
|
+
* can count room its contents do not have (macOS keeps a toolbar's: 1280×887 for 1280×800 of
|
|
110
|
+
* contents), and a full-page screenshot makes the screencast send one frame the size of the page,
|
|
111
|
+
* whose top left corner is the page's, not the viewport's: within the window's size, the video
|
|
112
|
+
* would show it cropped, and keep showing it until the page paints again. The first kept frame is
|
|
113
|
+
* as tall as the window's contents: the session waits for it (`Recorder.ready`) before any step,
|
|
114
|
+
* and frames from before the window was fit are shorter than the video, never kept. Its width is
|
|
115
|
+
* not bounded the same way: a phone's frames in a window wider than it (Chrome 158 on macOS) are
|
|
116
|
+
* the window's width at first and the viewport's after a navigation, and either may come first.
|
|
117
|
+
*/
|
|
118
|
+
export const firstBound = (first, window) => window === undefined
|
|
119
|
+
? undefined
|
|
120
|
+
: { width: window.width, height: Math.min(window.height, first.height + 1) };
|
|
81
121
|
/**
|
|
82
122
|
* Which frames go on the video, and where: a frame's time on the video is its paint time (epoch
|
|
83
123
|
* ms) after the first kept frame's, so the video starts at its first frame, as Playwright's does.
|
|
124
|
+
* `window` is as for `fits` until a frame is kept; from then on the frames it lets in are at most
|
|
125
|
+
* as tall as that first frame and a pixel (`firstBound`).
|
|
84
126
|
*/
|
|
85
|
-
export const frameGate = (video) => {
|
|
127
|
+
export const frameGate = (video, window) => {
|
|
128
|
+
let bound = window;
|
|
86
129
|
/** Screenshots being taken (`end` undefined) or taken, by when, in epoch ms. */
|
|
87
130
|
let holds = [];
|
|
88
131
|
let first;
|
|
@@ -99,15 +142,20 @@ export const frameGate = (video) => {
|
|
|
99
142
|
},
|
|
100
143
|
/**
|
|
101
144
|
* The frame's time on the video in ms when it is kept, else undefined: when it does not fit
|
|
102
|
-
* (`size` undefined is a frame that could not be read)
|
|
103
|
-
* taken
|
|
145
|
+
* (`size` undefined is a frame that could not be read) or was painted while a screenshot was
|
|
146
|
+
* taken. Frames come in the order the page painted them, but not always stamped so: Chrome
|
|
147
|
+
* stamps the frame a screencast sends when it starts (again, `startRecorder`) with when it
|
|
148
|
+
* started, which can be before the last frame it sent was stamped. A frame stamped at or
|
|
149
|
+
* before the last kept one goes a millisecond after it, so the video's frames only go forward
|
|
150
|
+
* and the latest is always the page's latest state.
|
|
104
151
|
*/
|
|
105
152
|
admit: (size, timestamp) => {
|
|
106
|
-
if (size === undefined || !fits(size, video) || held(timestamp))
|
|
107
|
-
return undefined;
|
|
108
|
-
const ms = Math.round(timestamp - (first ?? timestamp));
|
|
109
|
-
if (lastMs !== undefined && ms <= lastMs)
|
|
153
|
+
if (size === undefined || !fits(size, video, bound) || held(timestamp))
|
|
110
154
|
return undefined;
|
|
155
|
+
const painted = Math.round(timestamp - (first ?? timestamp));
|
|
156
|
+
const ms = lastMs !== undefined && painted <= lastMs ? lastMs + 1 : painted;
|
|
157
|
+
if (first === undefined)
|
|
158
|
+
bound = firstBound(size, bound);
|
|
111
159
|
first ??= timestamp;
|
|
112
160
|
lastMs = ms;
|
|
113
161
|
// A screenshot taken before this frame was painted cannot hold back any later frame.
|
|
@@ -252,7 +300,8 @@ export const ffmpegArgs = (size, file) => {
|
|
|
252
300
|
`-b:v ${Math.round(pixelRateScale * 1000)}k -threads ${threads}`,
|
|
253
301
|
`-tile-columns ${Math.ceil(Math.log2(threads))} -row-mt 1`,
|
|
254
302
|
// A frame a little smaller than the video (see `FRAME_SLACK`) is padded, as Playwright does;
|
|
255
|
-
// one a pixel larger loses its odd row or column first
|
|
303
|
+
// one a pixel larger loses its odd row or column first, and one of a window wider or taller
|
|
304
|
+
// than the viewport (`fits`) all but the viewport in its corner. Cropped before padded: `pad` cuts
|
|
256
305
|
// an odd-height 4:2:0 frame (the JPEG's) to even and pads it back, greying its last row.
|
|
257
306
|
`-vf crop='min(iw,${w})':'min(ih,${h})':0:0,pad=${w}:${h}:0:0:gray`,
|
|
258
307
|
'-f webm',
|
|
@@ -260,31 +309,44 @@ export const ffmpegArgs = (size, file) => {
|
|
|
260
309
|
.flatMap((options) => options.split(' '))
|
|
261
310
|
.concat(file);
|
|
262
311
|
};
|
|
312
|
+
/** The kind of problem a session's close gave about its video (`finish`, or its timeout). */
|
|
313
|
+
export const videoProblemReason = (problem) => problem.includes('never showed a frame')
|
|
314
|
+
? 'no_frames'
|
|
315
|
+
: problem.includes('ffmpeg') || problem.includes('not saved within')
|
|
316
|
+
? 'encoder'
|
|
317
|
+
: 'output';
|
|
263
318
|
const ffmpegEnded = (code) => typeof code === 'number' ? `ffmpeg ended with code ${code}` : `ffmpeg failed: ${code}`;
|
|
264
319
|
/**
|
|
265
320
|
* Records `page`'s video into `file` (a `.webm`) with the ffmpeg at `ffmpeg`, at `size` (see
|
|
266
|
-
* `videoSize`). Written to a file beside it first and
|
|
267
|
-
* process dies leaves no half-written video where a
|
|
268
|
-
* the screencast cannot start; with the scope, ffmpeg
|
|
321
|
+
* `videoSize`), from frames up to `window` (see `fits`). Written to a file beside it first and
|
|
322
|
+
* moved there by `finish`, so a run whose process dies leaves no half-written video where a
|
|
323
|
+
* video is looked for. Fails when ffmpeg or the screencast cannot start; with the scope, ffmpeg
|
|
324
|
+
* and the screencast are stopped.
|
|
269
325
|
*/
|
|
270
326
|
export const startRecorder = (page, options) => Effect.gen(function* () {
|
|
271
327
|
const fs = yield* FileSystem.FileSystem;
|
|
272
328
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
273
329
|
const clock = yield* Effect.clockWith((clock) => Effect.succeed(clock));
|
|
274
330
|
const partial = `${options.file}.part`;
|
|
275
|
-
const gate = frameGate(options.size);
|
|
331
|
+
const gate = frameGate(options.size, options.window);
|
|
276
332
|
// Bounded, so an ffmpeg that stops reading never makes frames pile up in memory.
|
|
277
333
|
const queue = yield* Queue.make({
|
|
278
334
|
capacity: BACKLOG_FRAMES,
|
|
279
335
|
strategy: 'dropping',
|
|
280
336
|
});
|
|
281
337
|
const first = yield* Deferred.make();
|
|
282
|
-
const handle = yield* spawner
|
|
338
|
+
const handle = yield* spawner
|
|
339
|
+
.spawn(ChildProcess.make(options.ffmpeg, [...ffmpegArgs(options.size, partial)], {
|
|
283
340
|
stdin: Stream.fromQueue(queue),
|
|
284
341
|
stdout: 'ignore',
|
|
285
342
|
stderr: 'ignore',
|
|
286
343
|
forceKillAfter: FFMPEG_KILL_AFTER,
|
|
287
|
-
}))
|
|
344
|
+
}))
|
|
345
|
+
.pipe(Effect.mapError((error) => new RecordingFailed({
|
|
346
|
+
reason: 'encoder',
|
|
347
|
+
message: `ffmpeg did not start: ${error.message}`,
|
|
348
|
+
cause: error,
|
|
349
|
+
})));
|
|
288
350
|
// Once ffmpeg has ended, frames are no longer queued for it.
|
|
289
351
|
const exited = yield* Deferred.make();
|
|
290
352
|
let endedWith;
|
|
@@ -293,6 +355,9 @@ export const startRecorder = (page, options) => Effect.gen(function* () {
|
|
|
293
355
|
}), Deferred.succeed(exited, code))), Effect.andThen(Queue.shutdown(queue)), Effect.forkScoped);
|
|
294
356
|
Queue.offerUnsafe(queue, matroskaHeader());
|
|
295
357
|
let ended = false;
|
|
358
|
+
/** Frames left out for their size (or unreadable) before the first kept one, and the last. */
|
|
359
|
+
let rejected = { count: 0, size: undefined };
|
|
360
|
+
let seen = 0;
|
|
296
361
|
const pacer = framePacer();
|
|
297
362
|
/** The latest frame on the video (written, or waiting in `pacer`). */
|
|
298
363
|
let last;
|
|
@@ -300,7 +365,12 @@ export const startRecorder = (page, options) => Effect.gen(function* () {
|
|
|
300
365
|
const onFrame = ({ data, timestamp, }) => {
|
|
301
366
|
if (ended)
|
|
302
367
|
return;
|
|
303
|
-
|
|
368
|
+
seen++;
|
|
369
|
+
const size = jpegSize(data);
|
|
370
|
+
if (gate.first() === undefined &&
|
|
371
|
+
(size === undefined || !fits(size, options.size, options.window)))
|
|
372
|
+
rejected = { count: rejected.count + 1, size };
|
|
373
|
+
const ms = gate.admit(size, timestamp);
|
|
304
374
|
if (ms === undefined)
|
|
305
375
|
return;
|
|
306
376
|
const now = pacer.add(data, ms);
|
|
@@ -312,16 +382,70 @@ export const startRecorder = (page, options) => Effect.gen(function* () {
|
|
|
312
382
|
if (now.length > 0)
|
|
313
383
|
Deferred.doneUnsafe(first, Exit.succeed(gate.first()));
|
|
314
384
|
};
|
|
315
|
-
|
|
385
|
+
// Boundary: Playwright's screencast is a promise API, and the tab tells of loads by events.
|
|
386
|
+
const cast = () => page.screencast.start({
|
|
316
387
|
// Two pixels more than the video, so the page's odd last row or column comes as it is:
|
|
317
388
|
// the screencast shrinks, resampling, a frame not smaller than the size it is asked for
|
|
318
|
-
// (1206x2043 for 1206x2043, as for 1206x2042; not for 1206x2044).
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
389
|
+
// (1206x2043 for 1206x2043, as for 1206x2042; not for 1206x2044). From a window larger
|
|
390
|
+
// than the viewport, as large as the window, so the viewport in its corner is not shrunk.
|
|
391
|
+
size: {
|
|
392
|
+
width: Math.max(options.size.width, options.window?.width ?? 0) + 2,
|
|
393
|
+
height: Math.max(options.size.height, options.window?.height ?? 0) + 2,
|
|
394
|
+
},
|
|
395
|
+
onFrame,
|
|
396
|
+
});
|
|
397
|
+
let casting;
|
|
398
|
+
let released = false;
|
|
399
|
+
let restarting = Promise.resolve();
|
|
400
|
+
/** Why the screencast could not be started again on a tab still open, once it could not. */
|
|
401
|
+
let restartFailed;
|
|
402
|
+
/**
|
|
403
|
+
* Starts the screencast again, after the restarts asked for before; it sends the page as it is
|
|
404
|
+
* then. Chrome's headless mode (158, macOS) may send no frame of a document the tab loads after
|
|
405
|
+
* the screencast started: the video would show the page before it for good.
|
|
406
|
+
*/
|
|
407
|
+
const restart = () => {
|
|
408
|
+
restarting = restarting
|
|
409
|
+
.then(async () => {
|
|
410
|
+
if (released)
|
|
411
|
+
return;
|
|
412
|
+
const previous = casting;
|
|
413
|
+
casting = undefined;
|
|
414
|
+
await previous?.dispose().catch(() => undefined);
|
|
415
|
+
let firstError;
|
|
416
|
+
for (let attempt = 0; attempt < 2 && !released && casting === undefined; attempt++)
|
|
417
|
+
try {
|
|
418
|
+
casting = await cast();
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
firstError ??= error;
|
|
422
|
+
// Playwright counts a start that failed as started: stopped first, it can start again.
|
|
423
|
+
await page.screencast.stop().catch(() => undefined);
|
|
424
|
+
// A tab that closed is told of as such (the session's `crashed`), not as this.
|
|
425
|
+
if (attempt === 1 && !page.isClosed())
|
|
426
|
+
restartFailed ??= String(firstError).split('\n')[0];
|
|
427
|
+
}
|
|
428
|
+
})
|
|
429
|
+
.catch(() => undefined);
|
|
430
|
+
};
|
|
431
|
+
yield* Effect.acquireRelease(Effect.tryPromise({
|
|
432
|
+
try: async () => {
|
|
433
|
+
casting = await cast();
|
|
434
|
+
page.on('domcontentloaded', restart);
|
|
435
|
+
page.on('load', restart);
|
|
436
|
+
},
|
|
437
|
+
catch: (error) => new RecordingFailed({
|
|
438
|
+
reason: 'no_frames',
|
|
439
|
+
message: `the screencast did not start: ${String(error).split('\n')[0]}`,
|
|
440
|
+
cause: error,
|
|
322
441
|
}),
|
|
323
|
-
|
|
324
|
-
|
|
442
|
+
}), () => Effect.tryPromise(async () => {
|
|
443
|
+
released = true;
|
|
444
|
+
page.off('domcontentloaded', restart);
|
|
445
|
+
page.off('load', restart);
|
|
446
|
+
await restarting;
|
|
447
|
+
await casting?.dispose();
|
|
448
|
+
}).pipe(Effect.timeoutOption('2 seconds'), Effect.ignore));
|
|
325
449
|
const finish = yield* Effect.cached(Effect.gen(function* () {
|
|
326
450
|
ended = true;
|
|
327
451
|
const now = yield* Clock.currentTimeMillis;
|
|
@@ -347,22 +471,48 @@ export const startRecorder = (page, options) => Effect.gen(function* () {
|
|
|
347
471
|
}));
|
|
348
472
|
return {
|
|
349
473
|
firstFrame: Deferred.await(first),
|
|
350
|
-
|
|
474
|
+
// Frames painted while the screenshot is taken are left out; a page that paints nothing
|
|
475
|
+
// after it (a load whose only frame came meanwhile) would leave the frame before it on the
|
|
476
|
+
// video, so the screencast is started again after it, which sends the page as it is.
|
|
477
|
+
hold: (effect) => Effect.acquireUseRelease(Clock.currentTimeMillis.pipe(Effect.map(gate.hold)), () => effect, (release) => Clock.currentTimeMillis.pipe(Effect.map(release), Effect.andThen(Effect.sync(restart)))),
|
|
351
478
|
finish,
|
|
352
479
|
ready: Effect.gen(function* () {
|
|
353
480
|
yield* Effect.raceFirst(Deferred.await(first), Deferred.await(exited)).pipe(Effect.timeoutOption(READY_TIMEOUT_MS));
|
|
481
|
+
if (endedWith === undefined && gate.first() === undefined) {
|
|
482
|
+
// Nothing went to ffmpeg: say what came instead, the sizes when frames were left out.
|
|
483
|
+
if (rejected.count > 0)
|
|
484
|
+
return yield* new RecordingFailed({
|
|
485
|
+
reason: 'frames_rejected',
|
|
486
|
+
message: rejectedFramesText(rejected.size, rejected.count, options.size),
|
|
487
|
+
});
|
|
488
|
+
if (seen === 0)
|
|
489
|
+
return yield* new RecordingFailed({
|
|
490
|
+
reason: 'no_frames',
|
|
491
|
+
message: `the tab sent no frame within ${READY_TIMEOUT_MS / 1000} s, so ffmpeg got none.`,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
354
494
|
const opened = yield* Effect.gen(function* () {
|
|
355
495
|
while (endedWith === undefined && !(yield* fs.exists(partial)))
|
|
356
496
|
yield* Effect.sleep(READY_POLL);
|
|
357
497
|
}).pipe(Effect.ignore, Effect.timeoutOption(READY_TIMEOUT_MS));
|
|
358
498
|
if (endedWith !== undefined)
|
|
359
|
-
return yield*
|
|
499
|
+
return yield* new RecordingFailed({
|
|
500
|
+
reason: 'encoder',
|
|
501
|
+
message: `${ffmpegEnded(endedWith)}.`,
|
|
502
|
+
});
|
|
360
503
|
if (opened._tag === 'None')
|
|
361
|
-
return yield*
|
|
504
|
+
return yield* new RecordingFailed({
|
|
505
|
+
reason: 'encoder',
|
|
506
|
+
message: `ffmpeg did not start writing the video within ${READY_TIMEOUT_MS / 1000} s.`,
|
|
507
|
+
});
|
|
362
508
|
}),
|
|
363
|
-
stopped: Effect.sync(() => ended
|
|
509
|
+
stopped: Effect.sync(() => ended
|
|
364
510
|
? undefined
|
|
365
|
-
:
|
|
511
|
+
: endedWith !== undefined
|
|
512
|
+
? `the video stopped being recorded (${ffmpegEnded(endedWith)}).`
|
|
513
|
+
: restartFailed !== undefined
|
|
514
|
+
? `the video stopped being recorded (the screencast could not be started again: ${restartFailed}).`
|
|
515
|
+
: undefined),
|
|
366
516
|
};
|
|
367
517
|
});
|
|
368
518
|
/**
|
|
@@ -373,10 +523,19 @@ export const videoRecording = (video) => Effect.gen(function* () {
|
|
|
373
523
|
const platform = yield* Effect.context();
|
|
374
524
|
return {
|
|
375
525
|
path: video.path,
|
|
376
|
-
record: (page, size) => Effect.gen(function* () {
|
|
526
|
+
record: (page, size, window) => Effect.gen(function* () {
|
|
377
527
|
const fs = yield* FileSystem.FileSystem;
|
|
378
|
-
yield* fs.makeDirectory(video.dir, { recursive: true })
|
|
379
|
-
|
|
528
|
+
yield* fs.makeDirectory(video.dir, { recursive: true }).pipe(Effect.mapError((error) => new RecordingFailed({
|
|
529
|
+
reason: 'output',
|
|
530
|
+
message: `the video's folder could not be made: ${error.message}`,
|
|
531
|
+
cause: error,
|
|
532
|
+
})));
|
|
533
|
+
return yield* startRecorder(page, {
|
|
534
|
+
ffmpeg: video.ffmpeg,
|
|
535
|
+
file: video.path,
|
|
536
|
+
size,
|
|
537
|
+
window,
|
|
538
|
+
});
|
|
380
539
|
}).pipe(Effect.provideContext(platform)),
|
|
381
540
|
};
|
|
382
541
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Duration, Effect, Option, Schedule } from 'effect';
|
|
2
2
|
import { PageActionFailed, sentTo, SITE_ICONS_MAX, siteTitle, } from '../core/index.js';
|
|
3
|
+
import { fitWindow } from './page.js';
|
|
3
4
|
/** The live view's viewport until the viewer says how much room it has. */
|
|
4
5
|
export const SIGN_IN_VIEWPORT = { width: 1280, height: 800 };
|
|
5
6
|
/** The viewports a viewer may ask for, in CSS pixels: a phone's up to a large desktop's. */
|
|
@@ -101,10 +102,17 @@ export const signInBrowser = (browser, url) => Effect.gen(function* () {
|
|
|
101
102
|
let cast;
|
|
102
103
|
const open = [first];
|
|
103
104
|
/** Streams `page`'s frames from now on, and stops the tab streamed before. */
|
|
104
|
-
const
|
|
105
|
+
const restream = async (page) => {
|
|
105
106
|
const before = cast;
|
|
106
107
|
cast = undefined;
|
|
107
108
|
await before?.detach().catch(() => undefined);
|
|
109
|
+
if (page.isClosed() || page !== active)
|
|
110
|
+
return;
|
|
111
|
+
const shown = { ...viewport };
|
|
112
|
+
// The frames show the window's contents, which must hold the whole viewport (see
|
|
113
|
+
// `fitWindow`); where the window stays wider, they show more, the viewport in their corner.
|
|
114
|
+
// Boundary: this runs from Playwright's event callbacks, so as a promise.
|
|
115
|
+
const window = await Effect.runPromise(fitWindow(page, shown));
|
|
108
116
|
if (page.isClosed() || page !== active)
|
|
109
117
|
return;
|
|
110
118
|
const session = await page.context().newCDPSession(page);
|
|
@@ -116,19 +124,40 @@ export const signInBrowser = (browser, url) => Effect.gen(function* () {
|
|
|
116
124
|
latest = {
|
|
117
125
|
seq: ++seq,
|
|
118
126
|
jpeg: frame.data,
|
|
119
|
-
|
|
120
|
-
|
|
127
|
+
...shown,
|
|
128
|
+
contents: {
|
|
129
|
+
width: Math.round(frame.metadata.deviceWidth),
|
|
130
|
+
height: Math.round(frame.metadata.deviceHeight),
|
|
131
|
+
},
|
|
121
132
|
url: page.url(),
|
|
122
133
|
};
|
|
123
134
|
});
|
|
135
|
+
// As large as the window, so the viewport in its corner is not shrunk.
|
|
124
136
|
await session.send('Page.startScreencast', {
|
|
125
137
|
format: 'jpeg',
|
|
126
138
|
quality: FRAME_QUALITY,
|
|
127
|
-
maxWidth:
|
|
128
|
-
maxHeight:
|
|
139
|
+
maxWidth: Math.max(shown.width, window?.width ?? 0),
|
|
140
|
+
maxHeight: Math.max(shown.height, window?.height ?? 0),
|
|
129
141
|
everyNthFrame: 1,
|
|
130
142
|
});
|
|
131
143
|
};
|
|
144
|
+
/** `restream`, one at a time, so two never both stream (one of them never stopped). */
|
|
145
|
+
let streaming = Promise.resolve();
|
|
146
|
+
const stream = (page) => (streaming = streaming.catch(() => undefined).then(() => restream(page)));
|
|
147
|
+
/**
|
|
148
|
+
* Starts the stream again whenever `page` loads a document: Chrome (158) sends no frame of a
|
|
149
|
+
* new document to a screencast started on the one before, so the live view would keep showing
|
|
150
|
+
* the page it left (the sign-in form, after the app redirects). On its DOM and once it loaded,
|
|
151
|
+
* so a page slow to load still shows as soon as it can.
|
|
152
|
+
*/
|
|
153
|
+
const follow = (page) => {
|
|
154
|
+
const again = () => {
|
|
155
|
+
if (page === active)
|
|
156
|
+
stream(page).catch(() => undefined);
|
|
157
|
+
};
|
|
158
|
+
page.on('domcontentloaded', again);
|
|
159
|
+
page.on('load', again);
|
|
160
|
+
};
|
|
132
161
|
/** Makes `page` the one shown and driven. */
|
|
133
162
|
const activate = (page) => {
|
|
134
163
|
active = page;
|
|
@@ -136,6 +165,7 @@ export const signInBrowser = (browser, url) => Effect.gen(function* () {
|
|
|
136
165
|
};
|
|
137
166
|
context.on('page', (page) => {
|
|
138
167
|
open.push(page);
|
|
168
|
+
follow(page);
|
|
139
169
|
page.setViewportSize(viewport).catch(() => undefined);
|
|
140
170
|
page.on('close', () => {
|
|
141
171
|
open.splice(open.indexOf(page), 1);
|
|
@@ -151,6 +181,7 @@ export const signInBrowser = (browser, url) => Effect.gen(function* () {
|
|
|
151
181
|
if (active === first && last !== undefined)
|
|
152
182
|
activate(last);
|
|
153
183
|
});
|
|
184
|
+
follow(first);
|
|
154
185
|
yield* attempt(() => stream(first));
|
|
155
186
|
// A page that is slow or fails to load still opens: the person sees what it shows.
|
|
156
187
|
yield* attempt(() => first.goto(url, { timeout: SIGN_IN_LOAD_TIMEOUT_MS })).pipe(Effect.ignore);
|
package/dist/build-info.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "2026-11-
|
|
3
|
-
"builtAt": "2026-11-
|
|
4
|
-
"commit": "
|
|
2
|
+
"id": "2026-11-26T15:11:17.849Z-bed7cd7b",
|
|
3
|
+
"builtAt": "2026-11-26T15:11:17.849Z",
|
|
4
|
+
"commit": "f5f1d3478c3dcd2c62d148e9b53aad78e881d3c6"
|
|
5
5
|
}
|
package/dist/cli/commands.js
CHANGED
|
@@ -33,12 +33,12 @@ const usage = (message) => Effect.fail(new Failure({ code: ExitCode.Usage, reaso
|
|
|
33
33
|
const stub = (name, description) => Command.make(name, { json }, (flags) => handle(flags.json)(Effect.fail(notImplemented(name)))).pipe(Command.withDescription(description));
|
|
34
34
|
const formatDoctorHuman = (report) => report.checks
|
|
35
35
|
.flatMap((check) => [
|
|
36
|
-
`${check.ok ? '✓' : check.severity === 'warning' ? '!' : '✗'} ${check.id.padEnd(
|
|
36
|
+
`${check.ok ? '✓' : check.severity === 'warning' ? '!' : '✗'} ${check.id.padEnd(9)} ${check.detail}`,
|
|
37
37
|
...(check.fix
|
|
38
38
|
? [
|
|
39
|
-
`
|
|
40
|
-
...(check.fix.command ? [`
|
|
41
|
-
`
|
|
39
|
+
` Fix: ${check.fix.action}`,
|
|
40
|
+
...(check.fix.command ? [` Run: ${check.fix.command}`] : []),
|
|
41
|
+
` Why: ${check.fix.why}`,
|
|
42
42
|
]
|
|
43
43
|
: []),
|
|
44
44
|
])
|
package/dist/cli/doctor.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, type FileSystem, type Path } from 'effect';
|
|
2
2
|
import { type FfmpegLookup } from '../browser-playwright/index.js';
|
|
3
|
-
import { Browser, type BrowserInfo } from '../core/index.js';
|
|
3
|
+
import { Browser, type BrowserInfo, type RecordingCheck } from '../core/index.js';
|
|
4
4
|
import type { DoctorCheck, DoctorReport } from '../schema/index.js';
|
|
5
5
|
import { type BuildInfo } from './build-info.js';
|
|
6
6
|
import { PackageInfo } from './package-info.js';
|
|
@@ -17,6 +17,11 @@ export declare const checkNode: (current: string, range: string) => DoctorCheck;
|
|
|
17
17
|
export declare const checkBrowser: (found: BrowserInfo | undefined, installCommand: string) => DoctorCheck;
|
|
18
18
|
/** A failure: every run is recorded as video, so without ffmpeg no run starts. */
|
|
19
19
|
export declare const checkVideo: (lookup: FfmpegLookup, installCommand: string) => DoctorCheck;
|
|
20
|
+
/**
|
|
21
|
+
* The test recording (`Browser.checkRecording`): a failure, said by what went wrong, since a run
|
|
22
|
+
* that cannot be recorded does not start. `ffmpegCommand` downloads Playwright's ffmpeg again.
|
|
23
|
+
*/
|
|
24
|
+
export declare const checkRecorded: (result: RecordingCheck, ffmpegCommand: string) => DoctorCheck;
|
|
20
25
|
export declare const checkDisk: (path: string, freeBytes: number | undefined) => DoctorCheck;
|
|
21
26
|
/** The host settings as set, trimmed; empty when unset. */
|
|
22
27
|
export interface HostSettings {
|