screw-bugs 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +906 -2
- package/bin/screw-bugs.js +29 -0
- package/dist/browser-playwright/annotate.d.ts +9 -0
- package/dist/browser-playwright/annotate.js +86 -0
- package/dist/browser-playwright/capture.d.ts +232 -0
- package/dist/browser-playwright/capture.js +1049 -0
- package/dist/browser-playwright/frames.d.ts +77 -0
- package/dist/browser-playwright/frames.js +191 -0
- package/dist/browser-playwright/index.d.ts +2 -0
- package/dist/browser-playwright/index.js +2 -0
- package/dist/browser-playwright/input.d.ts +44 -0
- package/dist/browser-playwright/input.js +116 -0
- package/dist/browser-playwright/launch.d.ts +21 -0
- package/dist/browser-playwright/launch.js +86 -0
- package/dist/browser-playwright/page.d.ts +387 -0
- package/dist/browser-playwright/page.js +1930 -0
- package/dist/build-info.json +5 -0
- package/dist/cli/app.d.ts +19 -0
- package/dist/cli/app.js +70 -0
- package/dist/cli/build-info.d.ts +52 -0
- package/dist/cli/build-info.js +82 -0
- package/dist/cli/commands.d.ts +14 -0
- package/dist/cli/commands.js +308 -0
- package/dist/cli/config.d.ts +16 -0
- package/dist/cli/config.js +71 -0
- package/dist/cli/doctor.d.ts +19 -0
- package/dist/cli/doctor.js +113 -0
- package/dist/cli/environment.d.ts +20 -0
- package/dist/cli/environment.js +34 -0
- package/dist/cli/exit-codes.d.ts +29 -0
- package/dist/cli/exit-codes.js +28 -0
- package/dist/cli/failure.d.ts +20 -0
- package/dist/cli/failure.js +15 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/install-method.d.ts +96 -0
- package/dist/cli/install-method.js +148 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +10 -0
- package/dist/cli/mcp.d.ts +30 -0
- package/dist/cli/mcp.js +309 -0
- package/dist/cli/node-version.d.ts +3 -0
- package/dist/cli/node-version.js +22 -0
- package/dist/cli/operations.d.ts +127 -0
- package/dist/cli/operations.js +337 -0
- package/dist/cli/package-info.d.ts +22 -0
- package/dist/cli/package-info.js +25 -0
- package/dist/cli/report-server.d.ts +170 -0
- package/dist/cli/report-server.js +387 -0
- package/dist/cli/signals.d.ts +37 -0
- package/dist/cli/signals.js +61 -0
- package/dist/cli/stamp-build.d.ts +1 -0
- package/dist/cli/stamp-build.js +9 -0
- package/dist/cli/update-check.d.ts +140 -0
- package/dist/cli/update-check.js +316 -0
- package/dist/cli/uploads.d.ts +16 -0
- package/dist/cli/uploads.js +80 -0
- package/dist/core/css.d.ts +95 -0
- package/dist/core/css.js +436 -0
- package/dist/core/engine.d.ts +65 -0
- package/dist/core/engine.js +436 -0
- package/dist/core/errors.d.ts +66 -0
- package/dist/core/errors.js +30 -0
- package/dist/core/evidence.d.ts +14 -0
- package/dist/core/evidence.js +127 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.js +12 -0
- package/dist/core/labels.d.ts +47 -0
- package/dist/core/labels.js +199 -0
- package/dist/core/liveness.d.ts +45 -0
- package/dist/core/liveness.js +64 -0
- package/dist/core/marks.d.ts +63 -0
- package/dist/core/marks.js +410 -0
- package/dist/core/services.d.ts +444 -0
- package/dist/core/services.js +22 -0
- package/dist/core/steps.d.ts +96 -0
- package/dist/core/steps.js +656 -0
- package/dist/core/uploads.d.ts +49 -0
- package/dist/core/uploads.js +133 -0
- package/dist/core/video.d.ts +16 -0
- package/dist/core/video.js +101 -0
- package/dist/core/viewport.d.ts +28 -0
- package/dist/core/viewport.js +50 -0
- package/dist/report/html.d.ts +37 -0
- package/dist/report/html.js +762 -0
- package/dist/report/index.d.ts +5 -0
- package/dist/report/index.js +5 -0
- package/dist/report/markup.d.ts +27 -0
- package/dist/report/markup.js +75 -0
- package/dist/report/pr-summary.d.ts +11 -0
- package/dist/report/pr-summary.js +110 -0
- package/dist/report/sha256.d.ts +9 -0
- package/dist/report/sha256.js +97 -0
- package/dist/report/styles.d.ts +1 -0
- package/dist/report/styles.js +328 -0
- package/dist/report/view.d.ts +141 -0
- package/dist/report/view.js +368 -0
- package/dist/report/walkthrough.d.ts +75 -0
- package/dist/report/walkthrough.js +458 -0
- package/dist/schema/config.d.ts +7 -0
- package/dist/schema/config.js +6 -0
- package/dist/schema/doctor.d.ts +46 -0
- package/dist/schema/doctor.js +23 -0
- package/dist/schema/evidence.d.ts +994 -0
- package/dist/schema/evidence.js +521 -0
- package/dist/schema/findings.d.ts +159 -0
- package/dist/schema/findings.js +80 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.js +7 -0
- package/dist/schema/job.d.ts +1724 -0
- package/dist/schema/job.js +505 -0
- package/dist/schema/ledger.d.ts +951 -0
- package/dist/schema/ledger.js +193 -0
- package/dist/schema/status.d.ts +7 -0
- package/dist/schema/status.js +11 -0
- package/dist/store-local/accounts.d.ts +7 -0
- package/dist/store-local/accounts.js +9 -0
- package/dist/store-local/index.d.ts +3 -0
- package/dist/store-local/index.js +3 -0
- package/dist/store-local/paths.d.ts +10 -0
- package/dist/store-local/paths.js +17 -0
- package/dist/store-local/storage.d.ts +20 -0
- package/dist/store-local/storage.js +170 -0
- package/package.json +73 -4
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** An `<iframe>` element as `frameElementInfo` describes it; offsets and sizes in CSS pixels. */
|
|
2
|
+
export interface FrameElementInfo {
|
|
3
|
+
readonly tag: string;
|
|
4
|
+
readonly role?: string;
|
|
5
|
+
readonly name?: string;
|
|
6
|
+
readonly id?: string;
|
|
7
|
+
readonly classes?: ReadonlyArray<string>;
|
|
8
|
+
readonly testId?: string;
|
|
9
|
+
readonly attrs?: Record<string, string>;
|
|
10
|
+
readonly cutAttrs?: ReadonlyArray<string>;
|
|
11
|
+
readonly omittedAttrs?: ReadonlyArray<string>;
|
|
12
|
+
readonly moreAttrs?: boolean;
|
|
13
|
+
readonly moreClasses?: boolean;
|
|
14
|
+
readonly foreign?: boolean;
|
|
15
|
+
/** The elements it is in, innermost first, as `PageNode`s without `parent`. */
|
|
16
|
+
readonly ancestors: ReadonlyArray<{
|
|
17
|
+
readonly tag: string;
|
|
18
|
+
readonly id?: string;
|
|
19
|
+
readonly classes?: ReadonlyArray<string>;
|
|
20
|
+
readonly testId?: string;
|
|
21
|
+
readonly attrs?: Record<string, string>;
|
|
22
|
+
readonly cutAttrs?: ReadonlyArray<string>;
|
|
23
|
+
readonly omittedAttrs?: ReadonlyArray<string>;
|
|
24
|
+
readonly moreAttrs?: boolean;
|
|
25
|
+
readonly moreClasses?: boolean;
|
|
26
|
+
readonly foreign?: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
readonly moreAncestors?: boolean;
|
|
29
|
+
readonly visible: boolean;
|
|
30
|
+
/** Its opacity with that of the elements around it in its document, as `captureState` reads it. */
|
|
31
|
+
readonly opacity: number;
|
|
32
|
+
/**
|
|
33
|
+
* The part of its document's viewport not cut away by the elements around it that clip their
|
|
34
|
+
* overflow, in CSS pixels of that viewport; missing when none of them does. Empty when one cuts
|
|
35
|
+
* it away whole.
|
|
36
|
+
*/
|
|
37
|
+
readonly clip?: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
43
|
+
/** Where its document starts inside its box (border and padding), and its size there. */
|
|
44
|
+
readonly left: number;
|
|
45
|
+
readonly top: number;
|
|
46
|
+
readonly width: number;
|
|
47
|
+
readonly height: number;
|
|
48
|
+
/** Its own layout size, to tell how much a CSS transform scales it on screen. */
|
|
49
|
+
readonly offsetWidth: number;
|
|
50
|
+
readonly offsetHeight: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* What a highlight can name an `<iframe>` by (its tag, role, title or ARIA label, ID, classes and
|
|
54
|
+
* test ID, other attributes and the elements it is in, at most `ancestorsMax`), whether it is
|
|
55
|
+
* visible, how transparent and how cut away it is, as `captureState` judges its own elements, and
|
|
56
|
+
* where its document shows inside it.
|
|
57
|
+
*/
|
|
58
|
+
export declare const frameElementInfo: (element: unknown, options: {
|
|
59
|
+
readonly attrsMax: number;
|
|
60
|
+
readonly attrValueMax: number;
|
|
61
|
+
readonly ancestorsMax: number;
|
|
62
|
+
}) => FrameElementInfo;
|
|
63
|
+
/**
|
|
64
|
+
* Scrolls the document `root` (its `<html>` element) is in: to its top or bottom, or by `by` CSS
|
|
65
|
+
* pixels down (negative: up), at once. Returns where it ended up.
|
|
66
|
+
*/
|
|
67
|
+
export declare const scrollDocument: (root: unknown, how: {
|
|
68
|
+
readonly to?: 'top' | 'bottom';
|
|
69
|
+
readonly by?: number;
|
|
70
|
+
}) => number;
|
|
71
|
+
/**
|
|
72
|
+
* A short CSS selector that finds `element`, an `<iframe>`, and nothing else in its document, as a
|
|
73
|
+
* person would write it: by its ID, test ID, name, title or ARIA label, else by a class (or a few),
|
|
74
|
+
* else by its `src`, else as the only frame there. Its position among the frames is the last
|
|
75
|
+
* resort (Playwright's `:nth-match`). Values longer than 60 characters are not used.
|
|
76
|
+
*/
|
|
77
|
+
export declare const frameSelector: (element: unknown) => string;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Functions that run inside the page under test, through Playwright's `evaluate`, for frames and
|
|
3
|
+
* scrolling. Like those in `capture.ts`, each one is self-contained: no imports, no helpers from
|
|
4
|
+
* outside. The project is built without DOM types; the page's globals are reached through
|
|
5
|
+
* `globalThis`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* What a highlight can name an `<iframe>` by (its tag, role, title or ARIA label, ID, classes and
|
|
9
|
+
* test ID, other attributes and the elements it is in, at most `ancestorsMax`), whether it is
|
|
10
|
+
* visible, how transparent and how cut away it is, as `captureState` judges its own elements, and
|
|
11
|
+
* where its document shows inside it.
|
|
12
|
+
*/
|
|
13
|
+
export const frameElementInfo = (element, options) => {
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
const el = element;
|
|
16
|
+
/*
|
|
17
|
+
* What a selector may name of an element, as saved (the same as in `captureState`; each function must stand alone): its classes (at most 8), and its attributes
|
|
18
|
+
* other than its ID, classes and test ID (saved as such), each value cut to `attrValueMax`
|
|
19
|
+
* characters, at most `attrsMax`. Values never saved (`style`, `value`, event handlers…) and
|
|
20
|
+
* those past the limit are named in `omittedAttrs`, and what was cut or left out is said, so
|
|
21
|
+
* a selector that depends on it is never taken as matching or not.
|
|
22
|
+
*/
|
|
23
|
+
const unsaved = new Set(['style', 'value', 'srcset', 'sizes', 'd', 'points']);
|
|
24
|
+
const namedApart = new Set(['id', 'class', 'data-testid']);
|
|
25
|
+
const savedOf = (node) => {
|
|
26
|
+
const attrs = {};
|
|
27
|
+
const cutAttrs = [];
|
|
28
|
+
const omittedAttrs = [];
|
|
29
|
+
let kept = 0;
|
|
30
|
+
let moreAttrs = false;
|
|
31
|
+
for (const attribute of Array.from(node.attributes)) {
|
|
32
|
+
const name = String(attribute.name).toLowerCase();
|
|
33
|
+
if (namedApart.has(name))
|
|
34
|
+
continue;
|
|
35
|
+
const value = String(attribute.value);
|
|
36
|
+
if (unsaved.has(name) || name.startsWith('on') || kept >= options.attrsMax) {
|
|
37
|
+
if (omittedAttrs.length < options.attrsMax)
|
|
38
|
+
omittedAttrs.push(name);
|
|
39
|
+
else
|
|
40
|
+
moreAttrs = true;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
attrs[name] = value.slice(0, options.attrValueMax);
|
|
44
|
+
if (value.length > options.attrValueMax)
|
|
45
|
+
cutAttrs.push(name);
|
|
46
|
+
kept++;
|
|
47
|
+
}
|
|
48
|
+
const all = Array.from(node.classList);
|
|
49
|
+
const classes = all.slice(0, 8);
|
|
50
|
+
return {
|
|
51
|
+
...(classes.length > 0 ? { classes } : {}),
|
|
52
|
+
...(all.length > classes.length ? { moreClasses: true } : {}),
|
|
53
|
+
...(kept > 0 ? { attrs } : {}),
|
|
54
|
+
...(cutAttrs.length > 0 ? { cutAttrs } : {}),
|
|
55
|
+
...(omittedAttrs.length > 0 ? { omittedAttrs } : {}),
|
|
56
|
+
...(moreAttrs ? { moreAttrs: true } : {}),
|
|
57
|
+
...(node.namespaceURI !== 'http://www.w3.org/1999/xhtml' ? { foreign: true } : {}),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const describe = (node) => {
|
|
61
|
+
const testId = node.getAttribute('data-testid');
|
|
62
|
+
return {
|
|
63
|
+
tag: String(node.tagName).toLowerCase(),
|
|
64
|
+
...(node.id ? { id: String(node.id) } : {}),
|
|
65
|
+
...(testId !== null ? { testId: String(testId) } : {}),
|
|
66
|
+
...savedOf(node),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const ancestors = [];
|
|
70
|
+
let up = el.parentElement;
|
|
71
|
+
for (; up && ancestors.length < options.ancestorsMax; up = up.parentElement)
|
|
72
|
+
ancestors.push(describe(up));
|
|
73
|
+
const moreAncestors = up !== null && up !== undefined;
|
|
74
|
+
const style = g.getComputedStyle(el);
|
|
75
|
+
const px = (value) => Number.parseFloat(String(value)) || 0;
|
|
76
|
+
const clean = (value) => {
|
|
77
|
+
const flat = typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : '';
|
|
78
|
+
return flat ? flat.slice(0, 200) : undefined;
|
|
79
|
+
};
|
|
80
|
+
const role = clean(el.getAttribute('role'))?.split(' ')[0];
|
|
81
|
+
const name = clean(el.getAttribute('aria-label')) ?? clean(el.getAttribute('title'));
|
|
82
|
+
const testId = el.getAttribute('data-testid');
|
|
83
|
+
const [padLeft, padTop] = [px(style.paddingLeft), px(style.paddingTop)];
|
|
84
|
+
/*
|
|
85
|
+
* The element a node shows inside, as it renders (the composed tree): the slot it is assigned
|
|
86
|
+
* to, else its parent, else the host of the shadow root it is at the top of (or is). The same in every
|
|
87
|
+
* page function here; each must stand alone. Opacity and clipping follow it.
|
|
88
|
+
*/
|
|
89
|
+
const composedUp = (node) => node.assignedSlot ?? node.parentElement ?? node.parentNode?.host ?? node.host ?? null;
|
|
90
|
+
const doc = el.ownerDocument;
|
|
91
|
+
let opacity = 1;
|
|
92
|
+
for (let up = el; up && up !== doc.documentElement; up = composedUp(up)) {
|
|
93
|
+
const own = Number.parseFloat(g.getComputedStyle(up).opacity);
|
|
94
|
+
opacity *= Number.isFinite(own) ? own : 1;
|
|
95
|
+
}
|
|
96
|
+
// As in `captureState`: the page scrolls, so its root and body do not clip.
|
|
97
|
+
let clip;
|
|
98
|
+
for (let up = composedUp(el); up && up !== doc.body; up = composedUp(up)) {
|
|
99
|
+
const around = g.getComputedStyle(up);
|
|
100
|
+
if ([around.overflowX, around.overflowY].every((o) => o === 'visible'))
|
|
101
|
+
continue;
|
|
102
|
+
const r = up.getBoundingClientRect();
|
|
103
|
+
const [left, top] = [Math.max(r.left, clip?.x ?? r.left), Math.max(r.top, clip?.y ?? r.top)];
|
|
104
|
+
const right = Math.min(r.right, clip === undefined ? r.right : clip.x + clip.width);
|
|
105
|
+
const bottom = Math.min(r.bottom, clip === undefined ? r.bottom : clip.y + clip.height);
|
|
106
|
+
clip = { x: left, y: top, width: Math.max(0, right - left), height: Math.max(0, bottom - top) };
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
tag: String(el.tagName).toLowerCase(),
|
|
110
|
+
...(role !== undefined ? { role } : {}),
|
|
111
|
+
...(name !== undefined ? { name } : {}),
|
|
112
|
+
...(el.id ? { id: String(el.id) } : {}),
|
|
113
|
+
...(testId !== null ? { testId: String(testId) } : {}),
|
|
114
|
+
...savedOf(el),
|
|
115
|
+
ancestors,
|
|
116
|
+
...(moreAncestors ? { moreAncestors: true } : {}),
|
|
117
|
+
visible: typeof el.checkVisibility === 'function'
|
|
118
|
+
? el.checkVisibility({ visibilityProperty: true })
|
|
119
|
+
: style.visibility !== 'hidden',
|
|
120
|
+
opacity,
|
|
121
|
+
...(clip !== undefined ? { clip } : {}),
|
|
122
|
+
left: (Number(el.clientLeft) || 0) + padLeft,
|
|
123
|
+
top: (Number(el.clientTop) || 0) + padTop,
|
|
124
|
+
width: Math.max(0, (Number(el.clientWidth) || 0) - padLeft - px(style.paddingRight)),
|
|
125
|
+
height: Math.max(0, (Number(el.clientHeight) || 0) - padTop - px(style.paddingBottom)),
|
|
126
|
+
offsetWidth: Number(el.offsetWidth) || 0,
|
|
127
|
+
offsetHeight: Number(el.offsetHeight) || 0,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Scrolls the document `root` (its `<html>` element) is in: to its top or bottom, or by `by` CSS
|
|
132
|
+
* pixels down (negative: up), at once. Returns where it ended up.
|
|
133
|
+
*/
|
|
134
|
+
export const scrollDocument = (root, how) => {
|
|
135
|
+
const doc = root.ownerDocument;
|
|
136
|
+
const win = doc.defaultView;
|
|
137
|
+
const scroller = doc.scrollingElement ?? doc.documentElement;
|
|
138
|
+
if (how.by !== undefined)
|
|
139
|
+
win.scrollBy({ top: how.by, left: 0, behavior: 'instant' });
|
|
140
|
+
else
|
|
141
|
+
win.scrollTo({
|
|
142
|
+
top: how.to === 'bottom' ? scroller.scrollHeight : 0,
|
|
143
|
+
left: win.scrollX,
|
|
144
|
+
behavior: 'instant',
|
|
145
|
+
});
|
|
146
|
+
return Number(win.scrollY) || 0;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* A short CSS selector that finds `element`, an `<iframe>`, and nothing else in its document, as a
|
|
150
|
+
* person would write it: by its ID, test ID, name, title or ARIA label, else by a class (or a few),
|
|
151
|
+
* else by its `src`, else as the only frame there. Its position among the frames is the last
|
|
152
|
+
* resort (Playwright's `:nth-match`). Values longer than 60 characters are not used.
|
|
153
|
+
*/
|
|
154
|
+
export const frameSelector = (element) => {
|
|
155
|
+
const el = element;
|
|
156
|
+
// Its document, or the shadow root it is in: selectors (Playwright's) reach into open ones.
|
|
157
|
+
const doc = el.getRootNode?.() ?? el.ownerDocument;
|
|
158
|
+
const tag = String(el.tagName).toLowerCase();
|
|
159
|
+
const usable = (value) => typeof value === 'string' && value.trim() !== '' && value.length <= 60;
|
|
160
|
+
const quoted = (value) => `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
161
|
+
const ident = /^-?[A-Za-z_][\w-]*$/;
|
|
162
|
+
const tries = [];
|
|
163
|
+
if (usable(el.id))
|
|
164
|
+
tries.push(ident.test(el.id) ? `#${el.id}` : `${tag}[id=${quoted(el.id)}]`);
|
|
165
|
+
for (const attribute of ['data-testid', 'name', 'title', 'aria-label']) {
|
|
166
|
+
const value = el.getAttribute(attribute);
|
|
167
|
+
if (usable(value))
|
|
168
|
+
tries.push(`${tag}[${attribute}=${quoted(value)}]`);
|
|
169
|
+
}
|
|
170
|
+
const classes = Array.from(el.classList).filter((name) => ident.test(name) && name.length <= 30);
|
|
171
|
+
for (const name of classes)
|
|
172
|
+
tries.push(`${tag}.${name}`);
|
|
173
|
+
if (classes.length > 1)
|
|
174
|
+
tries.push(`${tag}.${classes.slice(0, 3).join('.')}`);
|
|
175
|
+
const src = el.getAttribute('src');
|
|
176
|
+
if (usable(src))
|
|
177
|
+
tries.push(`${tag}[src=${quoted(src)}]`);
|
|
178
|
+
tries.push(tag);
|
|
179
|
+
for (const selector of tries) {
|
|
180
|
+
try {
|
|
181
|
+
const all = doc.querySelectorAll(selector);
|
|
182
|
+
if (all.length === 1 && all[0] === el)
|
|
183
|
+
return selector;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// Not a selector this browser takes; try the next.
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const same = Array.from(doc.querySelectorAll(tag));
|
|
190
|
+
return `:nth-match(${tag}, ${same.indexOf(el) + 1})`;
|
|
191
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** The isolated world the observer runs in, and the name of the binding it reports through. */
|
|
2
|
+
export declare const INPUT_WORLD = "screw-bugs-input";
|
|
3
|
+
export declare const INPUT_BINDING = "__screwBugsInput";
|
|
4
|
+
/**
|
|
5
|
+
* The input events the observer reports: a mouse press and a key going down. Only these, because
|
|
6
|
+
* a page cannot make a trusted one of them itself; in a session only Playwright's real input
|
|
7
|
+
* (CDP `Input.dispatch*`) does. A page's `dispatchEvent` and `element.click()` make untrusted
|
|
8
|
+
* events; activating a button with a key, clicking a label and submitting a form send a trusted
|
|
9
|
+
* `click` but no press before it; `focus()` sends focus events; `document.execCommand` sends
|
|
10
|
+
* trusted `beforeinput` and `input`, and so does setting a file input's files. So `click`,
|
|
11
|
+
* `beforeinput` and `input` could come from the page while an action runs and are not taken: a
|
|
12
|
+
* fill, and files set on an input directly, record no time or point at all.
|
|
13
|
+
*/
|
|
14
|
+
export declare const INPUT_EVENTS: readonly ['pointerdown', 'mousedown', 'keydown'];
|
|
15
|
+
/**
|
|
16
|
+
* Reports, through the binding named `binding`, each trusted input event of `types` that reached
|
|
17
|
+
* its target in the main frame. Child frames are skipped: their events never reach this window.
|
|
18
|
+
*
|
|
19
|
+
* It listens on `window` in the capture phase, where an event arrives first, and there only arms
|
|
20
|
+
* a one-time listener on the event's target; the event is reported from there. An event stopped
|
|
21
|
+
* on the way (by Playwright itself, when something covers what it would click as it presses; or
|
|
22
|
+
* by the page's own capture listeners) never reached the page's element and is not reported.
|
|
23
|
+
*
|
|
24
|
+
* Where it pressed is given as the event's `screenX` and `screenY`: on the widget the page is drawn
|
|
25
|
+
* in, in CSS pixels of the viewport Playwright set, which is what the video shows. `clientX` and
|
|
26
|
+
* `clientY` are in the page's layout viewport instead, which the video shows scaled and moved
|
|
27
|
+
* whenever the visual viewport is: a mobile page without a viewport meta tag laid out 980 wide on
|
|
28
|
+
* a phone, or one zoomed in. Sent along to check the screen point against: `clientX`, `clientY`,
|
|
29
|
+
* the visual viewport's `scale`, and the window's own `screenX` and `screenY` (where Playwright's
|
|
30
|
+
* emulation puts the widget on the screen; see `framePoint` in page.ts).
|
|
31
|
+
*
|
|
32
|
+
* It does nothing a page could notice, not even in timing: it reads only the event's own plain
|
|
33
|
+
* fields (`type`, `isTrusted`, `target`, `clientX`, `clientY`, `screenX`, `screenY`, which the
|
|
34
|
+
* browser fixed when it made the event), the window's `screenX` and `screenY`, the visual
|
|
35
|
+
* viewport's `scale`, and the clock. None of these makes the browser bring its style or layout up
|
|
36
|
+
* to date mid-dispatch, which starts and cancels CSS transitions the page's own listeners set off
|
|
37
|
+
* (tested: the visual viewport's offsets and size, and CDP's `Page.getLayoutMetrics`, all do). So
|
|
38
|
+
* no element boxes, no `offsetX` or `layerX`, no computed style, no `visualViewport.offsetLeft`.
|
|
39
|
+
* It writes nothing to the DOM. Everything is caught: nothing it does can throw into the page, and
|
|
40
|
+
* the binding answers nothing, so there is no promise to reject.
|
|
41
|
+
*/
|
|
42
|
+
export declare const observeInput: (binding: string, types: ReadonlyArray<string>) => void;
|
|
43
|
+
/** The script that sets up `observeInput` in each new document's isolated world. */
|
|
44
|
+
export declare const inputObserverSource: string;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Plain browser code: the input observer, run by CDP in an isolated world of the page under test
|
|
3
|
+
* (`watchInput` in page.ts). Its source is sent as a string, so the function is self-contained: no
|
|
4
|
+
* imports, no helpers from outside. The project is built without DOM types; the page's globals
|
|
5
|
+
* are reached through `globalThis`.
|
|
6
|
+
*
|
|
7
|
+
* An isolated world shares the page's DOM but none of its JavaScript: page scripts cannot see
|
|
8
|
+
* the observer's listeners, its globals or the binding it reports through, and cannot replace the
|
|
9
|
+
* `Date`, `performance` or `JSON` it uses. It adds nothing to the DOM and never changes an event.
|
|
10
|
+
*/
|
|
11
|
+
/** The isolated world the observer runs in, and the name of the binding it reports through. */
|
|
12
|
+
export const INPUT_WORLD = 'screw-bugs-input';
|
|
13
|
+
export const INPUT_BINDING = '__screwBugsInput';
|
|
14
|
+
/**
|
|
15
|
+
* The input events the observer reports: a mouse press and a key going down. Only these, because
|
|
16
|
+
* a page cannot make a trusted one of them itself; in a session only Playwright's real input
|
|
17
|
+
* (CDP `Input.dispatch*`) does. A page's `dispatchEvent` and `element.click()` make untrusted
|
|
18
|
+
* events; activating a button with a key, clicking a label and submitting a form send a trusted
|
|
19
|
+
* `click` but no press before it; `focus()` sends focus events; `document.execCommand` sends
|
|
20
|
+
* trusted `beforeinput` and `input`, and so does setting a file input's files. So `click`,
|
|
21
|
+
* `beforeinput` and `input` could come from the page while an action runs and are not taken: a
|
|
22
|
+
* fill, and files set on an input directly, record no time or point at all.
|
|
23
|
+
*/
|
|
24
|
+
export const INPUT_EVENTS = ['pointerdown', 'mousedown', 'keydown'];
|
|
25
|
+
/**
|
|
26
|
+
* Reports, through the binding named `binding`, each trusted input event of `types` that reached
|
|
27
|
+
* its target in the main frame. Child frames are skipped: their events never reach this window.
|
|
28
|
+
*
|
|
29
|
+
* It listens on `window` in the capture phase, where an event arrives first, and there only arms
|
|
30
|
+
* a one-time listener on the event's target; the event is reported from there. An event stopped
|
|
31
|
+
* on the way (by Playwright itself, when something covers what it would click as it presses; or
|
|
32
|
+
* by the page's own capture listeners) never reached the page's element and is not reported.
|
|
33
|
+
*
|
|
34
|
+
* Where it pressed is given as the event's `screenX` and `screenY`: on the widget the page is drawn
|
|
35
|
+
* in, in CSS pixels of the viewport Playwright set, which is what the video shows. `clientX` and
|
|
36
|
+
* `clientY` are in the page's layout viewport instead, which the video shows scaled and moved
|
|
37
|
+
* whenever the visual viewport is: a mobile page without a viewport meta tag laid out 980 wide on
|
|
38
|
+
* a phone, or one zoomed in. Sent along to check the screen point against: `clientX`, `clientY`,
|
|
39
|
+
* the visual viewport's `scale`, and the window's own `screenX` and `screenY` (where Playwright's
|
|
40
|
+
* emulation puts the widget on the screen; see `framePoint` in page.ts).
|
|
41
|
+
*
|
|
42
|
+
* It does nothing a page could notice, not even in timing: it reads only the event's own plain
|
|
43
|
+
* fields (`type`, `isTrusted`, `target`, `clientX`, `clientY`, `screenX`, `screenY`, which the
|
|
44
|
+
* browser fixed when it made the event), the window's `screenX` and `screenY`, the visual
|
|
45
|
+
* viewport's `scale`, and the clock. None of these makes the browser bring its style or layout up
|
|
46
|
+
* to date mid-dispatch, which starts and cancels CSS transitions the page's own listeners set off
|
|
47
|
+
* (tested: the visual viewport's offsets and size, and CDP's `Page.getLayoutMetrics`, all do). So
|
|
48
|
+
* no element boxes, no `offsetX` or `layerX`, no computed style, no `visualViewport.offsetLeft`.
|
|
49
|
+
* It writes nothing to the DOM. Everything is caught: nothing it does can throw into the page, and
|
|
50
|
+
* the binding answers nothing, so there is no promise to reject.
|
|
51
|
+
*/
|
|
52
|
+
export const observeInput = (binding, types) => {
|
|
53
|
+
const world = globalThis;
|
|
54
|
+
const send = world[binding];
|
|
55
|
+
// Out of sight of the world's own globals too; the function itself is kept.
|
|
56
|
+
delete world[binding];
|
|
57
|
+
if (typeof send !== 'function' || world.top !== globalThis)
|
|
58
|
+
return;
|
|
59
|
+
const report = send;
|
|
60
|
+
/** The target listener armed for each type, removed when the next event of it comes. */
|
|
61
|
+
const armed = new Map();
|
|
62
|
+
const disarm = (type) => {
|
|
63
|
+
const was = armed.get(type);
|
|
64
|
+
if (was === undefined)
|
|
65
|
+
return;
|
|
66
|
+
armed.delete(type);
|
|
67
|
+
was.node.removeEventListener(type, was.listener, true);
|
|
68
|
+
};
|
|
69
|
+
const onWindow = (event) => {
|
|
70
|
+
try {
|
|
71
|
+
// Only the browser's own events: a page's `dispatchEvent` makes untrusted ones.
|
|
72
|
+
if (!event.isTrusted)
|
|
73
|
+
return;
|
|
74
|
+
disarm(event.type);
|
|
75
|
+
const node = event.target;
|
|
76
|
+
if (node === null || node === world || typeof node !== 'object')
|
|
77
|
+
return;
|
|
78
|
+
if (typeof node.addEventListener !== 'function')
|
|
79
|
+
return;
|
|
80
|
+
// Now is when the browser dispatched it to the page: this listener was added before any of
|
|
81
|
+
// the page's, so it runs first. Not the event's `timeStamp`, which is when the input was
|
|
82
|
+
// made, possibly long before, while the page was busy. On a clock the page cannot change.
|
|
83
|
+
const at = Date.now();
|
|
84
|
+
const numbers = {
|
|
85
|
+
x: event.screenX,
|
|
86
|
+
y: event.screenY,
|
|
87
|
+
clientX: event.clientX,
|
|
88
|
+
clientY: event.clientY,
|
|
89
|
+
scale: world.visualViewport?.scale,
|
|
90
|
+
windowX: world.screenX,
|
|
91
|
+
windowY: world.screenY,
|
|
92
|
+
};
|
|
93
|
+
const point = Object.values(numbers).every((n) => typeof n === 'number') ? numbers : {};
|
|
94
|
+
const listener = (reached) => {
|
|
95
|
+
if (reached !== event)
|
|
96
|
+
return;
|
|
97
|
+
try {
|
|
98
|
+
disarm(event.type);
|
|
99
|
+
report(JSON.stringify({ type: event.type, at, ...point }));
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Nothing reported.
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
node.addEventListener(event.type, listener, true);
|
|
106
|
+
armed.set(event.type, { node, listener });
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// Nothing reported.
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
for (const type of types)
|
|
113
|
+
world.addEventListener(type, onWindow, true);
|
|
114
|
+
};
|
|
115
|
+
/** The script that sets up `observeInput` in each new document's isolated world. */
|
|
116
|
+
export const inputObserverSource = `(${observeInput.toString()})(${JSON.stringify(INPUT_BINDING)}, ${JSON.stringify(INPUT_EVENTS)});`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Effect, FileSystem, Layer, Path } from 'effect';
|
|
2
|
+
import { Browser } from '../core/index.js';
|
|
3
|
+
/** Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. */
|
|
4
|
+
export declare const BrowserPlaywright: Layer.Layer<Browser, never, never>;
|
|
5
|
+
/**
|
|
6
|
+
* Downloads the Chromium build that matches the bundled Playwright. Pinned to our version so the
|
|
7
|
+
* browser revision is the one we look for.
|
|
8
|
+
*/
|
|
9
|
+
export declare const installBrowserCommand: Effect.Effect<string, never, FileSystem.FileSystem | Path.Path>;
|
|
10
|
+
/** Downloads the ffmpeg build that the bundled Playwright records videos with. */
|
|
11
|
+
export declare const installFfmpegCommand: Effect.Effect<string, never, FileSystem.FileSystem | Path.Path>;
|
|
12
|
+
/** Where Playwright's ffmpeg is, and whether it is there. `path` is undefined when unknown. */
|
|
13
|
+
export interface FfmpegLookup {
|
|
14
|
+
readonly found: boolean;
|
|
15
|
+
readonly path: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Finds the ffmpeg Playwright records videos with, where Playwright itself looks (its registry
|
|
19
|
+
* follows PLAYWRIGHT_BROWSERS_PATH and the platform's cache folder). Never downloads anything.
|
|
20
|
+
*/
|
|
21
|
+
export declare const findFfmpeg: Effect.Effect<FfmpegLookup, never, FileSystem.FileSystem>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Effect, FileSystem, Layer, Path, Schema } from 'effect';
|
|
2
|
+
import { chromium } from 'playwright-core';
|
|
3
|
+
import { Browser, BrowserNotFound } from '../core/index.js';
|
|
4
|
+
import { annotateAll } from './annotate.js';
|
|
5
|
+
import { deviceLabel, newSession } from './page.js';
|
|
6
|
+
/** Order matters: prefer what the user already has installed. */
|
|
7
|
+
const candidates = [
|
|
8
|
+
{ kind: 'chrome', channel: 'chrome' },
|
|
9
|
+
{ kind: 'msedge', channel: 'msedge' },
|
|
10
|
+
{ kind: 'playwright-chromium', channel: undefined },
|
|
11
|
+
];
|
|
12
|
+
const LAUNCH_TIMEOUT_MS = 30_000;
|
|
13
|
+
/** Boundary: Playwright's launch is a promise; failures are collected into BrowserNotFound. */
|
|
14
|
+
const launch = (candidate, headed) => Effect.tryPromise(() => chromium.launch({
|
|
15
|
+
...(candidate.channel ? { channel: candidate.channel } : {}),
|
|
16
|
+
headless: !headed,
|
|
17
|
+
timeout: LAUNCH_TIMEOUT_MS,
|
|
18
|
+
// The CLI handles SIGINT and SIGTERM (src/cli/signals.ts) and closes the browser with its
|
|
19
|
+
// scope. Playwright's own handlers would close it at once (and exit with 130 on Ctrl+C),
|
|
20
|
+
// racing the run's final report and ledger and the message that says where they are.
|
|
21
|
+
handleSIGINT: false,
|
|
22
|
+
handleSIGTERM: false,
|
|
23
|
+
}));
|
|
24
|
+
/** The first browser that launches, closed with the scope. */
|
|
25
|
+
const launchAny = (headed) => Effect.gen(function* () {
|
|
26
|
+
const errors = [];
|
|
27
|
+
for (const candidate of candidates) {
|
|
28
|
+
const result = yield* Effect.result(Effect.acquireRelease(launch(candidate, headed), (browser) =>
|
|
29
|
+
// Everything it was for has ended by now; a browser that fails to close changes none of
|
|
30
|
+
// it, and ends with the process.
|
|
31
|
+
Effect.tryPromise(() => browser.close()).pipe(Effect.ignore)));
|
|
32
|
+
if (result._tag === 'Success')
|
|
33
|
+
return { candidate, browser: result.success };
|
|
34
|
+
errors.push(result.failure);
|
|
35
|
+
}
|
|
36
|
+
return yield* new BrowserNotFound({
|
|
37
|
+
tried: candidates.map((c) => c.kind),
|
|
38
|
+
cause: errors,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
const open = (options) => launchAny(options.headed).pipe(Effect.map(({ candidate, browser }) => ({
|
|
42
|
+
info: { kind: candidate.kind, version: browser.version() },
|
|
43
|
+
newSession: (session) => newSession(browser, session.device, session.video),
|
|
44
|
+
})));
|
|
45
|
+
/** Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. */
|
|
46
|
+
export const BrowserPlaywright = Layer.succeed(Browser, {
|
|
47
|
+
detect: Effect.scoped(open({ headed: false })).pipe(Effect.map((session) => session.info)),
|
|
48
|
+
open,
|
|
49
|
+
deviceLabel,
|
|
50
|
+
annotate: (jobs) => Effect.scoped(launchAny(false).pipe(Effect.flatMap(({ browser }) => annotateAll(browser, jobs)))),
|
|
51
|
+
});
|
|
52
|
+
const PlaywrightPackage = Schema.Struct({ version: Schema.String });
|
|
53
|
+
/** The bundled Playwright's version, for install commands pinned to it. */
|
|
54
|
+
const playwrightVersion = Effect.gen(function* () {
|
|
55
|
+
const fs = yield* FileSystem.FileSystem;
|
|
56
|
+
const path = yield* Path.Path;
|
|
57
|
+
const file = yield* path.fromFileUrl(new URL(import.meta.resolve('playwright-core/package.json')));
|
|
58
|
+
const text = yield* fs.readFileString(file);
|
|
59
|
+
const { version } = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(PlaywrightPackage))(text);
|
|
60
|
+
return version;
|
|
61
|
+
// Playwright's own package.json is part of the install; failing to read it is a defect.
|
|
62
|
+
}).pipe(Effect.orDie);
|
|
63
|
+
/**
|
|
64
|
+
* Downloads the Chromium build that matches the bundled Playwright. Pinned to our version so the
|
|
65
|
+
* browser revision is the one we look for.
|
|
66
|
+
*/
|
|
67
|
+
export const installBrowserCommand = playwrightVersion.pipe(Effect.map((version) => `npx -y playwright-core@${version} install chromium`));
|
|
68
|
+
/** Downloads the ffmpeg build that the bundled Playwright records videos with. */
|
|
69
|
+
export const installFfmpegCommand = playwrightVersion.pipe(Effect.map((version) => `npx -y playwright-core@${version} install ffmpeg`));
|
|
70
|
+
/**
|
|
71
|
+
* Finds the ffmpeg Playwright records videos with, where Playwright itself looks (its registry
|
|
72
|
+
* follows PLAYWRIGHT_BROWSERS_PATH and the platform's cache folder). Never downloads anything.
|
|
73
|
+
*/
|
|
74
|
+
export const findFfmpeg = Effect.gen(function* () {
|
|
75
|
+
// Boundary: Playwright's registry is only reachable through its untyped bundle, loaded as a
|
|
76
|
+
// promise. Any change in its shape fails here and reads as "not found".
|
|
77
|
+
const bundle = yield* Effect.tryPromise(async () => {
|
|
78
|
+
// A CommonJS module: its exports are the default export.
|
|
79
|
+
const loaded = await import(import.meta.resolve('playwright-core/lib/coreBundle'));
|
|
80
|
+
return loaded.default;
|
|
81
|
+
});
|
|
82
|
+
const path = yield* Effect.try(() => bundle.registry.registry.findExecutable('ffmpeg').executablePath()).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.String)));
|
|
83
|
+
const fs = yield* FileSystem.FileSystem;
|
|
84
|
+
const found = yield* fs.exists(path);
|
|
85
|
+
return { found, path };
|
|
86
|
+
}).pipe(Effect.orElseSucceed(() => ({ found: false, path: undefined })));
|