@vitrinka/web 0.6.0 → 0.7.1
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/CHANGELOG.md +79 -0
- package/README.md +127 -4
- package/build/hud.iife.js +7 -7
- package/build/index.d.ts +1 -0
- package/build/recorder/RecorderProvider.js +5 -18
- package/build/recorder/api.d.ts +20 -0
- package/build/recorder/api.js +21 -9
- package/build/recorder/capture/console.d.ts +6 -1
- package/build/recorder/capture/console.js +28 -5
- package/build/recorder/capture/net.d.ts +10 -1
- package/build/recorder/capture/net.js +14 -1
- package/build/recorder/capture/redact.d.ts +1 -0
- package/build/recorder/capture/redact.js +6 -1
- package/build/recorder/capture/rrweb-lane.d.ts +19 -0
- package/build/recorder/capture/rrweb-lane.js +109 -0
- package/build/recorder/capture/rrweb.d.ts +2 -9
- package/build/recorder/capture/rrweb.js +11 -86
- package/build/recorder/config.d.ts +3 -1
- package/build/recorder/config.js +15 -2
- package/build/recorder/flight.d.ts +141 -22
- package/build/recorder/flight.js +312 -27
- package/build/recorder/hud/host-style.d.ts +14 -0
- package/build/recorder/hud/host-style.js +15 -0
- package/build/recorder/hud/host.js +1 -1
- package/build/recorder/hud/styles.d.ts +1 -11
- package/build/recorder/hud/styles.js +1 -12
- package/build/recorder/state.d.ts +18 -1
- package/build/recorder/state.js +40 -1
- package/build/recorder/storage/capture.d.ts +44 -0
- package/build/recorder/storage/capture.js +136 -0
- package/build/recorder/version.d.ts +2 -2
- package/build/recorder/version.js +1 -1
- package/build/report/bundle.d.ts +4 -0
- package/build/report/bundle.js +30 -0
- package/build/report/element.d.ts +86 -0
- package/build/report/element.js +146 -0
- package/build/report/engine.d.ts +144 -0
- package/build/report/engine.js +402 -0
- package/build/report/i18n.d.ts +78 -0
- package/build/report/i18n.js +151 -0
- package/build/report/identity.d.ts +26 -0
- package/build/report/identity.js +36 -0
- package/build/report/index.d.ts +12 -0
- package/build/report/index.js +15 -0
- package/build/report/keybind.d.ts +29 -0
- package/build/report/keybind.js +99 -0
- package/build/report/markers.d.ts +77 -0
- package/build/report/markers.js +162 -0
- package/build/report/profile.d.ts +62 -0
- package/build/report/profile.js +115 -0
- package/build/report/recorder-face.d.ts +2 -0
- package/build/report/recorder-face.js +20 -0
- package/build/report/styles.d.ts +7 -0
- package/build/report/styles.js +226 -0
- package/build/report/widget.d.ts +111 -0
- package/build/report/widget.js +927 -0
- package/build/report/wire.d.ts +68 -0
- package/build/report/wire.js +96 -0
- package/build/report-widget.mjs +229 -0
- package/package.json +11 -4
|
@@ -1,30 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The flight recorder (react-recorder decisions D9/D10
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The flight recorder (react-recorder decisions D9/D10, QA Studio D6/D7):
|
|
3
|
+
* ONE rolling buffer for both faces of the capture client — the recorder
|
|
4
|
+
* pill's idle "last minute" behind "Report a bug" (report.ts) and Report a
|
|
5
|
+
* problem's capture profile (../report). A `FlightProfile` says how far back
|
|
6
|
+
* it reaches, how often rrweb checks out, the caps and where windows live.
|
|
6
7
|
*
|
|
7
|
-
* - rrweb runs with `checkoutEveryNms:
|
|
8
|
-
* one at the head of each full snapshot) opens a window,
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* - rrweb runs with `checkoutEveryNms: profile.checkoutMs`; every Meta event
|
|
9
|
+
* (rrweb emits one at the head of each full snapshot) opens a window, so a
|
|
10
|
+
* clip always starts at a Meta + FullSnapshot. A window is kept while it
|
|
11
|
+
* still covers part of the last `windowMs` (`windowEnd`: it lasts until the
|
|
12
|
+
* next window of its page load opens, or to its last event when the page
|
|
13
|
+
* went away). The recorder face's `RECORDER_FLIGHT` (30 s windows, 30 s
|
|
14
|
+
* checkouts) keeps the current and the previous window: the last 30–60 s.
|
|
11
15
|
* - The click, nav, console and net lanes reach `pushFlightEvent` through
|
|
12
16
|
* the queue's `pushEvent` when no session is live: the same capture code
|
|
13
|
-
* and the same redaction as a recording, held instead of sent.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* and the same redaction as a recording, held instead of sent. A profile's
|
|
18
|
+
* `keepLane` may reduce or refuse each one first (the report face keeps
|
|
19
|
+
* metadata only). They are trimmed to the oldest kept snapshot (to the
|
|
20
|
+
* window when there is none) and to `maxLaneEvents`.
|
|
21
|
+
* - Caps: `maxBytes` of serialized rrweb (each event measured at emit) and
|
|
22
|
+
* `maxEvents`. Over a cap the oldest window goes. When only the window
|
|
23
|
+
* being recorded is left over a cap, a fresh checkout is forced and the old
|
|
24
|
+
* window goes — rrweb's stream is stateful, so incrementals are NEVER
|
|
25
|
+
* spliced out; a fresh snapshot alone over the cap is dropped too and
|
|
26
|
+
* buffering resumes at the next checkout (or at the one a report takes,
|
|
27
|
+
* report.ts `holdReport`). Either way the clip says `truncated` until the
|
|
28
|
+
* lost stretch has left the window.
|
|
29
|
+
* - Memory by default: a reload starts a fresh buffer. A `store` (capture
|
|
30
|
+
* profile `storage: browser` — storage/capture.ts, IndexedDB) also gets
|
|
31
|
+
* every window's new events every 2 s as one chunk, already masked (rrweb
|
|
32
|
+
* masks at emit, the lanes redact at capture), loses each window with the
|
|
33
|
+
* window, and hands this tab's surviving windows of earlier page loads
|
|
34
|
+
* back as `prior` on the next load. `clearFlight` empties memory and the
|
|
35
|
+
* store once a report is sent.
|
|
20
36
|
*
|
|
21
|
-
* DOM-free and React-free: the rrweb lane (capture/rrweb.ts) feeds it.
|
|
37
|
+
* DOM-free and React-free: the rrweb lane (capture/rrweb-lane.ts) feeds it.
|
|
22
38
|
*/
|
|
23
39
|
import type { eventWithTime } from '@rrweb/types';
|
|
24
40
|
export declare const FLIGHT_CHECKOUT_MS = 30000;
|
|
25
41
|
export declare const FLIGHT_MAX_RRWEB_BYTES: number;
|
|
26
42
|
export declare const FLIGHT_MAX_RRWEB_EVENTS = 20000;
|
|
27
43
|
export declare const FLIGHT_MAX_LANE_EVENTS = 500;
|
|
44
|
+
/** How often a store receives the windows' new events. */
|
|
45
|
+
export declare const FLIGHT_PERSIST_MS = 2000;
|
|
28
46
|
/** One lane event as captured — stamped with its ORIGINAL time, no seq yet. */
|
|
29
47
|
export interface FlightLaneEvent {
|
|
30
48
|
ts: string;
|
|
@@ -33,9 +51,23 @@ export interface FlightLaneEvent {
|
|
|
33
51
|
kind: string;
|
|
34
52
|
payload?: Record<string, unknown>;
|
|
35
53
|
}
|
|
54
|
+
/** A window's place in time: all the retention rule reads. */
|
|
55
|
+
export interface FlightSpan {
|
|
56
|
+
/** The page load that recorded it (`FLIGHT_LOAD` for this one). */
|
|
57
|
+
load: string;
|
|
58
|
+
/** Its Meta event's timestamp. */
|
|
59
|
+
startMs: number;
|
|
60
|
+
/** Its newest event's timestamp. */
|
|
61
|
+
lastMs: number;
|
|
62
|
+
}
|
|
36
63
|
/** One checkout window: a Meta + FullSnapshot and what followed it. */
|
|
37
|
-
export interface FlightWindow {
|
|
64
|
+
export interface FlightWindow extends FlightSpan {
|
|
65
|
+
/** Unique; a store's key. */
|
|
66
|
+
id: string;
|
|
67
|
+
/** In capture order; empty for a window an earlier page load left in the store (`stored`). */
|
|
38
68
|
events: eventWithTime[];
|
|
69
|
+
/** How many events it holds (the store's count for a stored window). */
|
|
70
|
+
count: number;
|
|
39
71
|
/** UTF-8 bytes of the events' JSON. */
|
|
40
72
|
bytes: number;
|
|
41
73
|
/** The Meta event's (already redacted) page URL. */
|
|
@@ -45,22 +77,109 @@ export interface FlightWindow {
|
|
|
45
77
|
* so route-only rules apply (never re-derived from the scrubbed `href`).
|
|
46
78
|
*/
|
|
47
79
|
route: string;
|
|
80
|
+
/** Its events live only in the store (an earlier page load): read them there. */
|
|
81
|
+
stored?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** A window as a store keeps it: its span and head, never its events. */
|
|
84
|
+
export interface StoredWindow extends FlightSpan {
|
|
85
|
+
id: string;
|
|
86
|
+
/** The tab (`currentRoute.tabId`) that recorded it; a report sends only its own tab's. */
|
|
87
|
+
tab: string;
|
|
88
|
+
/** The profile's `scope` it was captured under. */
|
|
89
|
+
scope: string;
|
|
90
|
+
/**
|
|
91
|
+
* `lanes`: a span of console and network entries alone (they are stored
|
|
92
|
+
* whether or not a replay runs); absent: an rrweb window.
|
|
93
|
+
*/
|
|
94
|
+
kind?: 'lanes';
|
|
95
|
+
count: number;
|
|
96
|
+
bytes: number;
|
|
97
|
+
href: string;
|
|
98
|
+
route: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Where a `storage: browser` profile keeps its windows besides memory. Every
|
|
102
|
+
* write is queued in order from the synchronous capture path; a failure
|
|
103
|
+
* drops the store for the rest of the page (memory carries on) and says so.
|
|
104
|
+
*/
|
|
105
|
+
export interface FlightStore {
|
|
106
|
+
/** Write (or update) a window's head. */
|
|
107
|
+
putWindow(w: StoredWindow): Promise<void>;
|
|
108
|
+
/** One chunk of a window: its masked rrweb events (a JSON array) and the lane events captured meanwhile. */
|
|
109
|
+
putChunk(windowId: string, part: number, events: string, lanes: readonly FlightLaneEvent[]): Promise<void>;
|
|
110
|
+
/** A chunk and its window's (updated) head in ONE transaction: never a chunk no head can find. */
|
|
111
|
+
putWindowChunk(head: StoredWindow, part: number, events: string, lanes: readonly FlightLaneEvent[]): Promise<void>;
|
|
112
|
+
/** Forget a window and its chunks. */
|
|
113
|
+
dropWindow(windowId: string): Promise<void>;
|
|
114
|
+
/** Forget every window of a tab (a report was sent). */
|
|
115
|
+
clear(tab: string): Promise<void>;
|
|
48
116
|
}
|
|
117
|
+
/** What a buffer keeps, for how long, and where. */
|
|
118
|
+
export interface FlightProfile {
|
|
119
|
+
/** How far back a clip reaches. */
|
|
120
|
+
windowMs: number;
|
|
121
|
+
/** rrweb's `checkoutEveryNms`: how often a fresh full snapshot opens a window. */
|
|
122
|
+
checkoutMs: number;
|
|
123
|
+
maxBytes: number;
|
|
124
|
+
maxEvents: number;
|
|
125
|
+
maxLaneEvents: number;
|
|
126
|
+
/** Reduce a lane event before it is held; null refuses it. Absent = held as captured. */
|
|
127
|
+
keepLane?: (kind: string, payload: Record<string, unknown> | undefined) => Record<string, unknown> | undefined | null;
|
|
128
|
+
/** Keep the windows here too (browser storage); null/absent = memory only. */
|
|
129
|
+
store?: FlightStore | null;
|
|
130
|
+
/**
|
|
131
|
+
* What the windows are captured for (project, masking, classes): written on
|
|
132
|
+
* every stored window, so a sweep under another scope never restores them.
|
|
133
|
+
*/
|
|
134
|
+
scope?: string;
|
|
135
|
+
/** This tab's windows an earlier page load left in the store (its sweep), oldest first. */
|
|
136
|
+
prior?: readonly StoredWindow[];
|
|
137
|
+
/** The console and network entries earlier page loads stored (their lane spans), oldest first. */
|
|
138
|
+
priorLanes?: readonly FlightLaneEvent[];
|
|
139
|
+
}
|
|
140
|
+
/** The recorder face's idle last minute: memory only, 30 s windows. */
|
|
141
|
+
export declare const RECORDER_FLIGHT: FlightProfile;
|
|
49
142
|
/** What a report sends: oldest window first, lanes in capture order. */
|
|
50
143
|
export interface FlightClip {
|
|
51
144
|
windows: FlightWindow[];
|
|
52
145
|
lanes: FlightLaneEvent[];
|
|
146
|
+
/** A cap dropped part of the window: the replay starts later than `windowMs` ago. */
|
|
147
|
+
truncated: boolean;
|
|
53
148
|
}
|
|
54
|
-
/**
|
|
55
|
-
export declare
|
|
56
|
-
/**
|
|
149
|
+
/** This page load's id: windows of an earlier load (`prior`) carry theirs. */
|
|
150
|
+
export declare const FLIGHT_LOAD: string;
|
|
151
|
+
/**
|
|
152
|
+
* Where a window stops covering the page: when the next window of the same
|
|
153
|
+
* page load opens, else at its own last event (the page went away).
|
|
154
|
+
*/
|
|
155
|
+
export declare function windowEnd(w: FlightSpan, next: FlightSpan | undefined): number;
|
|
156
|
+
/** Start a fresh buffer under `next` (default: the recorder face's last minute). */
|
|
157
|
+
export declare function startFlightBuffer(next?: FlightProfile): void;
|
|
158
|
+
/** Stop buffering and forget everything held in memory; a store keeps its windows for the next load. */
|
|
57
159
|
export declare function stopFlightBuffer(): void;
|
|
160
|
+
/** The profile the buffer runs under. */
|
|
161
|
+
export declare function flightProfile(): Readonly<FlightProfile>;
|
|
162
|
+
/** The rrweb lane registers its checkout while it feeds the buffer (null when it stops). */
|
|
163
|
+
export declare function setFlightCheckout(fn: (() => void) | null): void;
|
|
164
|
+
/**
|
|
165
|
+
* Empty the buffer — memory and this tab's stored windows — after a report
|
|
166
|
+
* went out, and open a fresh window at once when rrweb is running.
|
|
167
|
+
*/
|
|
168
|
+
export declare function clearFlight(): void;
|
|
169
|
+
/** Settles once every queued store write has (the report face awaits it before reading). */
|
|
170
|
+
export declare function flightWrites(): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Hand the store every window's events it does not hold yet, as one chunk
|
|
173
|
+
* per window (the lane events ride the newest one's). The 2 s timer calls
|
|
174
|
+
* it; the report face calls it on pagehide. A no-op without a store.
|
|
175
|
+
*/
|
|
176
|
+
export declare function persistFlightNow(): void;
|
|
58
177
|
export declare function flightActive(): boolean;
|
|
59
178
|
/** The capture target id while buffering (the net lane binds in-flight requests to it), else null. */
|
|
60
179
|
export declare function flightTarget(): string | null;
|
|
61
|
-
/** One rrweb event, already redacted. Events before
|
|
180
|
+
/** One rrweb event, already redacted. Events before this page's first snapshot are dropped. */
|
|
62
181
|
export declare function pushFlightRRWeb(ev: eventWithTime): void;
|
|
63
|
-
/** One lane event (the queue's idle path). Returns its ts, null when not buffering. */
|
|
182
|
+
/** One lane event (the queue's idle path). Returns its ts, null when not buffering or refused. */
|
|
64
183
|
export declare function pushFlightEvent(kind: string, payload: Record<string, unknown> | undefined, route: {
|
|
65
184
|
tabId: string;
|
|
66
185
|
tabHost: string;
|
package/build/recorder/flight.js
CHANGED
|
@@ -4,26 +4,286 @@ export const FLIGHT_CHECKOUT_MS = 30_000;
|
|
|
4
4
|
export const FLIGHT_MAX_RRWEB_BYTES = 4 * 1024 * 1024;
|
|
5
5
|
export const FLIGHT_MAX_RRWEB_EVENTS = 20_000;
|
|
6
6
|
export const FLIGHT_MAX_LANE_EVENTS = 500;
|
|
7
|
+
/** How often a store receives the windows' new events. */
|
|
8
|
+
export const FLIGHT_PERSIST_MS = 2000;
|
|
7
9
|
/** rrweb's `EventType.FullSnapshot`; `@rrweb/types` is type-only here, so the value. */
|
|
8
10
|
const RRWEB_FULL_SNAPSHOT = 2;
|
|
11
|
+
/** The recorder face's idle last minute: memory only, 30 s windows. */
|
|
12
|
+
export const RECORDER_FLIGHT = {
|
|
13
|
+
windowMs: FLIGHT_CHECKOUT_MS,
|
|
14
|
+
checkoutMs: FLIGHT_CHECKOUT_MS,
|
|
15
|
+
maxBytes: FLIGHT_MAX_RRWEB_BYTES,
|
|
16
|
+
maxEvents: FLIGHT_MAX_RRWEB_EVENTS,
|
|
17
|
+
maxLaneEvents: FLIGHT_MAX_LANE_EVENTS,
|
|
18
|
+
};
|
|
19
|
+
/** This page load's id: windows of an earlier load (`prior`) carry theirs. */
|
|
20
|
+
export const FLIGHT_LOAD = `${Date.now().toString(36)}.${Math.random().toString(36).slice(2, 8)}`;
|
|
21
|
+
/**
|
|
22
|
+
* Where a window stops covering the page: when the next window of the same
|
|
23
|
+
* page load opens, else at its own last event (the page went away).
|
|
24
|
+
*/
|
|
25
|
+
export function windowEnd(w, next) {
|
|
26
|
+
return next && next.load === w.load ? next.startMs : w.lastMs;
|
|
27
|
+
}
|
|
9
28
|
const encoder = new TextEncoder();
|
|
10
29
|
let active = false;
|
|
11
30
|
/** Bumped on every start, so a capture begun in one buffer never lands in the next. */
|
|
12
31
|
let epoch = 0;
|
|
32
|
+
let profile = RECORDER_FLIGHT;
|
|
13
33
|
let windows = [];
|
|
14
34
|
let lanes = [];
|
|
15
|
-
/**
|
|
16
|
-
|
|
35
|
+
/** Lane events a store has not received yet (the next lane-span chunk). */
|
|
36
|
+
let unstoredLanes = [];
|
|
37
|
+
/** This load's stored lane spans, oldest first; a span covers at most the window. */
|
|
38
|
+
let laneSpans = [];
|
|
39
|
+
let laneSeq = 0;
|
|
40
|
+
/** Lane spans earlier loads stored (restored as `priorLanes`): they expire on this load's clock too. */
|
|
41
|
+
let priorSpans = [];
|
|
42
|
+
/** Per window id: how many of its events the store holds, and its next chunk's part. */
|
|
43
|
+
const persisted = new Map();
|
|
44
|
+
/** Start of the oldest window left after a cap dropped one; null = nothing lost. */
|
|
45
|
+
let truncatedFrom = null;
|
|
46
|
+
/** The rrweb lane's checkout (a fresh full snapshot), while it feeds this buffer. */
|
|
47
|
+
let checkout = null;
|
|
48
|
+
let forcing = false;
|
|
49
|
+
let windowSeq = 0;
|
|
50
|
+
let store = null;
|
|
51
|
+
let persistTimer = null;
|
|
52
|
+
let writes = Promise.resolve();
|
|
53
|
+
/** Start a fresh buffer under `next` (default: the recorder face's last minute). */
|
|
54
|
+
export function startFlightBuffer(next = RECORDER_FLIGHT) {
|
|
55
|
+
stopPersisting();
|
|
17
56
|
active = true;
|
|
18
57
|
epoch++;
|
|
19
|
-
|
|
20
|
-
|
|
58
|
+
profile = next;
|
|
59
|
+
store = next.store ?? null;
|
|
60
|
+
windows = (next.prior ?? []).filter((w) => w.kind !== 'lanes').map((w) => ({
|
|
61
|
+
id: w.id,
|
|
62
|
+
load: w.load,
|
|
63
|
+
startMs: w.startMs,
|
|
64
|
+
lastMs: w.lastMs,
|
|
65
|
+
events: [],
|
|
66
|
+
count: w.count,
|
|
67
|
+
bytes: w.bytes,
|
|
68
|
+
href: w.href,
|
|
69
|
+
route: w.route,
|
|
70
|
+
stored: true,
|
|
71
|
+
}));
|
|
72
|
+
// Already in the store (their spans): held, never written again.
|
|
73
|
+
lanes = (next.priorLanes ?? []).slice(-next.maxLaneEvents);
|
|
74
|
+
unstoredLanes = [];
|
|
75
|
+
laneSpans = [];
|
|
76
|
+
priorSpans = (next.prior ?? []).filter((w) => w.kind === 'lanes').map((w) => ({ id: w.id, lastMs: w.lastMs }));
|
|
77
|
+
persisted.clear();
|
|
78
|
+
truncatedFrom = null;
|
|
79
|
+
enforce(Date.now());
|
|
80
|
+
if (store)
|
|
81
|
+
persistTimer = setInterval(persistFlightNow, FLIGHT_PERSIST_MS);
|
|
21
82
|
}
|
|
22
|
-
/** Stop buffering and forget everything held. */
|
|
83
|
+
/** Stop buffering and forget everything held in memory; a store keeps its windows for the next load. */
|
|
23
84
|
export function stopFlightBuffer() {
|
|
85
|
+
persistFlightNow();
|
|
86
|
+
stopPersisting();
|
|
24
87
|
active = false;
|
|
88
|
+
store = null;
|
|
89
|
+
windows = [];
|
|
90
|
+
lanes = [];
|
|
91
|
+
unstoredLanes = [];
|
|
92
|
+
laneSpans = [];
|
|
93
|
+
priorSpans = [];
|
|
94
|
+
persisted.clear();
|
|
95
|
+
truncatedFrom = null;
|
|
96
|
+
}
|
|
97
|
+
/** The profile the buffer runs under. */
|
|
98
|
+
export function flightProfile() {
|
|
99
|
+
return profile;
|
|
100
|
+
}
|
|
101
|
+
/** The rrweb lane registers its checkout while it feeds the buffer (null when it stops). */
|
|
102
|
+
export function setFlightCheckout(fn) {
|
|
103
|
+
checkout = fn;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Empty the buffer — memory and this tab's stored windows — after a report
|
|
107
|
+
* went out, and open a fresh window at once when rrweb is running.
|
|
108
|
+
*/
|
|
109
|
+
export function clearFlight() {
|
|
110
|
+
if (!active)
|
|
111
|
+
return;
|
|
25
112
|
windows = [];
|
|
26
113
|
lanes = [];
|
|
114
|
+
unstoredLanes = [];
|
|
115
|
+
laneSpans = [];
|
|
116
|
+
priorSpans = [];
|
|
117
|
+
persisted.clear();
|
|
118
|
+
truncatedFrom = null;
|
|
119
|
+
const tab = currentRoute.tabId;
|
|
120
|
+
queueWrite((s) => s.clear(tab));
|
|
121
|
+
checkout?.();
|
|
122
|
+
}
|
|
123
|
+
/** Settles once every queued store write has (the report face awaits it before reading). */
|
|
124
|
+
export function flightWrites() {
|
|
125
|
+
return writes;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Hand the store every window's events it does not hold yet, as one chunk
|
|
129
|
+
* per window (the lane events ride the newest one's). The 2 s timer calls
|
|
130
|
+
* it; the report face calls it on pagehide. A no-op without a store.
|
|
131
|
+
*/
|
|
132
|
+
export function persistFlightNow() {
|
|
133
|
+
if (!active || !store)
|
|
134
|
+
return;
|
|
135
|
+
const now = Date.now();
|
|
136
|
+
enforce(now);
|
|
137
|
+
trimLanes(now);
|
|
138
|
+
for (const w of windows) {
|
|
139
|
+
if (w.stored)
|
|
140
|
+
continue;
|
|
141
|
+
const p = persisted.get(w.id) ?? { events: 0, parts: 0 };
|
|
142
|
+
if (p.events === w.events.length)
|
|
143
|
+
continue;
|
|
144
|
+
const body = JSON.stringify(w.events.slice(p.events));
|
|
145
|
+
const part = p.parts;
|
|
146
|
+
persisted.set(w.id, { events: w.events.length, parts: part + 1 });
|
|
147
|
+
const head = storedWindow(w);
|
|
148
|
+
queueWrite((s) => s.putWindowChunk(head, part, body, []));
|
|
149
|
+
}
|
|
150
|
+
persistLanes(now);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The console and network entries go to lane spans of their own, so an
|
|
154
|
+
* errors-only profile (no replay, no windows) keeps them across loads too.
|
|
155
|
+
* A span covers at most the window; it leaves once its newest entry has.
|
|
156
|
+
*/
|
|
157
|
+
function persistLanes(now) {
|
|
158
|
+
const cutoff = now - profile.windowMs;
|
|
159
|
+
while (laneSpans.length > 0 && laneSpans[0].lastMs <= cutoff) {
|
|
160
|
+
const [gone] = laneSpans.splice(0, 1);
|
|
161
|
+
if (gone)
|
|
162
|
+
queueWrite((s) => s.dropWindow(gone.id));
|
|
163
|
+
}
|
|
164
|
+
for (const gone of priorSpans.filter((s) => s.lastMs <= cutoff))
|
|
165
|
+
queueWrite((s) => s.dropWindow(gone.id));
|
|
166
|
+
priorSpans = priorSpans.filter((s) => s.lastMs > cutoff);
|
|
167
|
+
const batch = unstoredLanes;
|
|
168
|
+
if (!batch.length)
|
|
169
|
+
return;
|
|
170
|
+
unstoredLanes = [];
|
|
171
|
+
let span = laneSpans.at(-1);
|
|
172
|
+
if (!span || span.startMs <= cutoff) {
|
|
173
|
+
span = { id: `${FLIGHT_LOAD}.lanes.${++laneSeq}`, startMs: Date.parse(batch[0].ts), lastMs: 0, parts: 0 };
|
|
174
|
+
laneSpans.push(span);
|
|
175
|
+
}
|
|
176
|
+
span.lastMs = Date.parse(batch.at(-1).ts);
|
|
177
|
+
const part = span.parts++;
|
|
178
|
+
const target = span;
|
|
179
|
+
const head = {
|
|
180
|
+
id: target.id,
|
|
181
|
+
tab: currentRoute.tabId,
|
|
182
|
+
scope: profile.scope ?? '',
|
|
183
|
+
kind: 'lanes',
|
|
184
|
+
load: FLIGHT_LOAD,
|
|
185
|
+
startMs: target.startMs,
|
|
186
|
+
lastMs: target.lastMs,
|
|
187
|
+
count: 0,
|
|
188
|
+
bytes: 0,
|
|
189
|
+
href: '',
|
|
190
|
+
route: '',
|
|
191
|
+
};
|
|
192
|
+
queueWrite((s) => s.putWindowChunk(head, part, '[]', batch));
|
|
193
|
+
}
|
|
194
|
+
function stopPersisting() {
|
|
195
|
+
if (persistTimer)
|
|
196
|
+
clearInterval(persistTimer);
|
|
197
|
+
persistTimer = null;
|
|
198
|
+
}
|
|
199
|
+
function storedWindow(w) {
|
|
200
|
+
return {
|
|
201
|
+
id: w.id,
|
|
202
|
+
tab: currentRoute.tabId,
|
|
203
|
+
scope: profile.scope ?? '',
|
|
204
|
+
load: w.load,
|
|
205
|
+
startMs: w.startMs,
|
|
206
|
+
lastMs: w.lastMs,
|
|
207
|
+
count: w.count,
|
|
208
|
+
bytes: w.bytes,
|
|
209
|
+
href: w.href,
|
|
210
|
+
route: w.route,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/** Queue one store write behind the others; the first failure drops the store, loudly, once. */
|
|
214
|
+
function queueWrite(op) {
|
|
215
|
+
const s = store;
|
|
216
|
+
if (!s)
|
|
217
|
+
return;
|
|
218
|
+
writes = writes
|
|
219
|
+
.then(() => op(s))
|
|
220
|
+
.catch((e) => {
|
|
221
|
+
if (store !== s)
|
|
222
|
+
return;
|
|
223
|
+
store = null;
|
|
224
|
+
stopPersisting();
|
|
225
|
+
console.warn('vitrinka: browser capture storage failed — the capture stays in memory for this page', e);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function dropWindow(i) {
|
|
229
|
+
const [w] = windows.splice(i, 1);
|
|
230
|
+
if (!w)
|
|
231
|
+
return;
|
|
232
|
+
persisted.delete(w.id);
|
|
233
|
+
queueWrite((s) => s.dropWindow(w.id));
|
|
234
|
+
}
|
|
235
|
+
/** Age, then caps: what `profile` allows the buffer to keep at `now`. */
|
|
236
|
+
function enforce(now) {
|
|
237
|
+
while (windows.length > 0) {
|
|
238
|
+
const w = windows[0];
|
|
239
|
+
const next = windows[1];
|
|
240
|
+
// The window being recorded never ages out: it is the screen.
|
|
241
|
+
if (!next && w.load === FLIGHT_LOAD)
|
|
242
|
+
break;
|
|
243
|
+
if (windowEnd(w, next) > now - profile.windowMs)
|
|
244
|
+
break;
|
|
245
|
+
dropWindow(0);
|
|
246
|
+
}
|
|
247
|
+
if (forcing)
|
|
248
|
+
return; // the forced checkout's own events, re-entering
|
|
249
|
+
// rrweb checks its checkout interval only when the page emits: an idle page
|
|
250
|
+
// would keep one ever-older window. Once even its newest event is older
|
|
251
|
+
// than the window, a fresh screen replaces it — nothing of the window is lost.
|
|
252
|
+
const live = windows.at(-1);
|
|
253
|
+
if (live && live.load === FLIGHT_LOAD && checkout && live.lastMs <= now - profile.windowMs) {
|
|
254
|
+
forcing = true;
|
|
255
|
+
try {
|
|
256
|
+
checkout();
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
forcing = false;
|
|
260
|
+
}
|
|
261
|
+
const at = windows.indexOf(live);
|
|
262
|
+
if (at >= 0 && at < windows.length - 1)
|
|
263
|
+
for (let i = at; i >= 0; i--)
|
|
264
|
+
dropWindow(i);
|
|
265
|
+
}
|
|
266
|
+
let forced = false;
|
|
267
|
+
while (windows.length > 0 && overCap()) {
|
|
268
|
+
const live = windows.length === 1 && windows[0].load === FLIGHT_LOAD;
|
|
269
|
+
if (live && !forced && checkout) {
|
|
270
|
+
// Only the window being recorded is left and it is over: shrink by a
|
|
271
|
+
// fresh full snapshot (never by splicing incrementals); the old window
|
|
272
|
+
// goes on the next turn of the loop.
|
|
273
|
+
forced = true;
|
|
274
|
+
forcing = true;
|
|
275
|
+
try {
|
|
276
|
+
checkout();
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
forcing = false;
|
|
280
|
+
}
|
|
281
|
+
if (windows.length > 1)
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
dropWindow(0);
|
|
285
|
+
truncatedFrom = windows[0]?.startMs ?? now;
|
|
286
|
+
}
|
|
27
287
|
}
|
|
28
288
|
export function flightActive() {
|
|
29
289
|
return active;
|
|
@@ -32,13 +292,13 @@ export function flightActive() {
|
|
|
32
292
|
export function flightTarget() {
|
|
33
293
|
return active ? `flight:${epoch}` : null;
|
|
34
294
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Lane events go once they are older than both the oldest kept snapshot and
|
|
297
|
+
* the window (a replay cut short by a cap or a fresh screen keeps the
|
|
298
|
+
* window's errors and requests).
|
|
299
|
+
*/
|
|
300
|
+
function trimLanes(now) {
|
|
301
|
+
const from = Math.min(windows[0]?.startMs ?? Number.POSITIVE_INFINITY, now - profile.windowMs);
|
|
42
302
|
const keep = lanes.findIndex((e) => Date.parse(e.ts) >= from);
|
|
43
303
|
if (keep === -1)
|
|
44
304
|
lanes = [];
|
|
@@ -50,11 +310,11 @@ function overCap() {
|
|
|
50
310
|
let count = 0;
|
|
51
311
|
for (const w of windows) {
|
|
52
312
|
bytes += w.bytes;
|
|
53
|
-
count += w.
|
|
313
|
+
count += w.count;
|
|
54
314
|
}
|
|
55
|
-
return bytes >
|
|
315
|
+
return bytes > profile.maxBytes || count > profile.maxEvents;
|
|
56
316
|
}
|
|
57
|
-
/** One rrweb event, already redacted. Events before
|
|
317
|
+
/** One rrweb event, already redacted. Events before this page's first snapshot are dropped. */
|
|
58
318
|
export function pushFlightRRWeb(ev) {
|
|
59
319
|
if (!active)
|
|
60
320
|
return;
|
|
@@ -62,38 +322,63 @@ export function pushFlightRRWeb(ev) {
|
|
|
62
322
|
if (isMetaEvent(ev)) {
|
|
63
323
|
// rrweb stamps the Meta event synchronously: the document is still on its page.
|
|
64
324
|
const path = globalThis.location?.pathname ?? currentRoute.pathname;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
325
|
+
const opened = {
|
|
326
|
+
id: `${FLIGHT_LOAD}.${++windowSeq}`,
|
|
327
|
+
load: FLIGHT_LOAD,
|
|
328
|
+
startMs: ev.timestamp,
|
|
329
|
+
lastMs: ev.timestamp,
|
|
330
|
+
events: [],
|
|
331
|
+
count: 0,
|
|
332
|
+
bytes: 0,
|
|
333
|
+
href: ev.data.href,
|
|
334
|
+
route: redactUrl(path),
|
|
335
|
+
};
|
|
336
|
+
windows.push(opened);
|
|
337
|
+
const head = storedWindow(opened);
|
|
338
|
+
queueWrite((s) => s.putWindow(head));
|
|
68
339
|
}
|
|
69
340
|
const current = windows.at(-1);
|
|
70
|
-
if (!current)
|
|
341
|
+
if (!current || current.load !== FLIGHT_LOAD)
|
|
71
342
|
return;
|
|
72
343
|
current.events.push(ev);
|
|
344
|
+
current.count++;
|
|
345
|
+
current.lastMs = Math.max(current.lastMs, ev.timestamp);
|
|
73
346
|
current.bytes += encoder.encode(JSON.stringify(ev)).length;
|
|
74
|
-
|
|
75
|
-
windows.shift();
|
|
347
|
+
enforce(ev.timestamp);
|
|
76
348
|
if (windows[0] !== oldest)
|
|
77
|
-
trimLanes();
|
|
349
|
+
trimLanes(ev.timestamp);
|
|
78
350
|
}
|
|
79
|
-
/** One lane event (the queue's idle path). Returns its ts, null when not buffering. */
|
|
351
|
+
/** One lane event (the queue's idle path). Returns its ts, null when not buffering or refused. */
|
|
80
352
|
export function pushFlightEvent(kind, payload, route) {
|
|
81
353
|
if (!active)
|
|
82
354
|
return null;
|
|
355
|
+
const kept = profile.keepLane ? profile.keepLane(kind, payload) : payload;
|
|
356
|
+
if (kept === null)
|
|
357
|
+
return null;
|
|
83
358
|
const ts = new Date().toISOString();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
359
|
+
const ev = { ts, tabId: route.tabId, tabHost: route.tabHost, kind, payload: kept };
|
|
360
|
+
const max = profile.maxLaneEvents;
|
|
361
|
+
lanes.push(ev);
|
|
362
|
+
if (lanes.length > max)
|
|
363
|
+
lanes.splice(0, lanes.length - max);
|
|
364
|
+
if (store) {
|
|
365
|
+
unstoredLanes.push(ev);
|
|
366
|
+
if (unstoredLanes.length > max)
|
|
367
|
+
unstoredLanes.splice(0, unstoredLanes.length - max);
|
|
368
|
+
}
|
|
87
369
|
return ts;
|
|
88
370
|
}
|
|
89
371
|
/** A copy of what the buffer holds now (it keeps rolling); null when not buffering. */
|
|
90
372
|
export function takeFlightClip() {
|
|
91
373
|
if (!active)
|
|
92
374
|
return null;
|
|
93
|
-
|
|
375
|
+
const now = Date.now();
|
|
376
|
+
enforce(now);
|
|
377
|
+
trimLanes(now);
|
|
94
378
|
return {
|
|
95
379
|
windows: windows.map((w) => ({ ...w, events: w.events.slice() })),
|
|
96
380
|
lanes: lanes.slice(),
|
|
381
|
+
truncated: truncatedFrom !== null && truncatedFrom > now - profile.windowMs,
|
|
97
382
|
};
|
|
98
383
|
}
|
|
99
384
|
/** Does the clip hold a window that opens on a Meta + FullSnapshot — a screen to replay? */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline style of the HUD host: a 0×0 fixed box at the viewport origin (the
|
|
3
|
+
* dock and sheets are fixed children of its shadow root). Zero-size keeps
|
|
4
|
+
* rrweb's placeholder for this blocked node empty in every replay — rrweb 2
|
|
5
|
+
* has no "omit entirely" mode, a blocked node always leaves a sized
|
|
6
|
+
* placeholder — and `pointer-events:none` lets the page under the HUD's gaps
|
|
7
|
+
* take every click. Overrides the [popover] UA sheet.
|
|
8
|
+
*
|
|
9
|
+
* Its own leaf module so host.ts (which the React-free report face mounts
|
|
10
|
+
* into) never pulls the HUD's React sheets in through styles.ts.
|
|
11
|
+
*/
|
|
12
|
+
export declare const HOST_STYLE: string;
|
|
13
|
+
/** Inline style of a sheet host portaled into a dialog — the same 0×0 origin box. */
|
|
14
|
+
export declare const SHEET_HOST_STYLE: string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline style of the HUD host: a 0×0 fixed box at the viewport origin (the
|
|
3
|
+
* dock and sheets are fixed children of its shadow root). Zero-size keeps
|
|
4
|
+
* rrweb's placeholder for this blocked node empty in every replay — rrweb 2
|
|
5
|
+
* has no "omit entirely" mode, a blocked node always leaves a sized
|
|
6
|
+
* placeholder — and `pointer-events:none` lets the page under the HUD's gaps
|
|
7
|
+
* take every click. Overrides the [popover] UA sheet.
|
|
8
|
+
*
|
|
9
|
+
* Its own leaf module so host.ts (which the React-free report face mounts
|
|
10
|
+
* into) never pulls the HUD's React sheets in through styles.ts.
|
|
11
|
+
*/
|
|
12
|
+
export const HOST_STYLE = 'all:initial;position:fixed;z-index:2147483647;inset:0 auto auto 0;margin:0;padding:0;border:0;' +
|
|
13
|
+
'background:transparent;overflow:visible;width:0;height:0;pointer-events:none;color-scheme:normal;';
|
|
14
|
+
/** Inline style of a sheet host portaled into a dialog — the same 0×0 origin box. */
|
|
15
|
+
export const SHEET_HOST_STYLE = HOST_STYLE;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* — no preventDefault, so buttons and the textarea still focus.
|
|
13
13
|
*/
|
|
14
14
|
import { RRWEB_BLOCK_ATTR } from '../block';
|
|
15
|
-
import { HOST_STYLE, SHEET_HOST_STYLE } from './
|
|
15
|
+
import { HOST_STYLE, SHEET_HOST_STYLE } from './host-style';
|
|
16
16
|
const SHIELDED = [
|
|
17
17
|
'pointerdown', 'pointerup', 'pointermove', 'pointerover', 'pointerout', 'pointercancel',
|
|
18
18
|
'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'click', 'dblclick', 'auxclick',
|