@voila.dev/replay 0.1.0 → 0.2.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/README.md +4 -1
- package/dist/play/index.d.ts +2 -0
- package/dist/play/mirror.d.ts +5 -0
- package/dist/play.js +5 -2
- package/dist/send.js +2 -4
- package/dist/testing/cases.d.ts +5 -0
- package/dist/testing.js +11 -1
- package/package.json +1 -1
- package/src/play/index.ts +3 -0
- package/src/play/mirror.ts +10 -2
- package/src/send/index.ts +4 -3
- package/src/testing/cases.ts +3 -0
- package/src/testing/oracle.ts +20 -4
package/README.md
CHANGED
|
@@ -41,11 +41,14 @@ Recorder: Safari 15.4, Chrome and Edge 92, Firefox 90 and later. Below, `record`
|
|
|
41
41
|
|
|
42
42
|
```
|
|
43
43
|
bun test test/unit # format, sending, joining chunks
|
|
44
|
-
npm run test:browser #
|
|
44
|
+
npm run test:browser # 48 cases, each also played back through a checkpoint, then the budget, a module that throws and the cache return; Chromium, WebKit and Firefox
|
|
45
|
+
node test/browser/visit.mjs # a visit end to end: sending, beacon on the way out, back from the cache, the copy played
|
|
45
46
|
node test/browser/fuzz.mjs # random mutations, the copy judged after each round
|
|
46
47
|
npm run size
|
|
47
48
|
```
|
|
48
49
|
|
|
50
|
+
The browser suites take `--target`, one or several of `chromium`, `webkit`, `firefox` (Playwright), `android` (Chrome on a running emulator, through adb), `ios` (Safari in a booted iOS Simulator), `firefox-esr` (a stock Firefox, `REPLAY_FIREFOX=/path/to/firefox`) and `device` (any browser that opens the URL printed). Where nothing drives the browser, the page runs the suite itself and posts what it finds back to the lab's server.
|
|
51
|
+
|
|
49
52
|
## License
|
|
50
53
|
|
|
51
54
|
MIT
|
package/dist/play/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface PlayerOptions {
|
|
|
9
9
|
readonly skipIdle?: boolean;
|
|
10
10
|
/** Ms of recording between two checkpoints; a seek starts from the nearest one. */
|
|
11
11
|
readonly every?: number;
|
|
12
|
+
/** Where to load a picture or a font from, given its address on the page (see `MirrorHooks`). */
|
|
13
|
+
readonly asset?: (url: string) => string;
|
|
12
14
|
}
|
|
13
15
|
export interface Gap {
|
|
14
16
|
/** Ms from the start of the recording. */
|
package/dist/play/mirror.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface MirrorHooks {
|
|
|
5
5
|
readonly size?: (width: number, height: number) => void;
|
|
6
6
|
readonly focus?: (el: Element | null) => void;
|
|
7
7
|
readonly print?: (ok: boolean, at: number, detail: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Where to load a picture or a font from, given its address on the page: a copy kept when
|
|
10
|
+
* the page was recorded outlives the file the site later renamed or replaced.
|
|
11
|
+
*/
|
|
12
|
+
readonly asset?: (url: string) => string;
|
|
8
13
|
}
|
|
9
14
|
export interface Mirror {
|
|
10
15
|
/** Runs the tape from `from`, up to the tick that would pass `until`. Returns where it stopped. */
|
package/dist/play.js
CHANGED
|
@@ -46,7 +46,8 @@ function mirror(doc, hooks = {}) {
|
|
|
46
46
|
return url;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const
|
|
49
|
+
const kept = (url) => hooks.asset ? hooks.asset(url) : url;
|
|
50
|
+
const css = (text, from = base) => text.replace(CSS_URL, (_m, _q, url) => `url("${kept(absolute(url, from))}")`);
|
|
50
51
|
const local = (el) => localName.call(el);
|
|
51
52
|
function add(n) {
|
|
52
53
|
const top = stack[stack.length - 1];
|
|
@@ -67,10 +68,11 @@ function mirror(doc, hooks = {}) {
|
|
|
67
68
|
if (ADDRESS.test(name)) {
|
|
68
69
|
value = absolute(value);
|
|
69
70
|
if (!SAFE_URL.test(value)) value = "about:blank";
|
|
71
|
+
else if (tag !== "link") value = kept(value);
|
|
70
72
|
} else if (name === "srcset")
|
|
71
73
|
value = value.split(",").map((part) => {
|
|
72
74
|
const [url, ...rest] = part.trim().split(/\s+/);
|
|
73
|
-
return [absolute(url || ""), ...rest].join(" ");
|
|
75
|
+
return [kept(absolute(url || "")), ...rest].join(" ");
|
|
74
76
|
}).join(", ");
|
|
75
77
|
else if (name === "style") value = css(value);
|
|
76
78
|
else if (tag === "a" && name === "target") return;
|
|
@@ -713,6 +715,7 @@ function createPlayer(options) {
|
|
|
713
715
|
let m = make();
|
|
714
716
|
function make() {
|
|
715
717
|
return mirror(doc, {
|
|
718
|
+
asset: options.asset,
|
|
716
719
|
pointer(x, y) {
|
|
717
720
|
cursor.style.display = "block";
|
|
718
721
|
cursor.style.transform = `translate(${x}px,${y}px)`;
|
package/dist/send.js
CHANGED
|
@@ -130,10 +130,7 @@ function connect(o) {
|
|
|
130
130
|
for (let round = 0; round < 3; round++) {
|
|
131
131
|
if (answer?.snap) o.onSnap?.();
|
|
132
132
|
const need = (answer?.need || []).filter((h) => kept.has(h));
|
|
133
|
-
if (
|
|
134
|
-
for (const h of local.keys()) if (!need.includes(h)) kept.delete(h);
|
|
135
|
-
}
|
|
136
|
-
if (!need.length) return;
|
|
133
|
+
if (!need.length) break;
|
|
137
134
|
for (const h of need) wanted.add(h);
|
|
138
135
|
const blobs = {};
|
|
139
136
|
for (const h of need) blobs[h] = kept.get(h);
|
|
@@ -143,6 +140,7 @@ function connect(o) {
|
|
|
143
140
|
kept.delete(h);
|
|
144
141
|
}
|
|
145
142
|
}
|
|
143
|
+
for (const h of local.keys()) kept.delete(h);
|
|
146
144
|
}
|
|
147
145
|
function current() {
|
|
148
146
|
const head = o.head();
|
package/dist/testing/cases.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export interface Case {
|
|
|
13
13
|
readonly select?: ReadonlyArray<readonly [string, string]>;
|
|
14
14
|
/** Strings that must never leave the page, in clear. */
|
|
15
15
|
readonly secrets?: ReadonlyArray<string>;
|
|
16
|
+
/** What the browser must offer for the case to mean anything; skipped otherwise. */
|
|
17
|
+
readonly needs?: {
|
|
18
|
+
readonly what: string;
|
|
19
|
+
readonly test: (w: Window & typeof globalThis) => boolean;
|
|
20
|
+
};
|
|
16
21
|
}
|
|
17
22
|
export declare const CASES: ReadonlyArray<Case>;
|
|
18
23
|
export {};
|
package/dist/testing.js
CHANGED
|
@@ -615,6 +615,7 @@ var CASES = [
|
|
|
615
615
|
{
|
|
616
616
|
name: "adoptedStyleSheets",
|
|
617
617
|
group: "styles",
|
|
618
|
+
needs: { what: "feuilles constructibles (Safari 16.4)", test: (w) => "adoptedStyleSheets" in w.Document.prototype },
|
|
618
619
|
html: D('<p class="a">a</p><div id="h"></div>'),
|
|
619
620
|
run: async (d, w, wait) => {
|
|
620
621
|
const s1 = new w.CSSStyleSheet();
|
|
@@ -688,6 +689,14 @@ function compare(live, copy, o = {}) {
|
|
|
688
689
|
}
|
|
689
690
|
};
|
|
690
691
|
const cssAbs = (t) => t.replace(CSS_URL, (_m, _q, u) => `url("${abs(u)}")`);
|
|
692
|
+
const refused = (name) => {
|
|
693
|
+
try {
|
|
694
|
+
copy.createAttribute(name);
|
|
695
|
+
return false;
|
|
696
|
+
} catch {
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
};
|
|
691
700
|
const rules = (sheet) => {
|
|
692
701
|
try {
|
|
693
702
|
return Array.from(sheet.cssRules, (r) => r.cssText).join("\n");
|
|
@@ -764,6 +773,7 @@ function compare(live, copy, o = {}) {
|
|
|
764
773
|
return [abs(u || ""), ...s].join(" ");
|
|
765
774
|
}).join(", ");
|
|
766
775
|
else if (name === "style" && side === "live") v = cssAbs(v);
|
|
776
|
+
if (side === "live" && refused(name)) continue;
|
|
767
777
|
m.set(name, v);
|
|
768
778
|
}
|
|
769
779
|
return m;
|
|
@@ -781,7 +791,7 @@ function compare(live, copy, o = {}) {
|
|
|
781
791
|
const want = shown(L.value, fieldHidden(L, masked, clear));
|
|
782
792
|
if (want !== R.value) add(p, "textarea.value", want, R.value);
|
|
783
793
|
} else if (tag === "select") {
|
|
784
|
-
const picked = (s) => Array.from(s.options, (x, i) => x.selected ? i : -1).filter((i) => i >= 0).join(",");
|
|
794
|
+
const picked = (s) => s.multiple || s.size > 1 ? Array.from(s.options, (x, i) => x.selected ? i : -1).filter((i) => i >= 0).join(",") : s.selectedIndex < 0 ? "" : String(s.selectedIndex);
|
|
785
795
|
let want = picked(L);
|
|
786
796
|
if (fieldHidden(L, masked, clear)) {
|
|
787
797
|
const options = Array.from(L.options);
|
package/package.json
CHANGED
package/src/play/index.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface PlayerOptions {
|
|
|
16
16
|
readonly skipIdle?: boolean;
|
|
17
17
|
/** Ms of recording between two checkpoints; a seek starts from the nearest one. */
|
|
18
18
|
readonly every?: number;
|
|
19
|
+
/** Where to load a picture or a font from, given its address on the page (see `MirrorHooks`). */
|
|
20
|
+
readonly asset?: (url: string) => string;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export interface Gap {
|
|
@@ -101,6 +103,7 @@ export function createPlayer(options: PlayerOptions): Player {
|
|
|
101
103
|
let m: Mirror = make();
|
|
102
104
|
function make() {
|
|
103
105
|
return mirror(doc, {
|
|
106
|
+
asset: options.asset,
|
|
104
107
|
pointer(x, y) {
|
|
105
108
|
cursor.style.display = "block";
|
|
106
109
|
cursor.style.transform = `translate(${x}px,${y}px)`;
|
package/src/play/mirror.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface MirrorHooks {
|
|
|
12
12
|
readonly size?: (width: number, height: number) => void;
|
|
13
13
|
readonly focus?: (el: Element | null) => void;
|
|
14
14
|
readonly print?: (ok: boolean, at: number, detail: string) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Where to load a picture or a font from, given its address on the page: a copy kept when
|
|
17
|
+
* the page was recorded outlives the file the site later renamed or replaced.
|
|
18
|
+
*/
|
|
19
|
+
readonly asset?: (url: string) => string;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export interface Mirror {
|
|
@@ -101,8 +106,9 @@ export function mirror(doc: Document, hooks: MirrorHooks = {}): Mirror {
|
|
|
101
106
|
return url;
|
|
102
107
|
}
|
|
103
108
|
};
|
|
109
|
+
const kept = (url: string) => (hooks.asset ? hooks.asset(url) : url);
|
|
104
110
|
const css = (text: string, from = base) =>
|
|
105
|
-
text.replace(CSS_URL, (_m, _q, url: string) => `url("${absolute(url, from)}")`);
|
|
111
|
+
text.replace(CSS_URL, (_m, _q, url: string) => `url("${kept(absolute(url, from))}")`);
|
|
106
112
|
const local = (el: Element) => localName.call(el);
|
|
107
113
|
|
|
108
114
|
function add(n: Node) {
|
|
@@ -126,12 +132,14 @@ export function mirror(doc: Document, hooks: MirrorHooks = {}): Mirror {
|
|
|
126
132
|
if (ADDRESS.test(name)) {
|
|
127
133
|
value = absolute(value);
|
|
128
134
|
if (!SAFE_URL.test(value)) value = "about:blank";
|
|
135
|
+
// A stylesheet's own address stays: its rules came on the tape, read from there.
|
|
136
|
+
else if (tag !== "link") value = kept(value);
|
|
129
137
|
} else if (name === "srcset")
|
|
130
138
|
value = value
|
|
131
139
|
.split(",")
|
|
132
140
|
.map((part) => {
|
|
133
141
|
const [url, ...rest] = part.trim().split(/\s+/);
|
|
134
|
-
return [absolute(url || ""), ...rest].join(" ");
|
|
142
|
+
return [kept(absolute(url || "")), ...rest].join(" ");
|
|
135
143
|
})
|
|
136
144
|
.join(", ");
|
|
137
145
|
else if (name === "style") value = css(value);
|
package/src/send/index.ts
CHANGED
|
@@ -219,12 +219,12 @@ export function connect(o: ConnectOptions): Link {
|
|
|
219
219
|
}),
|
|
220
220
|
);
|
|
221
221
|
let answer = await attempt(body);
|
|
222
|
-
// A piece may itself refer to long strings: the server asks again once it read the piece
|
|
222
|
+
// A piece may itself refer to long strings: the server asks again once it read the piece,
|
|
223
|
+
// so what this chunk refers to is kept until the server stops asking.
|
|
223
224
|
for (let round = 0; round < 3; round++) {
|
|
224
225
|
if (answer?.snap) o.onSnap?.();
|
|
225
226
|
const need = (answer?.need || []).filter((h) => kept.has(h));
|
|
226
|
-
if (
|
|
227
|
-
if (!need.length) return;
|
|
227
|
+
if (!need.length) break;
|
|
228
228
|
for (const h of need) wanted.add(h);
|
|
229
229
|
const blobs: Record<string, string> = {};
|
|
230
230
|
for (const h of need) blobs[h] = kept.get(h) as string;
|
|
@@ -234,6 +234,7 @@ export function connect(o: ConnectOptions): Link {
|
|
|
234
234
|
kept.delete(h);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
+
for (const h of local.keys()) kept.delete(h);
|
|
237
238
|
}
|
|
238
239
|
|
|
239
240
|
/** The head of the page view, numbering again from 0 when it changed. */
|
package/src/testing/cases.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface Case {
|
|
|
19
19
|
readonly select?: ReadonlyArray<readonly [string, string]>;
|
|
20
20
|
/** Strings that must never leave the page, in clear. */
|
|
21
21
|
readonly secrets?: ReadonlyArray<string>;
|
|
22
|
+
/** What the browser must offer for the case to mean anything; skipped otherwise. */
|
|
23
|
+
readonly needs?: { readonly what: string; readonly test: (w: Window & typeof globalThis) => boolean };
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
const D = (body: string, head = "") =>
|
|
@@ -642,6 +644,7 @@ export const CASES: ReadonlyArray<Case> = [
|
|
|
642
644
|
{
|
|
643
645
|
name: "adoptedStyleSheets",
|
|
644
646
|
group: "styles",
|
|
647
|
+
needs: { what: "feuilles constructibles (Safari 16.4)", test: (w) => "adoptedStyleSheets" in w.Document.prototype },
|
|
645
648
|
html: D('<p class="a">a</p><div id="h"></div>'),
|
|
646
649
|
run: async (d, w, wait) => {
|
|
647
650
|
const s1 = new w.CSSStyleSheet();
|
package/src/testing/oracle.ts
CHANGED
|
@@ -80,6 +80,16 @@ export function compare(live: Document, copy: Document, o: OracleOptions = {}):
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
const cssAbs = (t: string) => t.replace(CSS_URL, (_m, _q, u: string) => `url("${abs(u)}")`);
|
|
83
|
+
// The player leaves out a name the copy's DOM refuses (`@click`, `:class` where the DOM still
|
|
84
|
+
// holds attribute names to the XML rules): that browser cannot hold it outside the parser.
|
|
85
|
+
const refused = (name: string) => {
|
|
86
|
+
try {
|
|
87
|
+
copy.createAttribute(name);
|
|
88
|
+
return false;
|
|
89
|
+
} catch {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
83
93
|
const rules = (sheet: CSSStyleSheet) => {
|
|
84
94
|
try {
|
|
85
95
|
return Array.from(sheet.cssRules, (r) => r.cssText).join("\n");
|
|
@@ -176,6 +186,7 @@ export function compare(live: Document, copy: Document, o: OracleOptions = {}):
|
|
|
176
186
|
})
|
|
177
187
|
.join(", ");
|
|
178
188
|
else if (name === "style" && side === "live") v = cssAbs(v);
|
|
189
|
+
if (side === "live" && refused(name)) continue;
|
|
179
190
|
m.set(name, v);
|
|
180
191
|
}
|
|
181
192
|
return m;
|
|
@@ -195,13 +206,18 @@ export function compare(live: Document, copy: Document, o: OracleOptions = {}):
|
|
|
195
206
|
const want = shown(L.value, fieldHidden(L, masked, clear));
|
|
196
207
|
if (want !== R.value) add(p, "textarea.value", want, R.value);
|
|
197
208
|
} else if (tag === "select") {
|
|
209
|
+
// A single select shows its `selectedIndex`: Safari 16 may also report as chosen the
|
|
210
|
+
// option given `selected` by script, which it does not show.
|
|
198
211
|
const picked = (s: HTMLSelectElement) =>
|
|
199
|
-
|
|
200
|
-
.
|
|
201
|
-
|
|
212
|
+
s.multiple || s.size > 1
|
|
213
|
+
? Array.from(s.options, (x, i) => (x.selected ? i : -1))
|
|
214
|
+
.filter((i) => i >= 0)
|
|
215
|
+
.join(",")
|
|
216
|
+
: s.selectedIndex < 0
|
|
217
|
+
? ""
|
|
218
|
+
: String(s.selectedIndex);
|
|
202
219
|
let want = picked(L);
|
|
203
220
|
if (fieldHidden(L, masked, clear)) {
|
|
204
|
-
// A hidden choice: the copy shows what the markup alone selects.
|
|
205
221
|
// A hidden choice: the copy shows what the markup alone selects.
|
|
206
222
|
const options = Array.from(L.options as ArrayLike<HTMLOptionElement>);
|
|
207
223
|
if (L.multiple || L.size > 1) want = options.map((x, i) => (hasA(x, "selected") ? i : -1)).filter((i) => i >= 0).join(",");
|