screw-bugs 0.1.8 → 0.1.10
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 +49 -34
- package/dist/browser-playwright/capture.js +1 -1
- package/dist/browser-playwright/launch.js +27 -10
- package/dist/browser-playwright/page.d.ts +48 -26
- package/dist/browser-playwright/page.js +86 -89
- 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/app.js +6 -2
- package/dist/cli/commands.js +4 -3
- package/dist/cli/doctor.d.ts +17 -2
- package/dist/cli/doctor.js +62 -4
- package/dist/cli/mcp.js +2 -2
- package/dist/cli/report-server.d.ts +19 -10
- package/dist/cli/report-server.js +43 -18
- package/dist/cli/share.js +2 -2
- package/dist/cli/sign-in.d.ts +9 -3
- package/dist/cli/sign-in.js +12 -9
- package/dist/cli/tailnet.d.ts +57 -0
- package/dist/cli/tailnet.js +82 -0
- package/dist/core/index.d.ts +1 -14
- package/dist/core/index.js +3 -14
- package/dist/report/index.d.ts +1 -10
- package/dist/report/index.js +3 -10
- package/dist/schema/index.d.ts +1 -9
- package/dist/schema/index.js +3 -9
- package/package.json +14 -14
- package/dist/core/accounts.d.ts +0 -40
- package/dist/core/accounts.js +0 -95
- package/dist/core/css.d.ts +0 -95
- package/dist/core/css.js +0 -436
- package/dist/core/engine.d.ts +0 -75
- package/dist/core/engine.js +0 -554
- package/dist/core/errors.d.ts +0 -85
- package/dist/core/errors.js +0 -36
- package/dist/core/evidence.d.ts +0 -14
- package/dist/core/evidence.js +0 -131
- package/dist/core/labels.d.ts +0 -47
- package/dist/core/labels.js +0 -199
- package/dist/core/liveness.d.ts +0 -45
- package/dist/core/liveness.js +0 -66
- package/dist/core/marks.d.ts +0 -63
- package/dist/core/marks.js +0 -410
- package/dist/core/services.d.ts +0 -574
- package/dist/core/services.js +0 -25
- package/dist/core/share.d.ts +0 -68
- package/dist/core/share.js +0 -318
- package/dist/core/steps.d.ts +0 -106
- package/dist/core/steps.js +0 -722
- package/dist/core/uploads.d.ts +0 -49
- package/dist/core/uploads.js +0 -133
- package/dist/core/video.d.ts +0 -47
- package/dist/core/video.js +0 -233
- package/dist/core/viewport.d.ts +0 -28
- package/dist/core/viewport.js +0 -50
- package/dist/report/assets.d.ts +0 -34
- package/dist/report/assets.js +0 -105
- package/dist/report/bug.d.ts +0 -11
- package/dist/report/bug.js +0 -20
- package/dist/report/html.d.ts +0 -47
- package/dist/report/html.js +0 -923
- package/dist/report/icons.d.ts +0 -51
- package/dist/report/icons.js +0 -93
- package/dist/report/live.d.ts +0 -7
- package/dist/report/live.js +0 -135
- package/dist/report/logos.d.ts +0 -4
- package/dist/report/logos.js +0 -19
- package/dist/report/markup.d.ts +0 -50
- package/dist/report/markup.js +0 -156
- package/dist/report/menu-bar.d.ts +0 -60
- package/dist/report/menu-bar.js +0 -157
- package/dist/report/player.d.ts +0 -102
- package/dist/report/player.js +0 -315
- package/dist/report/pr-summary.d.ts +0 -11
- package/dist/report/pr-summary.js +0 -119
- package/dist/report/sha256.d.ts +0 -9
- package/dist/report/sha256.js +0 -97
- package/dist/report/share-page.d.ts +0 -48
- package/dist/report/share-page.js +0 -291
- package/dist/report/shots.d.ts +0 -59
- package/dist/report/shots.js +0 -280
- package/dist/report/sign-in.d.ts +0 -41
- package/dist/report/sign-in.js +0 -568
- package/dist/report/styles.d.ts +0 -3
- package/dist/report/styles.js +0 -274
- package/dist/report/view.d.ts +0 -296
- package/dist/report/view.js +0 -702
- package/dist/report/walkthrough.d.ts +0 -93
- package/dist/report/walkthrough.js +0 -716
- package/dist/schema/accounts.d.ts +0 -137
- package/dist/schema/accounts.js +0 -121
- package/dist/schema/config.d.ts +0 -7
- package/dist/schema/config.js +0 -6
- package/dist/schema/doctor.d.ts +0 -46
- package/dist/schema/doctor.js +0 -30
- package/dist/schema/evidence.d.ts +0 -1115
- package/dist/schema/evidence.js +0 -565
- package/dist/schema/findings.d.ts +0 -161
- package/dist/schema/findings.js +0 -82
- package/dist/schema/job.d.ts +0 -1905
- package/dist/schema/job.js +0 -577
- package/dist/schema/ledger.d.ts +0 -1124
- package/dist/schema/ledger.js +0 -285
- package/dist/schema/share.d.ts +0 -55
- package/dist/schema/share.js +0 -64
- package/dist/schema/status.d.ts +0 -7
- package/dist/schema/status.js +0 -11
package/dist/core/uploads.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/** How many bytes from the start of a file `contentMatches` looks at (text files are checked in it). */
|
|
2
|
-
export declare const UPLOAD_HEAD_BYTES: number;
|
|
3
|
-
/** How many bytes from the end: enough for a ZIP's end record with the longest comment. */
|
|
4
|
-
export declare const UPLOAD_TAIL_BYTES: number;
|
|
5
|
-
/** The start, the end and the size of a file, as `contentMatches` judges it. */
|
|
6
|
-
export interface FileSample {
|
|
7
|
-
readonly head: Uint8Array;
|
|
8
|
-
readonly tail: Uint8Array;
|
|
9
|
-
readonly size: number;
|
|
10
|
-
}
|
|
11
|
-
/** What a file should be, from its extension, such as `PDF`; `.xyz file` or `file` otherwise. */
|
|
12
|
-
export declare const uploadTypeOf: (path: string) => string;
|
|
13
|
-
/**
|
|
14
|
-
* Whether the content of a file fits its extension. Files of a type not checked (unknown or no
|
|
15
|
-
* extension) always do.
|
|
16
|
-
*/
|
|
17
|
-
export declare const contentMatches: (path: string, sample: FileSample) => boolean;
|
|
18
|
-
/** Why a file given for an upload cannot be used. */
|
|
19
|
-
export type FileProblem = 'missing' | 'not_a_file' | 'empty' | 'too_big' | 'wrong_type' | 'outside_project' | 'unreadable';
|
|
20
|
-
/** A file a job needs before it can run, and why the one on disk (if any) does not do. */
|
|
21
|
-
export interface FileNeeded {
|
|
22
|
-
/** As the job gives it, relative to the project. */
|
|
23
|
-
readonly path: string;
|
|
24
|
-
/** What it should be, from its extension (`uploadTypeOf`). */
|
|
25
|
-
readonly type: string;
|
|
26
|
-
readonly about?: string;
|
|
27
|
-
/** The job skips its content check on purpose (see `UploadFile`). */
|
|
28
|
-
readonly allowMismatch?: boolean;
|
|
29
|
-
readonly problem: FileProblem;
|
|
30
|
-
/** `problem` in words, such as `not really a PDF`. */
|
|
31
|
-
readonly reason: string;
|
|
32
|
-
}
|
|
33
|
-
/** `problem` in a few plain words, for a file of type `type`. */
|
|
34
|
-
export declare const fileProblemText: (problem: FileProblem, details: {
|
|
35
|
-
readonly type: string;
|
|
36
|
-
readonly size?: number;
|
|
37
|
-
readonly error?: string;
|
|
38
|
-
}) => string;
|
|
39
|
-
/** A files-needed reply lists at most this many files. */
|
|
40
|
-
export declare const FILES_LISTED = 10;
|
|
41
|
-
/** What the files-needed reply and the report say of a file whose content check is skipped. */
|
|
42
|
-
export declare const MISMATCH_ALLOWED = "type check skipped on purpose";
|
|
43
|
-
/**
|
|
44
|
-
* The reply when upload files are missing or unusable, so nothing started: a sentence with the
|
|
45
|
-
* count, one line per file (path, type, why, and what it should hold, whole: `about` is at most
|
|
46
|
-
* `ABOUT_MAX` characters already), then one sentence telling the caller to create them with
|
|
47
|
-
* synthetic content and start again.
|
|
48
|
-
*/
|
|
49
|
-
export declare const formatFilesNeeded: (files: ReadonlyArray<FileNeeded>) => string;
|
package/dist/core/uploads.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { UPLOAD_MAX_BYTES } from '../schema/index.js';
|
|
2
|
-
/*
|
|
3
|
-
* Upload files are made by the caller, never by screw-bugs. Before a run starts, every file its
|
|
4
|
-
* upload steps give is checked against the disk; what is wrong with one is listed as a file
|
|
5
|
-
* needed (`FileNeeded`), so the caller's agent can create it and start the run again. The content
|
|
6
|
-
* check is by magic bytes, so a text file renamed to `.pdf` is caught, unless the job skips it on
|
|
7
|
-
* purpose for that file (`allowMismatch`), to test how a site handles an invalid file.
|
|
8
|
-
*/
|
|
9
|
-
/** How many bytes from the start of a file `contentMatches` looks at (text files are checked in it). */
|
|
10
|
-
export const UPLOAD_HEAD_BYTES = 1024 * 1024;
|
|
11
|
-
/** How many bytes from the end: enough for a ZIP's end record with the longest comment. */
|
|
12
|
-
export const UPLOAD_TAIL_BYTES = 65_535 + 22;
|
|
13
|
-
const ascii = (text) => Array.from(text, (c) => c.charCodeAt(0));
|
|
14
|
-
const startsWith = (bytes, prefix, at = 0) => bytes.length >= at + prefix.length && prefix.every((b, i) => bytes[at + i] === b);
|
|
15
|
-
const includes = (bytes, needle) => {
|
|
16
|
-
for (let i = 0; i + needle.length <= bytes.length; i++)
|
|
17
|
-
if (startsWith(bytes, needle, i))
|
|
18
|
-
return true;
|
|
19
|
-
return false;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Valid UTF-8 without NUL bytes, as far as the head goes; a character cut at the end of the head
|
|
23
|
-
* is fine.
|
|
24
|
-
*/
|
|
25
|
-
const isText = ({ head }) => {
|
|
26
|
-
if (head.includes(0))
|
|
27
|
-
return false;
|
|
28
|
-
try {
|
|
29
|
-
new TextDecoder('utf-8', { fatal: true }).decode(head, { stream: true });
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const PDF_START = ascii('%PDF-');
|
|
37
|
-
const PDF_END = ascii('%%EOF');
|
|
38
|
-
const PNG_START = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
39
|
-
const PNG_END = ascii('IEND');
|
|
40
|
-
const ZIP_START = [0x50, 0x4b, 0x03, 0x04];
|
|
41
|
-
const ZIP_END = [0x50, 0x4b, 0x05, 0x06];
|
|
42
|
-
/** A ZIP archive (as Office files are): a local file header first, an end record last. */
|
|
43
|
-
const isZip = ({ head, tail }) => startsWith(head, ZIP_START) && includes(tail, ZIP_END);
|
|
44
|
-
const kinds = {
|
|
45
|
-
pdf: {
|
|
46
|
-
name: 'PDF',
|
|
47
|
-
// Readers accept a PDF whose end marker is within its last kilobyte.
|
|
48
|
-
matches: ({ head, tail }) => startsWith(head, PDF_START) && includes(tail.slice(-1024), PDF_END),
|
|
49
|
-
},
|
|
50
|
-
png: {
|
|
51
|
-
name: 'PNG image',
|
|
52
|
-
matches: ({ head, tail }) => startsWith(head, PNG_START) && includes(tail.slice(-12), PNG_END),
|
|
53
|
-
},
|
|
54
|
-
jpg: { name: 'JPEG image', matches: ({ head }) => startsWith(head, [0xff, 0xd8, 0xff]) },
|
|
55
|
-
jpeg: { name: 'JPEG image', matches: ({ head }) => startsWith(head, [0xff, 0xd8, 0xff]) },
|
|
56
|
-
gif: {
|
|
57
|
-
name: 'GIF image',
|
|
58
|
-
matches: ({ head }) => startsWith(head, ascii('GIF87a')) || startsWith(head, ascii('GIF89a')),
|
|
59
|
-
},
|
|
60
|
-
webp: {
|
|
61
|
-
name: 'WebP image',
|
|
62
|
-
matches: ({ head }) => startsWith(head, ascii('RIFF')) && startsWith(head, ascii('WEBP'), 8),
|
|
63
|
-
},
|
|
64
|
-
docx: { name: 'Word document', matches: isZip },
|
|
65
|
-
pptx: { name: 'PowerPoint presentation', matches: isZip },
|
|
66
|
-
xlsx: { name: 'Excel workbook', matches: isZip },
|
|
67
|
-
txt: { name: 'text file', matches: isText },
|
|
68
|
-
csv: { name: 'CSV file', matches: isText },
|
|
69
|
-
json: { name: 'JSON file', matches: isText },
|
|
70
|
-
md: { name: 'Markdown file', matches: isText },
|
|
71
|
-
};
|
|
72
|
-
const extensionOf = (path) => {
|
|
73
|
-
const name = path.split(/[\\/]/).at(-1) ?? path;
|
|
74
|
-
const dot = name.lastIndexOf('.');
|
|
75
|
-
return dot <= 0 ? '' : name.slice(dot + 1).toLowerCase();
|
|
76
|
-
};
|
|
77
|
-
/** What a file should be, from its extension, such as `PDF`; `.xyz file` or `file` otherwise. */
|
|
78
|
-
export const uploadTypeOf = (path) => {
|
|
79
|
-
const extension = extensionOf(path);
|
|
80
|
-
return kinds[extension]?.name ?? (extension ? `.${extension} file` : 'file');
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Whether the content of a file fits its extension. Files of a type not checked (unknown or no
|
|
84
|
-
* extension) always do.
|
|
85
|
-
*/
|
|
86
|
-
export const contentMatches = (path, sample) => kinds[extensionOf(path)]?.matches(sample) ?? true;
|
|
87
|
-
const MB = 1024 * 1024;
|
|
88
|
-
/** Rounded up, so a file just over the limit never reads as exactly the limit. */
|
|
89
|
-
const megabytes = (bytes) => `${(Math.ceil((bytes / MB) * 10) / 10).toFixed(1)} MB`;
|
|
90
|
-
/** `problem` in a few plain words, for a file of type `type`. */
|
|
91
|
-
export const fileProblemText = (problem, details) => {
|
|
92
|
-
switch (problem) {
|
|
93
|
-
case 'missing':
|
|
94
|
-
return 'missing';
|
|
95
|
-
case 'not_a_file':
|
|
96
|
-
return 'a folder, not a file';
|
|
97
|
-
case 'empty':
|
|
98
|
-
return 'empty';
|
|
99
|
-
case 'too_big':
|
|
100
|
-
return `too big (${megabytes(details.size ?? 0)}; at most ${UPLOAD_MAX_BYTES / MB} MB)`;
|
|
101
|
-
case 'wrong_type':
|
|
102
|
-
return `not really a ${details.type}; its content does not match its extension`;
|
|
103
|
-
case 'outside_project':
|
|
104
|
-
return 'outside the project (it links to a file elsewhere)';
|
|
105
|
-
case 'unreadable':
|
|
106
|
-
return `could not be read${details.error ? ` (${details.error})` : ''}`;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
/** A files-needed reply lists at most this many files. */
|
|
110
|
-
export const FILES_LISTED = 10;
|
|
111
|
-
/** What the files-needed reply and the report say of a file whose content check is skipped. */
|
|
112
|
-
export const MISMATCH_ALLOWED = 'type check skipped on purpose';
|
|
113
|
-
const oneLine = (text) => text.replace(/\s+/g, ' ').trim();
|
|
114
|
-
/**
|
|
115
|
-
* The reply when upload files are missing or unusable, so nothing started: a sentence with the
|
|
116
|
-
* count, one line per file (path, type, why, and what it should hold, whole: `about` is at most
|
|
117
|
-
* `ABOUT_MAX` characters already), then one sentence telling the caller to create them with
|
|
118
|
-
* synthetic content and start again.
|
|
119
|
-
*/
|
|
120
|
-
export const formatFilesNeeded = (files) => {
|
|
121
|
-
const lines = files
|
|
122
|
-
.slice(0, FILES_LISTED)
|
|
123
|
-
.map((file) => `- ${file.path} (${file.type}${file.allowMismatch === true ? `, ${MISMATCH_ALLOWED}` : ''}): ${file.reason}` +
|
|
124
|
-
(file.about?.trim() ? `. About: ${oneLine(file.about)}` : ''));
|
|
125
|
-
const more = files.length - FILES_LISTED;
|
|
126
|
-
const one = files.length === 1;
|
|
127
|
-
return [
|
|
128
|
-
`Nothing was started: ${files.length} upload ${one ? 'file is' : 'files are'} missing or unusable.`,
|
|
129
|
-
...lines,
|
|
130
|
-
...(more > 0 ? [`- and ${more} more.`] : []),
|
|
131
|
-
`Create ${one ? 'it' : 'them'} at ${one ? 'that path' : 'those paths'} in the project with synthetic test content (no real personal data), then start the run again.`,
|
|
132
|
-
].join('\n');
|
|
133
|
-
};
|
package/dist/core/video.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { StillStretch } from '../schema/index.js';
|
|
2
|
-
/** How many bytes from the start of a video file `webmDurationMs` needs. */
|
|
3
|
-
export declare const VIDEO_HEAD_BYTES: number;
|
|
4
|
-
/**
|
|
5
|
-
* How long a WebM video is, in ms, from the start of its file; undefined when the header does not
|
|
6
|
-
* say (a file cut short before its header was finished, or not WebM at all).
|
|
7
|
-
*/
|
|
8
|
-
export declare const webmDurationMs: (bytes: Uint8Array) => number | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Why a session's video is missing or incomplete, or undefined when it looks whole: it exists,
|
|
11
|
-
* is not empty, and is at least about as long as the session ran (it may be a little longer:
|
|
12
|
-
* the recorder keeps the last frame until the browser closes).
|
|
13
|
-
*/
|
|
14
|
-
export declare const videoProblemOf: (file: {
|
|
15
|
-
readonly size: number;
|
|
16
|
-
readonly durationMs: number | undefined;
|
|
17
|
-
} | undefined, sessionMs: number) => string | undefined;
|
|
18
|
-
/** Frames a second the video is sampled at to find where it stands still. */
|
|
19
|
-
export declare const STILL_FPS = 4;
|
|
20
|
-
/** How wide, in pixels, each sampled frame is (its height keeps the video's shape). */
|
|
21
|
-
export declare const STILL_WIDTH = 64;
|
|
22
|
-
/** A pixel changed when its grey level moved by more than this (the video's own noise stays under it). */
|
|
23
|
-
export declare const STILL_LEVEL = 8;
|
|
24
|
-
/** A frame changed when at least this many of its pixels did. */
|
|
25
|
-
export declare const STILL_PIXELS = 3;
|
|
26
|
-
/** Still stretches shorter than this are not recorded. */
|
|
27
|
-
export declare const STILL_MIN_MS = 1000;
|
|
28
|
-
/** A grey image: one byte a pixel, row by row. */
|
|
29
|
-
export interface GrayImage {
|
|
30
|
-
readonly width: number;
|
|
31
|
-
readonly height: number;
|
|
32
|
-
readonly pixels: Uint8Array;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The pixels of an 8-bit greyscale, non-interlaced PNG (what ffmpeg writes with `-pix_fmt gray`),
|
|
36
|
-
* with `inflate` to undo its zlib compression; undefined for any other PNG or a broken one.
|
|
37
|
-
*/
|
|
38
|
-
export declare const grayPng: (bytes: Uint8Array, inflate: (data: Uint8Array) => Uint8Array) => GrayImage | undefined;
|
|
39
|
-
/** Whether `next` shows something other than `previous`: `STILL_PIXELS` or more moved past `STILL_LEVEL`. */
|
|
40
|
-
export declare const frameChanged: (previous: GrayImage, next: GrayImage) => boolean;
|
|
41
|
-
/**
|
|
42
|
-
* The stretches in which frames sampled every `frameMs` (the first at 0) did not change (from one
|
|
43
|
-
* to the next, nor from the first of the stretch), at least
|
|
44
|
-
* `STILL_MIN_MS` long: from the first frame of each still run to its last, and to the end of the
|
|
45
|
-
* last frame for a run that lasts to the end. In time order.
|
|
46
|
-
*/
|
|
47
|
-
export declare const stillStretches: (frames: ReadonlyArray<GrayImage>, frameMs: number) => ReadonlyArray<StillStretch>;
|
package/dist/core/video.js
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Checking a session's video without a video library: the WebM file says how long it is in its
|
|
3
|
-
* header (Segment > Info > Duration), which is read here in pure code and compared with how long
|
|
4
|
-
* the session ran. Video problems are reported in words; they never change a status.
|
|
5
|
-
*/
|
|
6
|
-
/** How many bytes from the start of a video file `webmDurationMs` needs. */
|
|
7
|
-
export const VIDEO_HEAD_BYTES = 64 * 1024;
|
|
8
|
-
const EBML = 0x1a45dfa3;
|
|
9
|
-
const SEGMENT = 0x18538067;
|
|
10
|
-
const INFO = 0x1549a966;
|
|
11
|
-
const TIMECODE_SCALE = 0x2ad7b1;
|
|
12
|
-
const DURATION = 0x4489;
|
|
13
|
-
const CLUSTER = 0x1f43b675;
|
|
14
|
-
/** An EBML variable-length integer at `at`: its value (with or without the length marker). */
|
|
15
|
-
const vint = (bytes, at, keepMarker) => {
|
|
16
|
-
const first = bytes[at];
|
|
17
|
-
if (first === undefined || first === 0)
|
|
18
|
-
return undefined;
|
|
19
|
-
const length = Math.clz32(first) - 23;
|
|
20
|
-
if (at + length > bytes.length)
|
|
21
|
-
return undefined;
|
|
22
|
-
let value = keepMarker ? first : first & (0xff >> length);
|
|
23
|
-
let allOnes = value === 0xff >> length;
|
|
24
|
-
for (let i = 1; i < length; i++) {
|
|
25
|
-
const byte = bytes[at + i];
|
|
26
|
-
value = value * 256 + byte;
|
|
27
|
-
allOnes &&= byte === 0xff;
|
|
28
|
-
}
|
|
29
|
-
return { value, length, unknown: !keepMarker && allOnes };
|
|
30
|
-
};
|
|
31
|
-
const readUint = (bytes, at, size) => {
|
|
32
|
-
let value = 0;
|
|
33
|
-
for (let i = 0; i < size; i++)
|
|
34
|
-
value = value * 256 + bytes[at + i];
|
|
35
|
-
return value;
|
|
36
|
-
};
|
|
37
|
-
const readFloat = (bytes, at, size) => {
|
|
38
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset + at, size);
|
|
39
|
-
return size === 4 ? view.getFloat32(0) : size === 8 ? view.getFloat64(0) : undefined;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* How long a WebM video is, in ms, from the start of its file; undefined when the header does not
|
|
43
|
-
* say (a file cut short before its header was finished, or not WebM at all).
|
|
44
|
-
*/
|
|
45
|
-
export const webmDurationMs = (bytes) => {
|
|
46
|
-
let at = 0;
|
|
47
|
-
let end = bytes.length;
|
|
48
|
-
let scale = 1_000_000;
|
|
49
|
-
let duration;
|
|
50
|
-
let sawHeader = false;
|
|
51
|
-
while (at < end) {
|
|
52
|
-
const id = vint(bytes, at, true);
|
|
53
|
-
if (id === undefined)
|
|
54
|
-
return undefined;
|
|
55
|
-
const size = vint(bytes, at + id.length, false);
|
|
56
|
-
if (size === undefined)
|
|
57
|
-
return undefined;
|
|
58
|
-
const body = at + id.length + size.length;
|
|
59
|
-
if (id.value === EBML)
|
|
60
|
-
sawHeader = true;
|
|
61
|
-
if (!sawHeader)
|
|
62
|
-
return undefined;
|
|
63
|
-
if (id.value === SEGMENT || id.value === INFO) {
|
|
64
|
-
// Containers: read on inside them.
|
|
65
|
-
if (!size.unknown)
|
|
66
|
-
end = Math.min(bytes.length, body + size.value);
|
|
67
|
-
at = body;
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (size.unknown || id.value === CLUSTER)
|
|
71
|
-
break;
|
|
72
|
-
if (body + size.value > bytes.length)
|
|
73
|
-
break;
|
|
74
|
-
if (id.value === TIMECODE_SCALE)
|
|
75
|
-
scale = readUint(bytes, body, size.value);
|
|
76
|
-
if (id.value === DURATION)
|
|
77
|
-
duration = readFloat(bytes, body, size.value);
|
|
78
|
-
at = body + size.value;
|
|
79
|
-
}
|
|
80
|
-
return duration === undefined || !Number.isFinite(duration) || duration < 0
|
|
81
|
-
? undefined
|
|
82
|
-
: Math.round((duration * scale) / 1_000_000);
|
|
83
|
-
};
|
|
84
|
-
const seconds = (ms) => `${(ms / 1000).toFixed(1)} s`;
|
|
85
|
-
/**
|
|
86
|
-
* Why a session's video is missing or incomplete, or undefined when it looks whole: it exists,
|
|
87
|
-
* is not empty, and is at least about as long as the session ran (it may be a little longer:
|
|
88
|
-
* the recorder keeps the last frame until the browser closes).
|
|
89
|
-
*/
|
|
90
|
-
export const videoProblemOf = (file, sessionMs) => {
|
|
91
|
-
if (file === undefined)
|
|
92
|
-
return 'The video file was not saved.';
|
|
93
|
-
if (file.size === 0)
|
|
94
|
-
return 'The video file is empty.';
|
|
95
|
-
if (file.durationMs === undefined)
|
|
96
|
-
return 'The video file does not say how long it is, so it may have been cut short.';
|
|
97
|
-
const slack = Math.max(2_000, sessionMs * 0.1);
|
|
98
|
-
return file.durationMs < sessionMs - slack
|
|
99
|
-
? `The video is ${seconds(file.durationMs)} long, but the session ran for ${seconds(sessionMs)}.`
|
|
100
|
-
: undefined;
|
|
101
|
-
};
|
|
102
|
-
/*
|
|
103
|
-
* Where a session's video stands still, for the walkthrough's "Skip inactive". After a session,
|
|
104
|
-
* Playwright's ffmpeg writes the video as small grey PNG frames (`STILL_FPS` a second,
|
|
105
|
-
* `STILL_WIDTH` pixels wide); here, in pure code, they are decoded and compared one after
|
|
106
|
-
* another. Measuring never changes the video, a status or anything a run did.
|
|
107
|
-
*/
|
|
108
|
-
/** Frames a second the video is sampled at to find where it stands still. */
|
|
109
|
-
export const STILL_FPS = 4;
|
|
110
|
-
/** How wide, in pixels, each sampled frame is (its height keeps the video's shape). */
|
|
111
|
-
export const STILL_WIDTH = 64;
|
|
112
|
-
/** A pixel changed when its grey level moved by more than this (the video's own noise stays under it). */
|
|
113
|
-
export const STILL_LEVEL = 8;
|
|
114
|
-
/** A frame changed when at least this many of its pixels did. */
|
|
115
|
-
export const STILL_PIXELS = 3;
|
|
116
|
-
/** Still stretches shorter than this are not recorded. */
|
|
117
|
-
export const STILL_MIN_MS = 1000;
|
|
118
|
-
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
119
|
-
const paeth = (a, b, c) => {
|
|
120
|
-
const p = a + b - c;
|
|
121
|
-
const pa = Math.abs(p - a);
|
|
122
|
-
const pb = Math.abs(p - b);
|
|
123
|
-
const pc = Math.abs(p - c);
|
|
124
|
-
return pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* The pixels of an 8-bit greyscale, non-interlaced PNG (what ffmpeg writes with `-pix_fmt gray`),
|
|
128
|
-
* with `inflate` to undo its zlib compression; undefined for any other PNG or a broken one.
|
|
129
|
-
*/
|
|
130
|
-
export const grayPng = (bytes, inflate) => {
|
|
131
|
-
if (bytes.length < 8 || PNG_SIGNATURE.some((b, i) => bytes[i] !== b))
|
|
132
|
-
return undefined;
|
|
133
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
134
|
-
const tag = (at) => String.fromCharCode(...bytes.subarray(at, at + 4));
|
|
135
|
-
let width = 0;
|
|
136
|
-
let height = 0;
|
|
137
|
-
const data = [];
|
|
138
|
-
let at = 8;
|
|
139
|
-
while (at + 12 <= bytes.length) {
|
|
140
|
-
const length = view.getUint32(at);
|
|
141
|
-
const type = tag(at + 4);
|
|
142
|
-
const body = at + 8;
|
|
143
|
-
if (body + length > bytes.length)
|
|
144
|
-
return undefined;
|
|
145
|
-
if (type === 'IHDR') {
|
|
146
|
-
if (length < 13)
|
|
147
|
-
return undefined;
|
|
148
|
-
width = view.getUint32(body);
|
|
149
|
-
height = view.getUint32(body + 4);
|
|
150
|
-
const [depth, color, , , interlace] = bytes.subarray(body + 8, body + 13);
|
|
151
|
-
if (depth !== 8 || color !== 0 || interlace !== 0)
|
|
152
|
-
return undefined;
|
|
153
|
-
}
|
|
154
|
-
else if (type === 'IDAT')
|
|
155
|
-
data.push(bytes.subarray(body, body + length));
|
|
156
|
-
else if (type === 'IEND')
|
|
157
|
-
break;
|
|
158
|
-
at = body + length + 4;
|
|
159
|
-
}
|
|
160
|
-
if (width === 0 || height === 0 || data.length === 0)
|
|
161
|
-
return undefined;
|
|
162
|
-
const joined = new Uint8Array(data.reduce((n, d) => n + d.length, 0));
|
|
163
|
-
data.reduce((offset, d) => (joined.set(d, offset), offset + d.length), 0);
|
|
164
|
-
let raw;
|
|
165
|
-
try {
|
|
166
|
-
raw = inflate(joined);
|
|
167
|
-
}
|
|
168
|
-
catch {
|
|
169
|
-
return undefined;
|
|
170
|
-
}
|
|
171
|
-
if (raw.length < height * (width + 1))
|
|
172
|
-
return undefined;
|
|
173
|
-
const pixels = new Uint8Array(width * height);
|
|
174
|
-
for (let y = 0; y < height; y++) {
|
|
175
|
-
const filter = raw[y * (width + 1)];
|
|
176
|
-
const row = y * width;
|
|
177
|
-
for (let x = 0; x < width; x++) {
|
|
178
|
-
const value = raw[y * (width + 1) + 1 + x];
|
|
179
|
-
const left = x > 0 ? pixels[row + x - 1] : 0;
|
|
180
|
-
const up = y > 0 ? pixels[row - width + x] : 0;
|
|
181
|
-
const corner = x > 0 && y > 0 ? pixels[row - width + x - 1] : 0;
|
|
182
|
-
const predicted = filter === 0
|
|
183
|
-
? 0
|
|
184
|
-
: filter === 1
|
|
185
|
-
? left
|
|
186
|
-
: filter === 2
|
|
187
|
-
? up
|
|
188
|
-
: filter === 3
|
|
189
|
-
? (left + up) >> 1
|
|
190
|
-
: filter === 4
|
|
191
|
-
? paeth(left, up, corner)
|
|
192
|
-
: undefined;
|
|
193
|
-
if (predicted === undefined)
|
|
194
|
-
return undefined;
|
|
195
|
-
pixels[row + x] = (value + predicted) & 0xff;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return { width, height, pixels };
|
|
199
|
-
};
|
|
200
|
-
/** Whether `next` shows something other than `previous`: `STILL_PIXELS` or more moved past `STILL_LEVEL`. */
|
|
201
|
-
export const frameChanged = (previous, next) => {
|
|
202
|
-
if (previous.width !== next.width || previous.height !== next.height)
|
|
203
|
-
return true;
|
|
204
|
-
let changed = 0;
|
|
205
|
-
for (let i = 0; i < next.pixels.length; i++)
|
|
206
|
-
if (Math.abs(next.pixels[i] - previous.pixels[i]) > STILL_LEVEL && ++changed >= STILL_PIXELS)
|
|
207
|
-
return true;
|
|
208
|
-
return false;
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
211
|
-
* The stretches in which frames sampled every `frameMs` (the first at 0) did not change (from one
|
|
212
|
-
* to the next, nor from the first of the stretch), at least
|
|
213
|
-
* `STILL_MIN_MS` long: from the first frame of each still run to its last, and to the end of the
|
|
214
|
-
* last frame for a run that lasts to the end. In time order.
|
|
215
|
-
*/
|
|
216
|
-
export const stillStretches = (frames, frameMs) => {
|
|
217
|
-
const stretches = [];
|
|
218
|
-
const add = (from, to) => {
|
|
219
|
-
if (to - from >= STILL_MIN_MS)
|
|
220
|
-
stretches.push({ fromMs: from, toMs: to });
|
|
221
|
-
};
|
|
222
|
-
let start = 0;
|
|
223
|
-
// Each frame is compared with the one before and with the first of its still run, so a change
|
|
224
|
-
// too slow to show between two frames (a fade) still ends the run.
|
|
225
|
-
for (let i = 1; i < frames.length; i++)
|
|
226
|
-
if (frameChanged(frames[i - 1], frames[i]) || frameChanged(frames[start], frames[i])) {
|
|
227
|
-
add(start * frameMs, (i - 1) * frameMs);
|
|
228
|
-
start = i;
|
|
229
|
-
}
|
|
230
|
-
if (frames.length > 0)
|
|
231
|
-
add(start * frameMs, frames.length * frameMs);
|
|
232
|
-
return stretches;
|
|
233
|
-
};
|
package/dist/core/viewport.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Box, Device, Shot, ShotPage, StepAction, VisualViewport } from '../schema/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Where a box measured in the page's layout viewport (CSS pixels) shows in the viewport Playwright
|
|
4
|
-
* set (its CSS pixels, which is what a viewport screenshot and the video show): moved by where the
|
|
5
|
-
* visual viewport is in the layout, and scaled by its scale.
|
|
6
|
-
*/
|
|
7
|
-
export declare const layoutToScreen: (box: Box, visual: VisualViewport) => Box;
|
|
8
|
-
/**
|
|
9
|
-
* Whether boxes measured on a run on `device` can be drawn where they show: always when what they
|
|
10
|
-
* were measured in is known (`measuredIn`: a `VisualViewport` or its scale), else only on a
|
|
11
|
-
* desktop, whose visual viewport is its layout viewport. Older runs on a phone recorded boxes in
|
|
12
|
-
* the page's layout, which the phone may have shown scaled or moved: they are not drawn at all.
|
|
13
|
-
*/
|
|
14
|
-
export declare const boxesDrawable: (device: Device, measuredIn: unknown) => boolean;
|
|
15
|
-
/** Why the box of a step's element measured in the page's layout on a phone is not drawn. */
|
|
16
|
-
export declare const TARGET_UNPLACED = "the element was measured in the layout of the page, which the phone may have shown scaled or moved";
|
|
17
|
-
/**
|
|
18
|
-
* A screenshot's record as it may be drawn on a run on `device`: without `target` and
|
|
19
|
-
* `targetContent` when they cannot be placed where they show (see `boxesDrawable`), saying why.
|
|
20
|
-
*/
|
|
21
|
-
export declare const drawableShot: (shot: Shot, device: Device) => Shot;
|
|
22
|
-
/**
|
|
23
|
-
* Why the boxes of a screenshot's saved page state cannot be drawn on a run on `device`, when they
|
|
24
|
-
* cannot (see `boxesDrawable`).
|
|
25
|
-
*/
|
|
26
|
-
export declare const pageUnplaced: (page: ShotPage, device: Device) => string | undefined;
|
|
27
|
-
/** An action as it may be drawn on a run on `device`: without a `target` it cannot place. */
|
|
28
|
-
export declare const drawableAction: (action: StepAction, device: Device) => StepAction;
|
package/dist/core/viewport.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Where the page's layout shows on the screen. Element boxes are measured in the page's layout
|
|
3
|
-
* viewport (`getBoundingClientRect`), but a screenshot of the viewport, and the video, show the
|
|
4
|
-
* visual viewport: on a phone a page without a viewport meta tag is laid out 980 wide and shown at
|
|
5
|
-
* 0.41, and a page zoomed in shows part of its layout bigger. On a desktop the two are the same.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Where a box measured in the page's layout viewport (CSS pixels) shows in the viewport Playwright
|
|
9
|
-
* set (its CSS pixels, which is what a viewport screenshot and the video show): moved by where the
|
|
10
|
-
* visual viewport is in the layout, and scaled by its scale.
|
|
11
|
-
*/
|
|
12
|
-
export const layoutToScreen = (box, visual) => ({
|
|
13
|
-
x: (box.x - visual.x) * visual.scale,
|
|
14
|
-
y: (box.y - visual.y) * visual.scale,
|
|
15
|
-
width: box.width * visual.scale,
|
|
16
|
-
height: box.height * visual.scale,
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* Whether boxes measured on a run on `device` can be drawn where they show: always when what they
|
|
20
|
-
* were measured in is known (`measuredIn`: a `VisualViewport` or its scale), else only on a
|
|
21
|
-
* desktop, whose visual viewport is its layout viewport. Older runs on a phone recorded boxes in
|
|
22
|
-
* the page's layout, which the phone may have shown scaled or moved: they are not drawn at all.
|
|
23
|
-
*/
|
|
24
|
-
export const boxesDrawable = (device, measuredIn) => measuredIn !== undefined || device === 'desktop';
|
|
25
|
-
/** Why the box of a step's element measured in the page's layout on a phone is not drawn. */
|
|
26
|
-
export const TARGET_UNPLACED = 'the element was measured in the layout of the page, which the phone may have shown scaled or moved';
|
|
27
|
-
/**
|
|
28
|
-
* A screenshot's record as it may be drawn on a run on `device`: without `target` and
|
|
29
|
-
* `targetContent` when they cannot be placed where they show (see `boxesDrawable`), saying why.
|
|
30
|
-
*/
|
|
31
|
-
export const drawableShot = (shot, device) => {
|
|
32
|
-
if (shot.target === undefined || boxesDrawable(device, shot.visual))
|
|
33
|
-
return shot;
|
|
34
|
-
const { target: _target, targetContent: _content, ...rest } = shot;
|
|
35
|
-
return { ...rest, targetProblem: TARGET_UNPLACED };
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Why the boxes of a screenshot's saved page state cannot be drawn on a run on `device`, when they
|
|
39
|
-
* cannot (see `boxesDrawable`).
|
|
40
|
-
*/
|
|
41
|
-
export const pageUnplaced = (page, device) => boxesDrawable(device, page.visual)
|
|
42
|
-
? undefined
|
|
43
|
-
: 'the elements of this screenshot were measured in the layout of the page, which the phone may have shown scaled or moved';
|
|
44
|
-
/** An action as it may be drawn on a run on `device`: without a `target` it cannot place. */
|
|
45
|
-
export const drawableAction = (action, device) => {
|
|
46
|
-
if (action.target === undefined || boxesDrawable(device, action.scale))
|
|
47
|
-
return action;
|
|
48
|
-
const { target: _target, ...rest } = action;
|
|
49
|
-
return rest;
|
|
50
|
-
};
|
package/dist/report/assets.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
/**
|
|
3
|
-
* An asset base URL, for example `https://media.screwbugs.dev/runs/20261103-101500-ab12/`: an
|
|
4
|
-
* `https:` URL ending with `/`, with nothing in it that could get out of an attribute or the
|
|
5
|
-
* Content Security Policy. An uppercase or international host and an explicit `:443` are fine:
|
|
6
|
-
* the pages use the base as the URL parser normalizes it (`assetsOf`).
|
|
7
|
-
*/
|
|
8
|
-
export declare const AssetBaseUrl: Schema.brand<Schema.String, "AssetBaseUrl">;
|
|
9
|
-
export type AssetBaseUrl = typeof AssetBaseUrl.Type;
|
|
10
|
-
/** How a page is rendered. With no options, both pages are exactly as they are written locally. */
|
|
11
|
-
export interface RenderOptions {
|
|
12
|
-
/** Load the run's files from here instead of by relative path (see `AssetBaseUrl`). */
|
|
13
|
-
readonly assetBaseUrl?: AssetBaseUrl | undefined;
|
|
14
|
-
}
|
|
15
|
-
/** Where a page's links to the run's files point, and the origin its policy lets them load from. */
|
|
16
|
-
export interface Assets {
|
|
17
|
-
/** The URL of a file of the run, from its (already safe) path relative to the run folder. */
|
|
18
|
-
readonly url: (path: string) => string;
|
|
19
|
-
/** The origin files load from, when not the page's own. */
|
|
20
|
-
readonly origin: string | undefined;
|
|
21
|
-
}
|
|
22
|
-
/** Files by relative path, as the run writes them. */
|
|
23
|
-
export declare const LOCAL_ASSETS: Assets;
|
|
24
|
-
/**
|
|
25
|
-
* The page's assets for `options`. The base URL is checked again here, so a caller that skipped
|
|
26
|
-
* decoding it (or cast a string) cannot get anything unchecked into the page: it throws instead.
|
|
27
|
-
*/
|
|
28
|
-
export declare const assetsOf: (options: RenderOptions | undefined) => Assets;
|
|
29
|
-
/**
|
|
30
|
-
* Both pages' Content Security Policy: nothing by default; images and media from the page's own
|
|
31
|
-
* origin, from disk and (images) data URLs, plus the asset origin when there is one; Google Fonts'
|
|
32
|
-
* stylesheet and fonts; the one script by its hash.
|
|
33
|
-
*/
|
|
34
|
-
export declare const contentPolicy: (scriptHash: string, assetOrigin?: string) => string;
|