screw-bugs 0.1.0 → 0.1.1-next.2.gc84eb20
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 +79 -44
- package/dist/browser-playwright/launch.d.ts +7 -2
- package/dist/browser-playwright/launch.js +31 -8
- package/dist/browser-playwright/page.d.ts +29 -5
- package/dist/browser-playwright/page.js +92 -15
- package/dist/build-info.json +3 -3
- package/dist/cli/app.js +31 -3
- package/dist/cli/build-info.d.ts +7 -0
- package/dist/cli/build-info.js +17 -1
- package/dist/cli/commands.js +6 -2
- package/dist/cli/doctor.d.ts +7 -1
- package/dist/cli/doctor.js +23 -9
- package/dist/cli/exit-codes.d.ts +4 -1
- package/dist/cli/exit-codes.js +4 -1
- package/dist/cli/install-method.d.ts +12 -2
- package/dist/cli/install-method.js +12 -4
- package/dist/cli/mcp.js +4 -0
- package/dist/cli/operations.d.ts +6 -3
- package/dist/cli/operations.js +36 -14
- package/dist/cli/report-server.d.ts +15 -6
- package/dist/cli/report-server.js +73 -8
- package/dist/cli/update-check.d.ts +27 -11
- package/dist/cli/update-check.js +45 -24
- package/dist/core/engine.d.ts +6 -0
- package/dist/core/engine.js +41 -3
- package/dist/core/services.d.ts +17 -0
- package/dist/report/bug.d.ts +11 -0
- package/dist/report/bug.js +19 -0
- package/dist/report/html.d.ts +26 -24
- package/dist/report/html.js +704 -618
- package/dist/report/icons.d.ts +40 -0
- package/dist/report/icons.js +81 -0
- package/dist/report/logos.d.ts +4 -0
- package/dist/report/logos.js +19 -0
- package/dist/report/markup.d.ts +25 -6
- package/dist/report/markup.js +110 -22
- package/dist/report/player.d.ts +76 -0
- package/dist/report/player.js +249 -0
- package/dist/report/shots.d.ts +56 -0
- package/dist/report/shots.js +276 -0
- package/dist/report/styles.js +220 -265
- package/dist/report/view.d.ts +135 -0
- package/dist/report/view.js +288 -0
- package/dist/report/walkthrough.d.ts +26 -22
- package/dist/report/walkthrough.js +309 -163
- package/dist/schema/doctor.d.ts +3 -3
- package/dist/schema/doctor.js +8 -1
- package/dist/schema/findings.js +1 -5
- package/dist/schema/job.d.ts +20 -0
- package/dist/schema/job.js +10 -0
- package/dist/schema/ledger.d.ts +37 -1
- package/dist/schema/ledger.js +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,9 +19,10 @@ npx screw-bugs@latest doctor
|
|
|
19
19
|
|
|
20
20
|
`doctor` installs nothing. It tells you what is missing, the command that fixes it and why.
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
and prints the command that downloads it,
|
|
24
|
-
to the Playwright that screw-bugs uses.
|
|
22
|
+
Every run is recorded as video, which needs Playwright's ffmpeg. If `doctor` cannot find it, it
|
|
23
|
+
fails (exit code 4) and prints the command that downloads it,
|
|
24
|
+
`npx -y playwright-core@<version> install ffmpeg`, pinned to the Playwright that screw-bugs uses.
|
|
25
|
+
Without it no run starts: `start_run` and `screw-bugs run` reply with the same command (exit code 4).
|
|
25
26
|
|
|
26
27
|
## Use from a coding agent (MCP)
|
|
27
28
|
|
|
@@ -29,6 +30,11 @@ to the Playwright that screw-bugs uses. Runs still work without it; they just ha
|
|
|
29
30
|
claude mcp add screw-bugs -- npx -y screw-bugs@latest mcp
|
|
30
31
|
```
|
|
31
32
|
|
|
33
|
+
To try the newest build of `main` instead, use the `next` channel: every merge to `main` is
|
|
34
|
+
published as a prerelease under the npm tag `next` (for example `0.1.1-next.57.gfa82ee8`, which
|
|
35
|
+
names its commit), with `npx -y screw-bugs@next mcp`. `doctor` shows the version and commit that is
|
|
36
|
+
running. A `next` build checks for, and suggests, newer `next` builds only.
|
|
37
|
+
|
|
32
38
|
Tools: `doctor`, `start_run` (returns a job ID right away; the run continues inside the MCP
|
|
33
39
|
server), `run_status`, `submit_findings`, `answer_question`. `start_run` takes the same job as a
|
|
34
40
|
`--spec` file, without `version`, and there `summary` is required. Upload paths are relative to the
|
|
@@ -177,6 +183,7 @@ Limits (each text is one line, not blank; findings past them are rejected with w
|
|
|
177
183
|
{
|
|
178
184
|
"version": 1,
|
|
179
185
|
"url": "http://localhost:3000",
|
|
186
|
+
"title": "Sign-in after the refactor",
|
|
180
187
|
"instructions": "check that login still works after my refactor",
|
|
181
188
|
"summary": "Signing in with a test account still reaches the dashboard and greets the user.",
|
|
182
189
|
"cases": [
|
|
@@ -196,16 +203,20 @@ Limits (each text is one line, not blank; findings past them are rejected with w
|
|
|
196
203
|
}
|
|
197
204
|
```
|
|
198
205
|
|
|
199
|
-
|
|
200
|
-
`status` and the report, but never reads or interprets them: only `cases` decide what runs.
|
|
206
|
+
Three optional free-text fields describe a job. screw-bugs saves them in `job.json` and shows them
|
|
207
|
+
in `status` and the report, but never reads or interprets them: only `cases` decide what runs.
|
|
201
208
|
|
|
209
|
+
- `title`: a short name for the run, one line of at most 80 characters, such as
|
|
210
|
+
`Notes app walkthrough` or `Checkout on mobile`. It is the report's heading. Without one, the
|
|
211
|
+
heading is the app's own page title as the run recorded it (from the first case that recorded
|
|
212
|
+
one), else the target's host.
|
|
202
213
|
- `instructions`: what the user asked for, in their own words (verbatim when possible). Provenance.
|
|
203
214
|
- `summary`: what these cases test and why, written by whoever wrote the cases, for a reader who
|
|
204
215
|
never sees the steps. Not a list of steps. Without one, screw-bugs derives a summary from the case
|
|
205
216
|
titles, such as `Checks: page loads; signup with a valid email`.
|
|
206
217
|
|
|
207
|
-
With `run`, `--instructions <text>` and `--summary <text>` override the same
|
|
208
|
-
file.
|
|
218
|
+
With `run`, `--title <text>`, `--instructions <text>` and `--summary <text>` override the same
|
|
219
|
+
fields in a `--spec` file.
|
|
209
220
|
|
|
210
221
|
`device` is optional: `desktop` (the default, a 1280×800 window) or `mobile`, which emulates an
|
|
211
222
|
iPhone 17 (Playwright's profile: viewport, user agent, pixel ratio and touch). screw-bugs only
|
|
@@ -233,7 +244,8 @@ Every step that waits (all but `screenshot`) takes an optional `timeoutMs`, from
|
|
|
233
244
|
(three minutes): how long to wait for its element, text, URL, state or frame (default 5000), or
|
|
234
245
|
for the page it loads (`goto`, `reload`, `press`; default 15000). A page that a `click`, `fill`, `upload` or an
|
|
235
246
|
expectation starts loading gets at least the default 15 seconds, or the step's `timeoutMs` when
|
|
236
|
-
that is longer.
|
|
247
|
+
that is longer. A page load that has not finished by then blocks the case and is stopped, so the
|
|
248
|
+
case's screenshot and page facts show the page as it was before that load. Use it for slow work, such as generation that takes a minute:
|
|
237
249
|
`{ "action": "expectText", "text": "Your portfolio is ready", "timeoutMs": 120000 }`. A failed
|
|
238
250
|
expectation says how long it waited (`did not appear within 5 s`), and the report shows a timeout
|
|
239
251
|
that is not the default next to its step (`waited up to 120 s`).
|
|
@@ -501,7 +513,8 @@ That way each check of what a case made is a case of its own, and one failure hi
|
|
|
501
513
|
|
|
502
514
|
A continuing case runs whatever the case before it came to, failed or blocked; only a browser that
|
|
503
515
|
crashed stops the run, as always. Tabs and windows the case before it opened are closed, and its
|
|
504
|
-
page loads are not judged again
|
|
516
|
+
page loads are not judged again (one that did not finish was stopped, so the continuing case
|
|
517
|
+
starts on the page as it was before that load), but a way off the web it took (such as a `data:` frame) still
|
|
505
518
|
blocks the continuing case. The first case of a job cannot continue: that job is rejected
|
|
506
519
|
(`The first case, "generate", cannot continue: there is no case before it to continue from. …`).
|
|
507
520
|
The ledger and the evidence pack record `continuedFrom` (the ID of the case before it), and the
|
|
@@ -527,8 +540,8 @@ A `target` is exactly one of `{ "role": "button", "name": "Save" }` (`name` opti
|
|
|
527
540
|
[Frames](#frames)). When several elements match, the first visible one is used.
|
|
528
541
|
|
|
529
542
|
Cases run one after another, in job order, in one browser session (one test user in one browser),
|
|
530
|
-
recorded as one continuous video (`video/session-1.webm`, at
|
|
531
|
-
carry over from one case to the next, so a case can rely on what an earlier one did (signing in)
|
|
543
|
+
recorded as one continuous video (`video/session-1.webm`, at the viewport's own size: 1280×800 on a
|
|
544
|
+
desktop, 402×680 on a phone). Cookies and storage carry over from one case to the next, so a case can rely on what an earlier one did (signing in)
|
|
532
545
|
and can be affected by it. A failed or blocked case does not stop the session; only a browser that
|
|
533
546
|
crashes does, and the cases after it are then `not_verified`. A case whose first step is not `goto`
|
|
534
547
|
starts at the job URL, unless it continues (see below). A job without cases gets one "page loads" case: it opens the URL, passes when there is no HTTP
|
|
@@ -637,23 +650,33 @@ deletes the interrupted report once it has written its own.
|
|
|
637
650
|
|
|
638
651
|
### Report
|
|
639
652
|
|
|
640
|
-
Every run that ends, finished or errored, writes `report.html` into its folder.
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
at
|
|
655
|
-
|
|
656
|
-
|
|
653
|
+
Every run that ends, finished or errored, writes `report.html` into its folder. One page, one
|
|
654
|
+
player: at the top the target, the number of cases, how long the run took and the device, what was
|
|
655
|
+
asked (two lines, with the rest a click away) and a filter per status. Below, the run's video in a
|
|
656
|
+
browser window (a phone, for a run on a phone) with the page's address at each moment, as the run
|
|
657
|
+
recorded it, and beside it the evaluation and one card per case. The evaluation is the agent's
|
|
658
|
+
headline with the counts under it, one line per fix (most severe first), the agent's first fix as
|
|
659
|
+
"Fix first", and what was not tested and why; without a write-up, the counts alone. Each card has
|
|
660
|
+
the case's status (an icon and its word), its time on the video, why it did not pass, and its
|
|
661
|
+
screenshots: for a case that did not pass, the page when it stopped as "Actual" (beside one the
|
|
662
|
+
agent marked only in green as "Expected"), else small thumbnails. A screenshot opens in a viewer
|
|
663
|
+
with the highlights drawn over it (a checkbox hides them) and the element the step acted on; the
|
|
664
|
+
arrow keys step through the case's screenshots. "Steps and details" opens the case's steps with
|
|
665
|
+
their timecodes and the agent's write-up of it. Then what to test next, and the run's details
|
|
666
|
+
(what it checks, target, times, video, version, raw files). Scrolling the cases drives the player:
|
|
667
|
+
the case at the reading line plays, in a loop unless "Loop case" is off, when the cases follow the
|
|
668
|
+
video instead. Code lays out the page and decides every status; the agent's write-up fills fixed
|
|
669
|
+
slots and is labelled as its own.
|
|
670
|
+
|
|
671
|
+
It is one self-contained file: inline styles and one inline script allowed by its hash in the
|
|
672
|
+
Content Security Policy. The only thing it loads from the network is Geist and Geist Mono from
|
|
673
|
+
Google Fonts, when online; offline it falls back to the system's fonts. Screenshots and the video
|
|
674
|
+
load by relative paths, so it opens from disk and still works when the run folder is zipped or
|
|
675
|
+
moved. It has a light and a dark theme: it follows the
|
|
676
|
+
system, and a switch picks one (kept in the browser where it allows). Without script it follows the
|
|
677
|
+
system, the video has the browser's own controls, timecodes are plain links that open the video at
|
|
678
|
+
that time and screenshots open the image. One video loads at a time, so the screenshots load from
|
|
679
|
+
any static server, also one without HTTP range requests such as `python3 -m http.server`.
|
|
657
680
|
`run`, `status` and the MCP tool `run_status` give its path once the run has ended.
|
|
658
681
|
|
|
659
682
|
Only the run writes its `report.html`, plus `report` and `findings` under the rules below. For a
|
|
@@ -681,15 +704,18 @@ drawn in, and the report's path. It embeds no images, so it can be pasted into a
|
|
|
681
704
|
|
|
682
705
|
### Walkthrough
|
|
683
706
|
|
|
684
|
-
With `report.html`, the run writes `walkthrough.html`: a page to click through what the run did.
|
|
685
|
-
video
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
707
|
+
With `report.html`, the run writes `walkthrough.html`: a page to click through what the run did. The
|
|
708
|
+
video in a browser window (a phone, for a run on a phone, with the script beside it on a wide
|
|
709
|
+
screen) with the page's address at each moment, controls under it (speed, "Skip inactive" to jump
|
|
710
|
+
over stretches where no step ran, the cursor overlay, fullscreen), and below it the script: every
|
|
711
|
+
step of every case in run order, grouped by case (its title and status), each with its timecode
|
|
712
|
+
and the step in words (`0:01.5 Fill the field labelled "Note" with "this is a new line"`). As the
|
|
713
|
+
video plays, the step playing now is the script's top row, highlighted (without motion when the
|
|
714
|
+
system asks for less); "Expand" shows the whole script. Every timecode and row seeks the video
|
|
715
|
+
there (playing on if it was playing, staying paused if not), and switches to the right session's video when it is in another one; when one
|
|
716
|
+
session's video ends, the next one plays. The step that decided a case that did not pass says its
|
|
717
|
+
status and reason, in the report's words, and those cases are listed under the script, each with a
|
|
718
|
+
link to where it was decided.
|
|
693
719
|
While a step that acted on an element is playing, a box over the video shows that element: taken
|
|
694
720
|
from the step's screenshot of the viewport, measured as the step ran, and drawn only around the
|
|
695
721
|
moment it was measured. Steps with no such measurement get no box. Boxes on the video, on the
|
|
@@ -725,18 +751,19 @@ motion the cursor jumps instead of gliding and there is no ripple. **Show cursor
|
|
|
725
751
|
turns it off; the choice is remembered like the theme. Runs from before actions were recorded have
|
|
726
752
|
none of it.
|
|
727
753
|
|
|
728
|
-
Like the report it is self-contained, loads
|
|
729
|
-
|
|
754
|
+
Like the report it is self-contained, loads only Geist and Geist Mono from Google Fonts when
|
|
755
|
+
online (falling back to the system's fonts offline), links the video by relative path, follows the
|
|
756
|
+
light and dark theme, and works from disk and over the report server. A run with
|
|
730
757
|
no video, or an older run with no step times, still lists every step and error, and says why the
|
|
731
758
|
times cannot be played.
|
|
732
759
|
|
|
733
|
-
It is written
|
|
734
|
-
`
|
|
735
|
-
|
|
736
|
-
when it exists.
|
|
760
|
+
It is written with `report.html`: by the run when it ends, and again by `report` and
|
|
761
|
+
`findings`/`submit_findings`; never by status reads, and never for an interrupted run
|
|
762
|
+
(`report-interrupted.html` has no walkthrough). `walkthrough` rewrites only the walkthrough and
|
|
763
|
+
leaves the report as it is. The report links it near the top when it exists.
|
|
737
764
|
|
|
738
765
|
```sh
|
|
739
|
-
screw-bugs walkthrough <job-id> # (re)write it
|
|
766
|
+
screw-bugs walkthrough <job-id> # (re)write it (not the report) and print its path
|
|
740
767
|
screw-bugs walkthrough <job-id> --serve # serve it at a http://127.0.0.1 URL, as report --serve
|
|
741
768
|
```
|
|
742
769
|
|
|
@@ -773,6 +800,10 @@ processes, sessions and `report --serve`, as long as one of them serves the proj
|
|
|
773
800
|
- An MCP server that is not on the project's port tries it again each time it gives a URL. Once it
|
|
774
801
|
is free, it serves there too and gives that URL from then on; a free-port server it started
|
|
775
802
|
keeps running, so links it gave before still work.
|
|
803
|
+
- An MCP server that gave out another MCP server's URL also tries the port every 2 seconds in the
|
|
804
|
+
background, and serves there as soon as that one ends. So the project's report server lives as
|
|
805
|
+
long as any of its MCP servers that gave links to it, even when the one that started it (say, a
|
|
806
|
+
subagent's) is gone.
|
|
776
807
|
- `report --serve --port <n>` uses exactly that port, and fails if it is taken (`--port 0` picks a
|
|
777
808
|
free one).
|
|
778
809
|
|
|
@@ -848,6 +879,10 @@ checkout's (`pnpm build` stamps `dist/build-info.json`), it suggests `pnpm build
|
|
|
848
879
|
MCP server loaded an older build or version than is installed now, it says to restart the server
|
|
849
880
|
(in Claude Code: `/mcp`, pick screw-bugs, Reconnect).
|
|
850
881
|
|
|
882
|
+
A `next` build (see [Use from a coding agent](#use-from-a-coding-agent-mcp)) asks for the newest
|
|
883
|
+
`next` build instead of `latest`, keeps its own cache file (`update-check-next.json`), and its
|
|
884
|
+
commands use `@next` (`npx -y screw-bugs@next mcp`, `npm i -g screw-bugs@next`, …).
|
|
885
|
+
|
|
851
886
|
Turn the check off with `SCREW_BUGS_UPDATE_CHECK=0`. It is always off with `CI=true`.
|
|
852
887
|
|
|
853
888
|
### Analytics
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Effect, FileSystem, Layer, Path } from 'effect';
|
|
2
2
|
import { Browser } from '../core/index.js';
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. Needs the
|
|
5
|
+
* platform (`FileSystem`, `Path`) to find Playwright's ffmpeg.
|
|
6
|
+
*/
|
|
7
|
+
export declare const BrowserPlaywright: Layer.Layer<Browser, never, FileSystem.FileSystem | Path.Path>;
|
|
5
8
|
/**
|
|
6
9
|
* Downloads the Chromium build that matches the bundled Playwright. Pinned to our version so the
|
|
7
10
|
* browser revision is the one we look for.
|
|
@@ -14,6 +17,8 @@ export interface FfmpegLookup {
|
|
|
14
17
|
readonly found: boolean;
|
|
15
18
|
readonly path: string | undefined;
|
|
16
19
|
}
|
|
20
|
+
/** What is wrong when Playwright's ffmpeg is not found, as a clause: no full stop. */
|
|
21
|
+
export declare const ffmpegProblem: (lookup: FfmpegLookup) => string;
|
|
17
22
|
/**
|
|
18
23
|
* Finds the ffmpeg Playwright records videos with, where Playwright itself looks (its registry
|
|
19
24
|
* follows PLAYWRIGHT_BROWSERS_PATH and the platform's cache folder). Never downloads anything.
|
|
@@ -39,16 +39,35 @@ const launchAny = (headed) => Effect.gen(function* () {
|
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
const open = (options) => launchAny(options.headed).pipe(Effect.map(({ candidate, browser }) => ({
|
|
42
|
-
info: {
|
|
42
|
+
info: {
|
|
43
|
+
kind: candidate.kind,
|
|
44
|
+
type: browser.browserType().name(),
|
|
45
|
+
channel: candidate.channel,
|
|
46
|
+
version: browser.version(),
|
|
47
|
+
},
|
|
43
48
|
newSession: (session) => newSession(browser, session.device, session.video),
|
|
44
49
|
})));
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. Needs the
|
|
52
|
+
* platform (`FileSystem`, `Path`) to find Playwright's ffmpeg.
|
|
53
|
+
*/
|
|
54
|
+
export const BrowserPlaywright = Layer.effect(Browser, Effect.gen(function* () {
|
|
55
|
+
const fs = yield* FileSystem.FileSystem;
|
|
56
|
+
const path = yield* Path.Path;
|
|
57
|
+
const videoSupport = Effect.gen(function* () {
|
|
58
|
+
const lookup = yield* findFfmpeg;
|
|
59
|
+
if (lookup.found)
|
|
60
|
+
return { ok: true };
|
|
61
|
+
return { ok: false, problem: ffmpegProblem(lookup), command: yield* installFfmpegCommand };
|
|
62
|
+
}).pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path));
|
|
63
|
+
return {
|
|
64
|
+
detect: Effect.scoped(open({ headed: false })).pipe(Effect.map((session) => session.info)),
|
|
65
|
+
videoSupport,
|
|
66
|
+
open,
|
|
67
|
+
deviceLabel,
|
|
68
|
+
annotate: (jobs) => Effect.scoped(launchAny(false).pipe(Effect.flatMap(({ browser }) => annotateAll(browser, jobs)))),
|
|
69
|
+
};
|
|
70
|
+
}));
|
|
52
71
|
const PlaywrightPackage = Schema.Struct({ version: Schema.String });
|
|
53
72
|
/** The bundled Playwright's version, for install commands pinned to it. */
|
|
54
73
|
const playwrightVersion = Effect.gen(function* () {
|
|
@@ -67,6 +86,10 @@ const playwrightVersion = Effect.gen(function* () {
|
|
|
67
86
|
export const installBrowserCommand = playwrightVersion.pipe(Effect.map((version) => `npx -y playwright-core@${version} install chromium`));
|
|
68
87
|
/** Downloads the ffmpeg build that the bundled Playwright records videos with. */
|
|
69
88
|
export const installFfmpegCommand = playwrightVersion.pipe(Effect.map((version) => `npx -y playwright-core@${version} install ffmpeg`));
|
|
89
|
+
/** What is wrong when Playwright's ffmpeg is not found, as a clause: no full stop. */
|
|
90
|
+
export const ffmpegProblem = (lookup) => lookup.path === undefined
|
|
91
|
+
? "Playwright's ffmpeg could not be looked up"
|
|
92
|
+
: `Playwright's ffmpeg is missing (looked for ${lookup.path})`;
|
|
70
93
|
/**
|
|
71
94
|
* Finds the ffmpeg Playwright records videos with, where Playwright itself looks (its registry
|
|
72
95
|
* follows PLAYWRIGHT_BROWSERS_PATH and the platform's cache folder). Never downloads anything.
|
|
@@ -25,10 +25,15 @@ export declare const NAVIGATION_START_MS = 250;
|
|
|
25
25
|
export declare const MOBILE_DEVICE = "iPhone 17";
|
|
26
26
|
/** The device as reports show it; the engine is named because mobile is not real Safari. */
|
|
27
27
|
export declare const deviceLabel: (device: Device) => string;
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Session videos fit in this box, keeping the viewport's shape. It is larger than every viewport
|
|
30
|
+
* we set (desktop 1280x800), so videos are recorded 1:1: scaling frames down (as a 1280x720 box
|
|
31
|
+
* once did, to 1152x720) resamples every glyph and blurs text. Chromium's screencast sends frames
|
|
32
|
+
* in CSS pixels, so a box larger than the viewport would only pad the frame, not sharpen it.
|
|
33
|
+
*/
|
|
29
34
|
export declare const VIDEO_MAX: {
|
|
30
|
-
readonly width:
|
|
31
|
-
readonly height:
|
|
35
|
+
readonly width: 1920;
|
|
36
|
+
readonly height: 1080;
|
|
32
37
|
};
|
|
33
38
|
/** The size of a session's video for a viewport: the viewport, scaled down into `VIDEO_MAX`. */
|
|
34
39
|
export declare const videoSize: (viewport: {
|
|
@@ -44,6 +49,8 @@ export declare const CLOSE_TIMEOUT_MS = 30000;
|
|
|
44
49
|
export declare const MEASURE_TIMEOUT_MS = 1000;
|
|
45
50
|
/** How long setting up the input observer (`watchInput`) or taking it down may take. */
|
|
46
51
|
export declare const INPUT_SETUP_TIMEOUT_MS = 2000;
|
|
52
|
+
/** How long stopping a load judged unfinished may take (see `watchContext`'s `settle`). */
|
|
53
|
+
export declare const STOP_LOADING_TIMEOUT_MS = 2000;
|
|
47
54
|
/** How long saving what a screenshot needs besides the image may take. */
|
|
48
55
|
export declare const CAPTURE_TIMEOUT_MS = 3000;
|
|
49
56
|
/**
|
|
@@ -358,6 +365,23 @@ export declare const ABSENCE_BUDGET: {
|
|
|
358
365
|
* `findElsewhere`), and how long finding the frame the step named may take within it.
|
|
359
366
|
*/
|
|
360
367
|
export declare const ELSEWHERE_TIMEOUT_MS = 1000;
|
|
368
|
+
/** How long a new recorded tab may take to paint its video's first frame. */
|
|
369
|
+
export declare const FIRST_FRAME_TIMEOUT_MS = 2000;
|
|
370
|
+
/**
|
|
371
|
+
* When a recorded tab's video starts, in epoch ms; undefined when no frame came in time.
|
|
372
|
+
*
|
|
373
|
+
* Playwright's video starts at the first frame the browser sends, not when the tab opens, and
|
|
374
|
+
* every frame sits on the video at its paint time from there. Steps are timed from the video's
|
|
375
|
+
* start, so it has to be known. The blank tab's own paint often comes before the browser starts
|
|
376
|
+
* sending frames; then the first frame was the first page's, after its load, and every step came
|
|
377
|
+
* up on the video early by that long: a field filled on the video while the walkthrough still
|
|
378
|
+
* played the step before. So the blank tab is repainted (white and almost white, by turns) until
|
|
379
|
+
* a frame comes, before any page of the run loads; a repaint that only arrives once a page has
|
|
380
|
+
* loaded leaves it alone. A listener that starts after a frame is handed the latest one at once,
|
|
381
|
+
* which for a blank tab is its first. Frame times are the browser's wall clock, the one `Clock`
|
|
382
|
+
* reads in a run. The listener is let go of when this ends, timed out or not.
|
|
383
|
+
*/
|
|
384
|
+
export declare const firstFrameAt: (page: Page) => Effect.Effect<number | undefined, never, never>;
|
|
361
385
|
/**
|
|
362
386
|
* One session: a fresh context (no cookies or storage from other runs) with one tab that every
|
|
363
387
|
* case of the session runs in, recorded as one continuous video. Tabs and windows a case opens
|
|
@@ -365,8 +389,8 @@ export declare const ELSEWHERE_TIMEOUT_MS = 1000;
|
|
|
365
389
|
* is saved then too, so a run that is stopped keeps it.
|
|
366
390
|
*
|
|
367
391
|
* Playwright records each tab's video separately, so only the session's own tab is kept: the
|
|
368
|
-
* videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg
|
|
369
|
-
*
|
|
392
|
+
* videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg: a session
|
|
393
|
+
* with `video` that cannot be recorded fails rather than run without one.
|
|
370
394
|
*/
|
|
371
395
|
export declare const newSession: (browser: PlaywrightBrowser, device: Device, video: {
|
|
372
396
|
readonly dir: string;
|
|
@@ -30,8 +30,13 @@ export const MOBILE_DEVICE = 'iPhone 17';
|
|
|
30
30
|
/** The device as reports show it; the engine is named because mobile is not real Safari. */
|
|
31
31
|
export const deviceLabel = (device) => device === 'mobile' ? `${MOBILE_DEVICE} (Chromium)` : 'Desktop';
|
|
32
32
|
const contextOptions = (device) => device === 'mobile' ? devices[MOBILE_DEVICE] : { viewport: { width: 1280, height: 800 } };
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Session videos fit in this box, keeping the viewport's shape. It is larger than every viewport
|
|
35
|
+
* we set (desktop 1280x800), so videos are recorded 1:1: scaling frames down (as a 1280x720 box
|
|
36
|
+
* once did, to 1152x720) resamples every glyph and blurs text. Chromium's screencast sends frames
|
|
37
|
+
* in CSS pixels, so a box larger than the viewport would only pad the frame, not sharpen it.
|
|
38
|
+
*/
|
|
39
|
+
export const VIDEO_MAX = { width: 1920, height: 1080 };
|
|
35
40
|
/** The size of a session's video for a viewport: the viewport, scaled down into `VIDEO_MAX`. */
|
|
36
41
|
export const videoSize = (viewport) => {
|
|
37
42
|
const scale = Math.min(1, VIDEO_MAX.width / viewport.width, VIDEO_MAX.height / viewport.height);
|
|
@@ -44,6 +49,8 @@ export const CLOSE_TIMEOUT_MS = 30_000;
|
|
|
44
49
|
export const MEASURE_TIMEOUT_MS = 1_000;
|
|
45
50
|
/** How long setting up the input observer (`watchInput`) or taking it down may take. */
|
|
46
51
|
export const INPUT_SETUP_TIMEOUT_MS = 2_000;
|
|
52
|
+
/** How long stopping a load judged unfinished may take (see `watchContext`'s `settle`). */
|
|
53
|
+
export const STOP_LOADING_TIMEOUT_MS = 2_000;
|
|
47
54
|
/** How long saving what a screenshot needs besides the image may take. */
|
|
48
55
|
export const CAPTURE_TIMEOUT_MS = 3_000;
|
|
49
56
|
/**
|
|
@@ -131,7 +138,10 @@ const refusedIn = (url, child) => url === '' || url === LOAD_ERROR_URL || (child
|
|
|
131
138
|
* a load. `settle` waits for loads and judges them:
|
|
132
139
|
* - A load is in flight from its request until its final response or its failure. It is waited
|
|
133
140
|
* for up to its step's load timeout from its start (`NAVIGATION_TIMEOUT_MS` unless the step gives
|
|
134
|
-
* `timeoutMs`); one still in flight then did not finish.
|
|
141
|
+
* `timeoutMs`); one still in flight then did not finish. Once judged, it is stopped (CDP
|
|
142
|
+
* `Page.stopLoading` in its page, best effort): while a navigation hangs, every read of the
|
|
143
|
+
* page (scripts, screenshots) waits on it too, so the case's evidence would time out one read
|
|
144
|
+
* after another. Stopped, the page shows the document it had before.
|
|
135
145
|
* - A final response of 400 or above is an HTTP error; any other response is fine. A failure
|
|
136
146
|
* reported after the response is ignored: the response already decided. That is how Chromium
|
|
137
147
|
* ends a download (a response with `content-disposition: attachment`, then `ERR_ABORTED`), so a
|
|
@@ -167,6 +177,15 @@ const watchContext = (context, page, clock) => {
|
|
|
167
177
|
first = from;
|
|
168
178
|
return first;
|
|
169
179
|
};
|
|
180
|
+
/** The page a document request loads in, if its frame is known yet. */
|
|
181
|
+
const pageOf = (request) => {
|
|
182
|
+
try {
|
|
183
|
+
return request.frame().page();
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
170
189
|
/** Whether a request loads a document of the case's page, of another page, or neither. */
|
|
171
190
|
const kindOf = (request) => {
|
|
172
191
|
if (!request.isNavigationRequest())
|
|
@@ -201,6 +220,7 @@ const watchContext = (context, page, clock) => {
|
|
|
201
220
|
loads.set(first, {
|
|
202
221
|
step,
|
|
203
222
|
inNewTab: kind === 'popup',
|
|
223
|
+
page: kind === 'page' ? page : pageOf(first),
|
|
204
224
|
startedAt: clock.currentTimeMillisUnsafe(),
|
|
205
225
|
timeoutMs: stepTimeoutMs,
|
|
206
226
|
outcome: undefined,
|
|
@@ -272,6 +292,20 @@ const watchContext = (context, page, clock) => {
|
|
|
272
292
|
? { ...base, _tag: 'HttpError', status: outcome.status }
|
|
273
293
|
: undefined;
|
|
274
294
|
};
|
|
295
|
+
/**
|
|
296
|
+
* Stops the loads still in flight whose page is known, in that page. Best effort, each bounded:
|
|
297
|
+
* without CDP (not Chromium), or when it fails, the load goes on as before. (A new tab stuck on
|
|
298
|
+
* its first document has no page yet, and no read of the case waits on it.) Boundary: CDP
|
|
299
|
+
* sessions are Playwright promises.
|
|
300
|
+
*/
|
|
301
|
+
const stopLoading = (unfinished) => Effect.forEach(new Set(unfinished.flatMap((load) => (load.page?.isClosed() === false ? [load.page] : []))), (target) => within(STOP_LOADING_TIMEOUT_MS,
|
|
302
|
+
// All of it interruptible, so the bound holds; a session cut short goes with the
|
|
303
|
+
// context.
|
|
304
|
+
Effect.gen(function* () {
|
|
305
|
+
const session = yield* attempt(() => context.newCDPSession(target), firstLine);
|
|
306
|
+
yield* attempt(() => session.send('Page.stopLoading'), firstLine).pipe(Effect.ignore);
|
|
307
|
+
yield* attempt(() => session.detach(), firstLine);
|
|
308
|
+
})), { concurrency: 'unbounded', discard: true });
|
|
275
309
|
return {
|
|
276
310
|
settle: (next, loadTimeoutMs) => Effect.gen(function* () {
|
|
277
311
|
for (let wait = nextDeadline(); wait !== undefined; wait = nextDeadline())
|
|
@@ -287,6 +321,9 @@ const watchContext = (context, page, clock) => {
|
|
|
287
321
|
if (problem !== undefined && (first === undefined || problem.step < first.step))
|
|
288
322
|
first = problem;
|
|
289
323
|
}
|
|
324
|
+
// Only after the verdict, so it changes nothing judged. A stopped load ends as aborted,
|
|
325
|
+
// and it is no longer among the loads watched.
|
|
326
|
+
yield* stopLoading(judged.filter((load) => load.outcome === undefined));
|
|
290
327
|
return first;
|
|
291
328
|
}),
|
|
292
329
|
refused: Effect.sync(() => refused),
|
|
@@ -1829,6 +1866,44 @@ drawn) => {
|
|
|
1829
1866
|
}),
|
|
1830
1867
|
};
|
|
1831
1868
|
};
|
|
1869
|
+
/** How long a new recorded tab may take to paint its video's first frame. */
|
|
1870
|
+
export const FIRST_FRAME_TIMEOUT_MS = 2_000;
|
|
1871
|
+
/** How often the blank tab is repainted until its video has a first frame. */
|
|
1872
|
+
const REPAINT_EVERY_MS = 50;
|
|
1873
|
+
/**
|
|
1874
|
+
* When a recorded tab's video starts, in epoch ms; undefined when no frame came in time.
|
|
1875
|
+
*
|
|
1876
|
+
* Playwright's video starts at the first frame the browser sends, not when the tab opens, and
|
|
1877
|
+
* every frame sits on the video at its paint time from there. Steps are timed from the video's
|
|
1878
|
+
* start, so it has to be known. The blank tab's own paint often comes before the browser starts
|
|
1879
|
+
* sending frames; then the first frame was the first page's, after its load, and every step came
|
|
1880
|
+
* up on the video early by that long: a field filled on the video while the walkthrough still
|
|
1881
|
+
* played the step before. So the blank tab is repainted (white and almost white, by turns) until
|
|
1882
|
+
* a frame comes, before any page of the run loads; a repaint that only arrives once a page has
|
|
1883
|
+
* loaded leaves it alone. A listener that starts after a frame is handed the latest one at once,
|
|
1884
|
+
* which for a blank tab is its first. Frame times are the browser's wall clock, the one `Clock`
|
|
1885
|
+
* reads in a run. The listener is let go of when this ends, timed out or not.
|
|
1886
|
+
*/
|
|
1887
|
+
export const firstFrameAt = (page) => Effect.gen(function* () {
|
|
1888
|
+
let frame;
|
|
1889
|
+
let seen = () => undefined;
|
|
1890
|
+
// Boundary: Playwright hands frames to a callback.
|
|
1891
|
+
const first = new Promise((resolve) => {
|
|
1892
|
+
seen = resolve;
|
|
1893
|
+
});
|
|
1894
|
+
yield* Effect.acquireRelease(attempt(() => page.screencast.start({
|
|
1895
|
+
onFrame: ({ timestamp }) => {
|
|
1896
|
+
frame ??= timestamp;
|
|
1897
|
+
seen();
|
|
1898
|
+
},
|
|
1899
|
+
}), firstLine), (listening) => attempt(() => listening.dispose(), firstLine).pipe(Effect.timeoutOption(ACTION_TIMEOUT_MS), Effect.ignore));
|
|
1900
|
+
for (let turn = 0; frame === undefined; turn++) {
|
|
1901
|
+
const color = turn % 2 === 1 ? '#fff' : '#fefefe';
|
|
1902
|
+
yield* attempt(() => page.evaluate(`location.href === 'about:blank' && (document.documentElement.style.backgroundColor = '${color}')`), firstLine).pipe(Effect.ignore);
|
|
1903
|
+
yield* Effect.promise(() => first).pipe(Effect.timeoutOption(REPAINT_EVERY_MS));
|
|
1904
|
+
}
|
|
1905
|
+
return frame;
|
|
1906
|
+
}).pipe(Effect.scoped, Effect.timeoutOption(FIRST_FRAME_TIMEOUT_MS), Effect.map((first) => (first._tag === 'Some' ? first.value : undefined)), Effect.orElseSucceed(() => undefined));
|
|
1832
1907
|
/**
|
|
1833
1908
|
* One session: a fresh context (no cookies or storage from other runs) with one tab that every
|
|
1834
1909
|
* case of the session runs in, recorded as one continuous video. Tabs and windows a case opens
|
|
@@ -1836,8 +1911,8 @@ drawn) => {
|
|
|
1836
1911
|
* is saved then too, so a run that is stopped keeps it.
|
|
1837
1912
|
*
|
|
1838
1913
|
* Playwright records each tab's video separately, so only the session's own tab is kept: the
|
|
1839
|
-
* videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg
|
|
1840
|
-
*
|
|
1914
|
+
* videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg: a session
|
|
1915
|
+
* with `video` that cannot be recorded fails rather than run without one.
|
|
1841
1916
|
*/
|
|
1842
1917
|
export const newSession = (browser, device, video,
|
|
1843
1918
|
/** Whether to watch the input the page gets, for recording actions; for tests to compare. */
|
|
@@ -1855,14 +1930,14 @@ observed = true) => Effect.gen(function* () {
|
|
|
1855
1930
|
// Only reached when opening it went wrong, or once the session closed it already
|
|
1856
1931
|
// (`closeAll`): a failure to close it again cannot change what the session found.
|
|
1857
1932
|
(context) => attempt(() => context.close(), firstLine).pipe(Effect.ignore)).pipe(Effect.flatMap((context) => attempt(() => context.newPage(), failed).pipe(Effect.map((page) => ({ context, page })))));
|
|
1858
|
-
|
|
1933
|
+
// Video is not optional: a session that cannot be recorded does not run.
|
|
1859
1934
|
const { context, page } = yield* video === undefined
|
|
1860
1935
|
? open(false)
|
|
1861
|
-
: open(true).pipe(Effect.
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
const videoStartedAt =
|
|
1936
|
+
: open(true).pipe(Effect.mapError((error) => new PageActionFailed({
|
|
1937
|
+
message: `The session could not be recorded as video (run \`npx screw-bugs doctor\` to see what is missing): ${error.message}`,
|
|
1938
|
+
})));
|
|
1939
|
+
const tabOpenedAt = clock.currentTimeMillisUnsafe();
|
|
1940
|
+
const videoStartedAt = video === undefined ? tabOpenedAt : ((yield* firstFrameAt(page)) ?? tabOpenedAt);
|
|
1866
1941
|
// Boundary: Playwright reports crashes and closes through event callbacks.
|
|
1867
1942
|
let closing = false;
|
|
1868
1943
|
let crashed;
|
|
@@ -1885,8 +1960,10 @@ observed = true) => Effect.gen(function* () {
|
|
|
1885
1960
|
closing = true;
|
|
1886
1961
|
await context.close().catch(() => undefined);
|
|
1887
1962
|
const recorded = page.video();
|
|
1888
|
-
if (video === undefined
|
|
1889
|
-
return
|
|
1963
|
+
if (video === undefined)
|
|
1964
|
+
return undefined;
|
|
1965
|
+
if (recorded === null)
|
|
1966
|
+
return 'The session was not recorded.';
|
|
1890
1967
|
try {
|
|
1891
1968
|
await recorded.saveAs(video.path);
|
|
1892
1969
|
await recorded.delete();
|
|
@@ -1900,10 +1977,10 @@ observed = true) => Effect.gen(function* () {
|
|
|
1900
1977
|
.video()
|
|
1901
1978
|
?.delete()
|
|
1902
1979
|
.catch(() => undefined);
|
|
1903
|
-
return
|
|
1980
|
+
return undefined;
|
|
1904
1981
|
})());
|
|
1905
1982
|
// Closing never fails the session: what went wrong is said about the video, which it is for.
|
|
1906
|
-
const close = attempt(closeAll, (error) => `The video could not be saved: ${firstLine(error)}`).pipe(Effect.catchTag('PageActionFailed', (error) => Effect.succeed(video === undefined ?
|
|
1983
|
+
const close = attempt(closeAll, (error) => `The video could not be saved: ${firstLine(error)}`).pipe(Effect.catchTag('PageActionFailed', (error) => Effect.succeed(video === undefined ? undefined : error.message)), Effect.timeoutOption(CLOSE_TIMEOUT_MS), Effect.map((problem) => ({
|
|
1907
1984
|
videoProblem: problem._tag === 'Some'
|
|
1908
1985
|
? problem.value
|
|
1909
1986
|
: `The video was not saved within ${seconds(CLOSE_TIMEOUT_MS)}.`,
|
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-10T09:56:26.186Z-6571d75b",
|
|
3
|
+
"builtAt": "2026-11-10T09:56:26.186Z",
|
|
4
|
+
"commit": "c84eb2077e32061689180b9d739bda0c7cd97da5"
|
|
5
5
|
}
|