screw-bugs 0.1.7 → 0.1.9
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 +83 -13
- package/dist/browser-playwright/launch.js +27 -10
- package/dist/browser-playwright/page.d.ts +50 -28
- package/dist/browser-playwright/page.js +101 -91
- package/dist/browser-playwright/recorder.d.ts +154 -0
- package/dist/browser-playwright/recorder.js +382 -0
- package/dist/build-info.json +3 -3
- package/dist/cli/commands.js +56 -11
- package/dist/cli/mcp.d.ts +11 -4
- package/dist/cli/mcp.js +86 -23
- package/dist/cli/operations.d.ts +30 -2
- package/dist/cli/operations.js +126 -20
- package/dist/cli/report-links.js +2 -2
- package/dist/cli/report-server.d.ts +41 -9
- package/dist/cli/report-server.js +139 -23
- package/dist/cli/share.d.ts +71 -4
- package/dist/cli/share.js +540 -109
- package/dist/cli/sign-in.d.ts +22 -10
- package/dist/cli/sign-in.js +23 -23
- package/dist/core/engine.js +54 -13
- package/dist/core/liveness.js +3 -1
- package/dist/core/services.d.ts +29 -4
- package/dist/core/share.d.ts +31 -0
- package/dist/core/share.js +139 -0
- package/dist/core/steps.d.ts +5 -0
- package/dist/core/steps.js +15 -1
- package/dist/core/video.d.ts +6 -0
- package/dist/core/video.js +8 -0
- package/dist/report/html.d.ts +4 -2
- package/dist/report/html.js +36 -13
- package/dist/report/icons.d.ts +3 -0
- package/dist/report/icons.js +5 -1
- package/dist/report/index.d.ts +3 -1
- package/dist/report/index.js +3 -1
- package/dist/report/live.d.ts +7 -0
- package/dist/report/live.js +135 -0
- package/dist/report/menu-bar.d.ts +3 -3
- package/dist/report/menu-bar.js +3 -3
- package/dist/report/player.d.ts +3 -3
- package/dist/report/player.js +3 -3
- package/dist/report/share-page.d.ts +48 -0
- package/dist/report/share-page.js +291 -0
- package/dist/report/styles.d.ts +2 -0
- package/dist/report/styles.js +2 -2
- package/dist/report/view.js +2 -0
- package/dist/report/walkthrough.d.ts +5 -2
- package/dist/report/walkthrough.js +17 -5
- package/dist/schema/accounts.js +10 -1
- package/dist/schema/evidence.d.ts +15 -8
- package/dist/schema/evidence.js +9 -4
- package/dist/schema/findings.js +1 -1
- package/dist/schema/job.d.ts +205 -65
- package/dist/schema/job.js +63 -11
- package/dist/schema/ledger.d.ts +80 -16
- package/dist/schema/ledger.js +36 -0
- package/dist/schema/share.d.ts +17 -0
- package/dist/schema/share.js +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -125,7 +125,18 @@ Without a write-up the report still renders from the run alone.
|
|
|
125
125
|
|
|
126
126
|
`run_status` takes a `jobId` and an optional `waitSeconds` (0–60, default 0): if the run is still
|
|
127
127
|
queued or running, it waits up to that long for the run to end before replying. It rereads the
|
|
128
|
-
ledger, so it also works for runs started by another process.
|
|
128
|
+
ledger, so it also works for runs started by another process. While the run is still going, the
|
|
129
|
+
reply says which case and step it is on, then gives the run folder, `ledger.json` and its live page
|
|
130
|
+
(see [Following a run](#following-a-run)):
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
Job 20261029-104857-3f9a01c2 is running case 2 of 3 (reply-maya), step 4 (click): 0 passed, 1 failed, 0 blocked, 1 not verified; follow it as it runs in live.html (the URL below).
|
|
134
|
+
/path/to/project/.screw-bugs/runs/20261029-104857-3f9a01c2
|
|
135
|
+
/path/to/project/.screw-bugs/runs/20261029-104857-3f9a01c2/ledger.json
|
|
136
|
+
http://127.0.0.1:41234/20261029-104857-3f9a01c2/live.html
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Once the run has ended, its reply is
|
|
129
140
|
the counts, then a compact evidence pack: two lines per case (cases that did not pass first), the
|
|
130
141
|
status and reason, then the deciding step and when it ran, the screenshot IDs, the timecodes (ms
|
|
131
142
|
into the session video) a write-up may use, where the page was, HTTP errors, the visible text
|
|
@@ -326,6 +337,7 @@ Chromium: this catches responsive layout and touch problems, not Safari-only bug
|
|
|
326
337
|
| `goto` | `url` | Open a URL; paths resolve against the job URL. HTTP 400+ fails. |
|
|
327
338
|
| `reload` | | Reload the page; judged like `goto` |
|
|
328
339
|
| `click` | `target` | Click an element; a page it opens with HTTP 400+ fails |
|
|
340
|
+
| `hover` | `target` | Move the pointer over an element, for controls shown on hover |
|
|
329
341
|
| `fill` | `target`, `value` | Replace the value of an input |
|
|
330
342
|
| `upload` | `target`, `files` | Choose files for a file input (see [Uploads](#uploads)) |
|
|
331
343
|
| `press` | `key` | Press a key, such as `Enter`; a page it opens with 400+ fails |
|
|
@@ -711,7 +723,16 @@ When the account has no saved session for the job URL's origin, nothing starts.
|
|
|
711
723
|
reply gives a link to the live view (`http://127.0.0.1:<port>/<token>/`); open it, sign in as that
|
|
712
724
|
user (OAuth redirects and codes by email or an app work; passkeys and security keys do not, since
|
|
713
725
|
they need your own device), press **Save sign-in**, then
|
|
714
|
-
have your agent start the job again.
|
|
726
|
+
have your agent start the job again. `start_run` also takes an optional `waitSeconds` (0–600,
|
|
727
|
+
default 0): with it, the call waits up to that long for you to press **Save sign-in** and then
|
|
728
|
+
starts the run, so nobody has to tell the agent you are done. Since the link reaches you only in a
|
|
729
|
+
reply, an agent calls once without `waitSeconds` to get the link and show it to you, then again
|
|
730
|
+
with `waitSeconds` to wait. The wait counts from the call, opening the sign-in included; when it
|
|
731
|
+
runs out, a save already in progress gets up to 5 seconds to finish, then the call looks for a saved session once more and otherwise gives the same link again.
|
|
732
|
+
The live view opens the app at once, so when the account is not in `.screw-bugs/accounts.json`
|
|
733
|
+
yet, agents first get the app running and what that user needs to sign in (the user itself, in a
|
|
734
|
+
local database), then start the job before the rest of their preparation (seeding test data), so
|
|
735
|
+
you can sign in meanwhile. From the CLI, `screw-bugs run` exits with code 9
|
|
715
736
|
(`SignInNeeded`) and prints the command that opens the live view:
|
|
716
737
|
|
|
717
738
|
```sh
|
|
@@ -720,9 +741,10 @@ npx screw-bugs accounts sign-in trial-user --url http://localhost:3000 --about "
|
|
|
720
741
|
|
|
721
742
|
- **On another device.** The live view listens on 127.0.0.1, so by default it opens only on this
|
|
722
743
|
machine (in your coding tool's browser, for example). To sign in from your phone or another
|
|
723
|
-
computer on your network or tailnet, set `SCREW_BUGS_SIGN_IN_HOST`
|
|
724
|
-
|
|
725
|
-
|
|
744
|
+
computer on your network or tailnet, set `SCREW_BUGS_SIGN_IN_HOST` as `SCREW_BUGS_REPORT_HOST`
|
|
745
|
+
(below): this machine's full MagicDNS name or its Tailscale IP (`tailscale ip -4`). The link
|
|
746
|
+
then uses what you set, and with a name the IP it resolves to works too. It never listens on
|
|
747
|
+
every interface. The link holds a random token and works only while that
|
|
726
748
|
sign-in is open; it closes when you save or cancel, after 15 minutes without use, or when the
|
|
727
749
|
MCP server or the command stops.
|
|
728
750
|
- **Keeping it current.** A session is saved for one origin; a job on another origin (staging
|
|
@@ -754,6 +776,7 @@ npx screw-bugs accounts sign-in trial-user --url http://localhost:3000 --about "
|
|
|
754
776
|
| `report <job-id> --serve [--port N]` | Serve the report at a `http://127.0.0.1` URL |
|
|
755
777
|
| `walkthrough <job-id> [--serve]` | Write (or serve) the run's video walkthrough |
|
|
756
778
|
| `findings <job-id> <file\|->` | Submit an agent's write-up of an ended run |
|
|
779
|
+
| `schema <job\|findings>` | Print the JSON Schema of a job or write-up |
|
|
757
780
|
| `share <job-id>` | Share a report through Screw Bugs Cloud |
|
|
758
781
|
| `runs` | List recent runs |
|
|
759
782
|
| `analytics` | Show whether analytics are on (off by default) |
|
|
@@ -765,12 +788,14 @@ Runs go to `.screw-bugs/runs/<job-id>/` in your project: `job.json`, `ledger.jso
|
|
|
765
788
|
reason of every case, and when each case and step ran in the video), `evidence/` (screenshots, each
|
|
766
789
|
with a `.json` file of the page state at that moment), `video/` (one video per session),
|
|
767
790
|
`evidence.json` (the evidence pack), `findings.json` and `annotated/` (once an agent submitted a
|
|
768
|
-
write-up), `
|
|
769
|
-
`
|
|
791
|
+
write-up), `live.html` (see [Following a run](#following-a-run)), `report.html` (or
|
|
792
|
+
`report-interrupted.html`; see [Report](#report)) and `walkthrough.html` (see
|
|
793
|
+
[Walkthrough](#walkthrough)). The folder
|
|
770
794
|
ignores itself in git.
|
|
771
795
|
|
|
772
796
|
Besides screenshot steps and the page when a case stopped, a case gets a screenshot at each step
|
|
773
|
-
that acts on or finds an element: before a click, after a fill
|
|
797
|
+
that acts on or finds an element: before a click, after a fill or a hover (showing what the hover
|
|
798
|
+
revealed), and when expected text appears,
|
|
774
799
|
with the box of that element; and after each `waitFor` and `scroll`, of what is in view. Each
|
|
775
800
|
screenshot's `.json` holds the elements of the page and of the frames visible on it (at most 8
|
|
776
801
|
frames and 150 elements each, 400 in all frames together), with their boxes on the image. Video problems (no recording possible, an empty or cut-short file)
|
|
@@ -795,6 +820,23 @@ only once the heartbeat is 10 minutes old. They never write or remove `report.ht
|
|
|
795
820
|
itself writes that. If the process comes back anyway, its `report.html` takes precedence, and it
|
|
796
821
|
deletes the interrupted report once it has written its own.
|
|
797
822
|
|
|
823
|
+
### Following a run
|
|
824
|
+
|
|
825
|
+
While a run is going, it writes `live.html` into its folder: a page to watch it on, with the
|
|
826
|
+
counts, every case (passed, failed, blocked, running or pending) and the case and step it is on.
|
|
827
|
+
The run writes it when it starts and again with every write of `ledger.json` (when a case ends,
|
|
828
|
+
and every 5 seconds with its heartbeat), and the page reloads itself every 3 seconds. `ledger.json`
|
|
829
|
+
keeps where the run is as `progress` (`{ "case": 2, "step": 4, "kind": "click" }`), saved with
|
|
830
|
+
those writes, so it may be a few seconds behind. When the run ends, its last write of `live.html`
|
|
831
|
+
stops the reloading and links `report.html` (and `walkthrough.html`). If the run's process dies,
|
|
832
|
+
the page's "last updated" time stops moving; `status` and `run_status` then report the run as
|
|
833
|
+
errored and give its interrupted report, as above.
|
|
834
|
+
|
|
835
|
+
`run_status` and `status` give its URL while the run is going (its path when there is no URL, see
|
|
836
|
+
[Viewing reports](#viewing-reports); with `--json`, `livePath` and `liveUrl`), and say which case
|
|
837
|
+
and step the run is on in their first sentence. `live.html` is never the report: the
|
|
838
|
+
report rules below do not change.
|
|
839
|
+
|
|
798
840
|
### Report
|
|
799
841
|
|
|
800
842
|
Every run that ends, finished or errored, writes `report.html` into its folder. One page, one
|
|
@@ -894,7 +936,11 @@ apart from a page zoomed in and moved, so a phone click there records only its t
|
|
|
894
936
|
On a desktop, where only pinch zoom moves the page, every browser records the point. Only
|
|
895
937
|
those count, because a page cannot make them trusted itself. It can make trusted edits
|
|
896
938
|
(`document.execCommand`), so typing into a field, and files set on a file input directly, have no
|
|
897
|
-
time or point of their own: their label shows while the step plays. A
|
|
939
|
+
time or point of their own: their label shows while the step plays. A `hover` has none either:
|
|
940
|
+
when a page moves or scrolls under a mouse that stands still, the browser itself sends trusted
|
|
941
|
+
mouse events, so no mouse move proves where or when a hover moved it. Its label shows while the
|
|
942
|
+
step plays, and the cursor is hidden from then until the next click (also after a hover that
|
|
943
|
+
failed, which may have moved the mouse all the same), never left where the mouse no longer is. A step whose input was not
|
|
898
944
|
seen, such as a click inside an iframe, gets no cursor point and no ripple, never a guessed one,
|
|
899
945
|
and its label shows while the step plays. With reduced
|
|
900
946
|
motion the cursor jumps instead of gliding and there is no ripple. **Show cursor** under the video
|
|
@@ -932,12 +978,13 @@ Browsers built into coding tools, such as Cursor's browser or the browser pane o
|
|
|
932
978
|
desktop app, cannot open `file://` pages, but they can open `http://127.0.0.1`. Use a URL instead:
|
|
933
979
|
|
|
934
980
|
- From an agent, `run_status` (and `submit_findings`) give the report's URL (and the
|
|
935
|
-
walkthrough's) in place of its path. The MCP server starts a small local server for this the first time it has a report to give,
|
|
981
|
+
walkthrough's, or while the run is going, its `live.html`'s) in place of its path. The MCP server starts a small local server for this the first time it has a report to give,
|
|
936
982
|
and keeps it for as long as it runs; one per MCP server. `SCREW_BUGS_SERVE=0` turns it off, and
|
|
937
983
|
replies then give the paths.
|
|
938
984
|
- From a terminal (or an agent using the CLI), `run`, `status`, `report`, `walkthrough` and
|
|
939
985
|
`findings` print the report's and walkthrough's URLs in place of their paths (with `--json`,
|
|
940
|
-
`reportUrl` and `walkthroughUrl` beside `reportPath` and `walkthroughPath`)
|
|
986
|
+
`reportUrl` and `walkthroughUrl` beside `reportPath` and `walkthroughPath`), and `status` that of
|
|
987
|
+
a running run's `live.html` (`liveUrl` beside `livePath`). They use the
|
|
941
988
|
project's report server when one is up (an MCP server's, say); otherwise they start one in the
|
|
942
989
|
background, which keeps serving after the command ends and stops on its own after 30 minutes
|
|
943
990
|
without a request (an MCP server of the project then takes its port over). A command waits at
|
|
@@ -946,6 +993,19 @@ desktop app, cannot open `file://` pages, but they can open `http://127.0.0.1`.
|
|
|
946
993
|
- From a terminal, `screw-bugs report <job-id> --serve` (or `walkthrough <job-id> --serve`) writes
|
|
947
994
|
the report as `report` does, prints its URL (or the walkthrough's) and serves until Ctrl+C (which exits with 130, like any interrupted command). With
|
|
948
995
|
`--json` it prints `{ "url": "...", "ok": true, "path": "...", "reused": false }`.
|
|
996
|
+
- **On another device.** The report server listens on 127.0.0.1, so by default its links open only
|
|
997
|
+
on this machine. To open reports from your phone or another computer on your network or
|
|
998
|
+
tailnet, set `SCREW_BUGS_REPORT_HOST` in the MCP server's environment (or the shell that runs
|
|
999
|
+
the commands) to this machine's full MagicDNS name (`pop-os.tail1234.ts.net`, from `tailscale
|
|
1000
|
+
status --self`) or its Tailscale IP (`tailscale ip -4`). Links then use what you set. The
|
|
1001
|
+
server listens only on the one address that resolves to, never on every interface, and answers
|
|
1002
|
+
requests addressed to the name you set or to that address, so `http://100.x.y.z:…` works with
|
|
1003
|
+
the name set (but a bare `http://pop-os:…` only when you set `pop-os`). A name is looked up each
|
|
1004
|
+
time a server starts. The short name (`pop-os`) works too, but what it resolves to depends on
|
|
1005
|
+
this machine's DNS setup: without Tailscale's DNS it can resolve to a LAN address (opening
|
|
1006
|
+
reports to your LAN) or to loopback, which is refused (many Linux systems map the machine's own
|
|
1007
|
+
name to 127.0.1.1). Check with `getent hosts pop-os`. The Share button works there with a
|
|
1008
|
+
pairing code (see Sharing below).
|
|
949
1009
|
|
|
950
1010
|
**Ports.** Each project gets its own port in 41000–41999, the same one every time: a hash of the
|
|
951
1011
|
real path of its `.screw-bugs/runs` folder picks it. So a report link keeps working across MCP
|
|
@@ -999,7 +1059,7 @@ The one other thing they answer is the Share button's routes, under `/.screw-bug
|
|
|
999
1059
|
|
|
1000
1060
|
### Sharing
|
|
1001
1061
|
|
|
1002
|
-
A report or walkthrough opened through the report server (its `http
|
|
1062
|
+
A report or walkthrough opened through the report server (its `http://` URL) has a
|
|
1003
1063
|
**Share** button that puts the run on Screw Bugs Cloud: a link anyone can open for 7 days. Opened
|
|
1004
1064
|
from disk, or on Cloud itself, the page has no server to share it, so the button is not there.
|
|
1005
1065
|
|
|
@@ -1010,8 +1070,18 @@ from disk, or on Cloud itself, the page has no server to share it, so the button
|
|
|
1010
1070
|
its progress, then sends the browser to the share's page on Cloud: its link, when it expires,
|
|
1011
1071
|
and a button to delete it.
|
|
1012
1072
|
|
|
1073
|
+
Opened from another device (with `SCREW_BUGS_REPORT_HOST`, above), Cloud cannot send the browser
|
|
1074
|
+
back to this machine, so Share works as `stripe login` does: the report server asks Cloud for a
|
|
1075
|
+
share request and shows a pairing code with a link to `screwbugs.dev`. Type the code there and
|
|
1076
|
+
confirm; meanwhile the server asks Cloud for the ticket every couple of seconds, gets it once you
|
|
1077
|
+
confirmed, and uploads as above, and the page with the code moves on to the share. Only that page
|
|
1078
|
+
shows the code, so a share link someone else sends you cannot upload into your account.
|
|
1079
|
+
|
|
1013
1080
|
Only a person can share: it takes a click in the report and a confirmation on Cloud. The share
|
|
1014
|
-
starts only from a click in a page of the same server
|
|
1081
|
+
starts only from a click in a page of the same server. Where the browser does not say where a
|
|
1082
|
+
click came from (it says so only to 127.0.0.1 and localhost), Share first asks "Share this run on
|
|
1083
|
+
Screw Bugs Cloud?", and only that page's button, posted from the same server, starts it. The
|
|
1084
|
+
share's pages never show inside another site's page, the ticket goes only to the Cloud the
|
|
1015
1085
|
server was set up with, and a ticket works once, for the share it was made for. The `share`
|
|
1016
1086
|
command is not implemented; there is no agent or CLI path.
|
|
1017
1087
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Effect, FileSystem, Layer, Path, Schema } from 'effect';
|
|
2
2
|
import { ChildProcessSpawner } from 'effect/process';
|
|
3
3
|
import { chromium } from 'playwright-core';
|
|
4
|
-
import { Browser, BrowserNotFound } from '../core/index.js';
|
|
4
|
+
import { Browser, BrowserNotFound, PageActionFailed, } from '../core/index.js';
|
|
5
5
|
import { annotateAll } from './annotate.js';
|
|
6
6
|
import { stillVideo } from './still.js';
|
|
7
7
|
import { signInBrowser } from './sign-in.js';
|
|
8
|
-
import { deviceLabel, newSession } from './page.js';
|
|
8
|
+
import { deviceLabel, deviceScale, launchArgs, newSession } from './page.js';
|
|
9
|
+
import { videoRecording } from './recorder.js';
|
|
9
10
|
/** Order matters: prefer what the user already has installed. */
|
|
10
11
|
const candidates = [
|
|
11
12
|
{ kind: 'chrome', channel: 'chrome' },
|
|
@@ -14,9 +15,10 @@ const candidates = [
|
|
|
14
15
|
];
|
|
15
16
|
const LAUNCH_TIMEOUT_MS = 30_000;
|
|
16
17
|
/** Boundary: Playwright's launch is a promise; failures are collected into BrowserNotFound. */
|
|
17
|
-
const launch = (candidate, headed) => Effect.tryPromise(() => chromium.launch({
|
|
18
|
+
const launch = (candidate, headed, device) => Effect.tryPromise(() => chromium.launch({
|
|
18
19
|
...(candidate.channel ? { channel: candidate.channel } : {}),
|
|
19
20
|
headless: !headed,
|
|
21
|
+
args: [...launchArgs(device)],
|
|
20
22
|
timeout: LAUNCH_TIMEOUT_MS,
|
|
21
23
|
// The CLI handles SIGINT and SIGTERM (src/cli/signals.ts) and closes the browser with its
|
|
22
24
|
// scope. Playwright's own handlers would close it at once (and exit with 130 on Ctrl+C),
|
|
@@ -24,11 +26,11 @@ const launch = (candidate, headed) => Effect.tryPromise(() => chromium.launch({
|
|
|
24
26
|
handleSIGINT: false,
|
|
25
27
|
handleSIGTERM: false,
|
|
26
28
|
}));
|
|
27
|
-
/** The first browser that launches, closed with the scope. */
|
|
28
|
-
const launchAny = (headed) => Effect.gen(function* () {
|
|
29
|
+
/** The first browser that launches, for sessions on `device`; closed with the scope. */
|
|
30
|
+
const launchAny = (headed, device = 'desktop') => Effect.gen(function* () {
|
|
29
31
|
const errors = [];
|
|
30
32
|
for (const candidate of candidates) {
|
|
31
|
-
const result = yield* Effect.result(Effect.acquireRelease(launch(candidate, headed), (browser) =>
|
|
33
|
+
const result = yield* Effect.result(Effect.acquireRelease(launch(candidate, headed, device), (browser) =>
|
|
32
34
|
// Everything it was for has ended by now; a browser that fails to close changes none of
|
|
33
35
|
// it, and ends with the process.
|
|
34
36
|
Effect.tryPromise(() => browser.close()).pipe(Effect.ignore)));
|
|
@@ -41,14 +43,28 @@ const launchAny = (headed) => Effect.gen(function* () {
|
|
|
41
43
|
cause: errors,
|
|
42
44
|
});
|
|
43
45
|
});
|
|
44
|
-
|
|
46
|
+
/**
|
|
47
|
+
* How a session's video at `video` is recorded, with Playwright's ffmpeg; fails, saying what is
|
|
48
|
+
* missing, when there is no ffmpeg to record with.
|
|
49
|
+
*/
|
|
50
|
+
const recording = (video) => findFfmpeg.pipe(Effect.flatMap((lookup) => lookup.found && lookup.path !== undefined
|
|
51
|
+
? videoRecording({ ...video, ffmpeg: lookup.path })
|
|
52
|
+
: Effect.fail(new PageActionFailed({
|
|
53
|
+
message: `The session could not be recorded as video (run \`npx screw-bugs doctor\` to see what is missing): ${ffmpegProblem(lookup)}.`,
|
|
54
|
+
}))));
|
|
55
|
+
const open = (options, platform) => launchAny(options.headed, options.device).pipe(Effect.map(({ candidate, browser }) => ({
|
|
45
56
|
info: {
|
|
46
57
|
kind: candidate.kind,
|
|
47
58
|
type: browser.browserType().name(),
|
|
48
59
|
channel: candidate.channel,
|
|
49
60
|
version: browser.version(),
|
|
50
61
|
},
|
|
51
|
-
newSession: (session) =>
|
|
62
|
+
newSession: (session) => Effect.gen(function* () {
|
|
63
|
+
const video = session.video === undefined
|
|
64
|
+
? undefined
|
|
65
|
+
: yield* recording(session.video).pipe(Effect.provideContext(platform));
|
|
66
|
+
return yield* newSession(browser, session.device, video, true, session.session, deviceScale(options.device ?? 'desktop'));
|
|
67
|
+
}),
|
|
52
68
|
})));
|
|
53
69
|
/**
|
|
54
70
|
* Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. Needs the
|
|
@@ -59,6 +75,7 @@ export const BrowserPlaywright = Layer.effect(Browser, Effect.gen(function* () {
|
|
|
59
75
|
const fs = yield* FileSystem.FileSystem;
|
|
60
76
|
const path = yield* Path.Path;
|
|
61
77
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
78
|
+
const platform = yield* Effect.context();
|
|
62
79
|
const videoSupport = Effect.gen(function* () {
|
|
63
80
|
const lookup = yield* findFfmpeg;
|
|
64
81
|
if (lookup.found)
|
|
@@ -66,12 +83,12 @@ export const BrowserPlaywright = Layer.effect(Browser, Effect.gen(function* () {
|
|
|
66
83
|
return { ok: false, problem: ffmpegProblem(lookup), command: yield* installFfmpegCommand };
|
|
67
84
|
}).pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path));
|
|
68
85
|
return {
|
|
69
|
-
detect: Effect.scoped(open({ headed: false })).pipe(Effect.map((session) => session.info)),
|
|
86
|
+
detect: Effect.scoped(open({ headed: false }, platform)).pipe(Effect.map((session) => session.info)),
|
|
70
87
|
videoSupport,
|
|
71
88
|
stillVideo: (file) => findFfmpeg.pipe(Effect.flatMap((lookup) => lookup.found && lookup.path !== undefined
|
|
72
89
|
? stillVideo(lookup.path, file)
|
|
73
90
|
: Effect.succeed(undefined)), Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path), Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner)),
|
|
74
|
-
open,
|
|
91
|
+
open: (options) => open(options, platform),
|
|
75
92
|
deviceLabel,
|
|
76
93
|
annotate: (jobs) => Effect.scoped(launchAny(false).pipe(Effect.flatMap(({ browser }) => annotateAll(browser, jobs)))),
|
|
77
94
|
signIn: (url) => launchAny(false).pipe(Effect.flatMap(({ browser }) => signInBrowser(browser, url))),
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Effect, Schema, type Scope } from 'effect';
|
|
2
|
+
import type { PlatformError } from 'effect/PlatformError';
|
|
2
3
|
import { type Frame, type FrameLocator, type Browser as PlaywrightBrowser, type Page } from 'playwright-core';
|
|
3
4
|
import { type BrowserPage, PageActionFailed } from '../core/index.js';
|
|
4
5
|
import { type Device, type Point, type VisualViewport } from '../schema/index.js';
|
|
6
|
+
import type { FrameSize, Recorder } from './recorder.js';
|
|
5
7
|
/** Waiting for an element to appear before acting on it, unless the step gives `timeoutMs`. */
|
|
6
8
|
export declare const ACTION_TIMEOUT_MS = 5000;
|
|
7
9
|
/**
|
|
@@ -13,8 +15,8 @@ export declare const NAVIGATION_TIMEOUT_MS = 15000;
|
|
|
13
15
|
export declare const EXPECT_TIMEOUT_MS = 5000;
|
|
14
16
|
export declare const SCREENSHOT_TIMEOUT_MS = 10000;
|
|
15
17
|
/**
|
|
16
|
-
* How long a click or key press waits after it is dispatched, so that a navigation it
|
|
17
|
-
* starts while it is still the current step, such as a form that the Enter key submits.
|
|
18
|
+
* How long a click, hover or key press waits after it is dispatched, so that a navigation it
|
|
19
|
+
* causes starts while it is still the current step, such as a form that the Enter key submits.
|
|
18
20
|
*/
|
|
19
21
|
export declare const NAVIGATION_START_MS = 250;
|
|
20
22
|
/**
|
|
@@ -25,21 +27,25 @@ export declare const NAVIGATION_START_MS = 250;
|
|
|
25
27
|
export declare const MOBILE_DEVICE = "iPhone 17";
|
|
26
28
|
/** The device as reports show it; the engine is named because mobile is not real Safari. */
|
|
27
29
|
export declare const deviceLabel: (device: Device) => string;
|
|
30
|
+
/** The device pixels per CSS pixel `device` is shown at (3 on the phone). */
|
|
31
|
+
export declare const deviceScale: (device: Device) => number;
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
+
* Chromium's flags for a browser whose sessions are on `device`: one above 1x renders at its
|
|
34
|
+
* device pixels (`--force-device-scale-factor`), so the screencast, which sends frames at the
|
|
35
|
+
* browser's own scale and ignores the emulated one, records the phone at full resolution. The
|
|
36
|
+
* emulated scale stays what pages see (`devicePixelRatio`) and what screenshots are taken at.
|
|
37
|
+
*/
|
|
38
|
+
export declare const launchArgs: (device: Device) => ReadonlyArray<string>;
|
|
39
|
+
/**
|
|
40
|
+
* The size of a session's video: the viewport at the scale the browser renders at (`launchArgs`),
|
|
41
|
+
* the size of the screencast's frames, so a video is never scaled. Each side is rounded down to
|
|
42
|
+
* an even number, as video needs: an odd last row or column of the page (an iPhone 17's 2043rd
|
|
43
|
+
* row at 3x) is left out (see `ffmpegArgs`).
|
|
33
44
|
*/
|
|
34
|
-
export declare const VIDEO_MAX: {
|
|
35
|
-
readonly width: 1920;
|
|
36
|
-
readonly height: 1080;
|
|
37
|
-
};
|
|
38
|
-
/** The size of a session's video for a viewport: the viewport, scaled down into `VIDEO_MAX`. */
|
|
39
45
|
export declare const videoSize: (viewport: {
|
|
40
46
|
readonly width: number;
|
|
41
47
|
readonly height: number;
|
|
42
|
-
}) => {
|
|
48
|
+
}, scale: number) => {
|
|
43
49
|
width: number;
|
|
44
50
|
height: number;
|
|
45
51
|
};
|
|
@@ -387,28 +393,44 @@ export declare const ELSEWHERE_TIMEOUT_MS = 1000;
|
|
|
387
393
|
/** How long a new recorded tab may take to paint its video's first frame. */
|
|
388
394
|
export declare const FIRST_FRAME_TIMEOUT_MS = 2000;
|
|
389
395
|
/**
|
|
390
|
-
* When a recorded tab's video starts, in epoch ms
|
|
396
|
+
* When a recorded tab's video starts, in epoch ms (`first`, the recorder's first frame);
|
|
397
|
+
* undefined when no frame came in time.
|
|
391
398
|
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* which for a blank tab is its first. Frame times are the browser's wall clock, the one `Clock`
|
|
401
|
-
* reads in a run. The listener is let go of when this ends, timed out or not.
|
|
399
|
+
* The video starts at the first frame the browser sends, not when the tab opens, and every
|
|
400
|
+
* frame sits on the video at its paint time from there. Steps are timed from the video's start,
|
|
401
|
+
* so it has to be known. The blank tab's own paint often comes before the browser starts sending
|
|
402
|
+
* frames; then the first frame was the first page's, after its load, and every step came up on
|
|
403
|
+
* the video early by that long: a field filled on the video while the walkthrough still played
|
|
404
|
+
* the step before. So the blank tab is repainted (white and almost white, by turns) until a frame
|
|
405
|
+
* comes, before any page of the run loads; a repaint that only arrives once a page has loaded
|
|
406
|
+
* leaves it alone. Frame times are the browser's wall clock, the one `Clock` reads in a run.
|
|
402
407
|
*/
|
|
403
|
-
export declare const firstFrameAt: (page: Page) => Effect.Effect<number | undefined, never, never>;
|
|
404
|
-
|
|
405
|
-
|
|
408
|
+
export declare const firstFrameAt: (page: Page, first: Effect.Effect<number>) => Effect.Effect<number | undefined, never, never>;
|
|
409
|
+
/** Where a session's video goes, and how it is recorded (`videoRecording`). */
|
|
410
|
+
export interface SessionVideo {
|
|
411
|
+
/** The video, a `.webm`. */
|
|
406
412
|
readonly path: string;
|
|
407
|
-
|
|
413
|
+
/** Starts recording a tab into `path` at `size`. */
|
|
414
|
+
readonly record: (page: Page, size: FrameSize) => Effect.Effect<Recorder, PlatformError | Error, Scope.Scope>;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* One session: a fresh context (no cookies or storage from other runs) with one tab that every
|
|
418
|
+
* case of the session runs in, recorded as one continuous video. Tabs and windows a case opens
|
|
419
|
+
* are in the same context and are closed before the next case; only the session's own tab is
|
|
420
|
+
* recorded. Closed with its scope; the video is saved then too, so a run that is stopped keeps
|
|
421
|
+
* it.
|
|
422
|
+
*
|
|
423
|
+
* The video is recorded by screw-bugs (`startRecorder`), not Playwright's `recordVideo`, so that
|
|
424
|
+
* a step's screenshot never shows on it (see `recorder.ts`). Recording needs Playwright's ffmpeg:
|
|
425
|
+
* a session with `video` that cannot be recorded fails rather than run without one.
|
|
426
|
+
*/
|
|
427
|
+
export declare const newSession: (browser: PlaywrightBrowser, device: Device, video: SessionVideo | undefined,
|
|
408
428
|
/** Whether to watch the input the page gets, for recording actions; for tests to compare. */
|
|
409
429
|
observed?: boolean,
|
|
410
430
|
/** A saved session (an account's storage state, as JSON text) the context starts from. */
|
|
411
|
-
savedSession?: string
|
|
431
|
+
savedSession?: string,
|
|
432
|
+
/** The scale `browser` renders at (see `launchArgs`): its screencast frames, so its videos. */
|
|
433
|
+
renderScale?: number) => Effect.Effect<{
|
|
412
434
|
page: BrowserPage;
|
|
413
435
|
beginCase: (options: {
|
|
414
436
|
readonly continues?: boolean;
|