@vitrinka/web 0.5.3 → 0.7.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/CHANGELOG.md +113 -0
- package/README.md +145 -20
- package/build/hud.iife.js +150 -28
- package/build/index.d.ts +1 -0
- package/build/protocol/index.d.ts +10 -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/Hud.js +206 -31
- package/build/recorder/hud/NotesSheet.d.ts +24 -0
- package/build/recorder/hud/NotesSheet.js +147 -0
- package/build/recorder/hud/RecorderPill.d.ts +34 -12
- package/build/recorder/hud/RecorderPill.js +52 -14
- package/build/recorder/hud/Sheet.d.ts +18 -15
- package/build/recorder/hud/Sheet.js +13 -13
- package/build/recorder/hud/controller.d.ts +81 -4
- package/build/recorder/hud/drop.d.ts +26 -0
- package/build/recorder/hud/drop.js +35 -0
- 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/icons.d.ts +6 -0
- package/build/recorder/hud/icons.js +12 -0
- package/build/recorder/hud/notes-rows.d.ts +39 -0
- package/build/recorder/hud/notes-rows.js +49 -0
- package/build/recorder/hud/resize.d.ts +6 -3
- package/build/recorder/hud/resize.js +8 -4
- package/build/recorder/hud/styles.d.ts +2 -30
- package/build/recorder/hud/styles.js +63 -31
- package/build/recorder/page-controller.js +13 -7
- package/build/recorder/queue.d.ts +22 -1
- package/build/recorder/queue.js +84 -5
- package/build/recorder/recents.d.ts +20 -4
- package/build/recorder/recents.js +41 -6
- package/build/recorder/session.d.ts +25 -6
- package/build/recorder/session.js +50 -8
- 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 +109 -0
- package/build/report/widget.js +907 -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
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
import type { RedactionPolicy } from '@vitrinka/redact';
|
|
41
41
|
import type { RecorderEvent } from '../protocol';
|
|
42
42
|
import type { StagedImage } from './attachments';
|
|
43
|
+
import type { HudNote } from './hud/controller';
|
|
43
44
|
export declare const MAX_BATCH_BYTES: number;
|
|
44
45
|
/** The server's per-POST event cap. */
|
|
45
46
|
export declare const EVENTS_PER_POST = 500;
|
|
@@ -106,6 +107,8 @@ export declare const REC_KEY = "rec";
|
|
|
106
107
|
*/
|
|
107
108
|
export declare function getState(): SessionState | null;
|
|
108
109
|
export declare function setState(rec: SessionState | null): void;
|
|
110
|
+
export declare function noteLog(sessionId: string): HudNote[];
|
|
111
|
+
export declare function logNote(sessionId: string, note: HudNote): void;
|
|
109
112
|
/**
|
|
110
113
|
* This tab started (`sessionId`) or finished (null) stopping a session. Only
|
|
111
114
|
* the STORED record changes: this tab's own cache stays live, so the tail
|
|
@@ -135,6 +138,23 @@ export declare function persistNow(): void;
|
|
|
135
138
|
*/
|
|
136
139
|
export declare function pruneBlobJournal(ended?: string): Promise<void>;
|
|
137
140
|
export declare function queuedCount(): number;
|
|
141
|
+
/**
|
|
142
|
+
* What THIS tab delivered and the server acknowledged, by what a tester would
|
|
143
|
+
* call it (the HUD's stats float): clicks are actions, navigations pages,
|
|
144
|
+
* rrweb rows count their DOM frames, notes include annotations.
|
|
145
|
+
*/
|
|
146
|
+
export interface AckedCounts {
|
|
147
|
+
actions: number;
|
|
148
|
+
pages: number;
|
|
149
|
+
frames: number;
|
|
150
|
+
notes: number;
|
|
151
|
+
}
|
|
152
|
+
/** The acknowledged counts; the SAME object until a delivery changes them. */
|
|
153
|
+
export declare function ackedCounts(): AckedCounts;
|
|
154
|
+
/** Whether the server acknowledged the note with this client id. */
|
|
155
|
+
export declare function noteAcked(cid: string): boolean;
|
|
156
|
+
/** Client ids of this tab's notes still on their way: waiting for a seq, or buffered. */
|
|
157
|
+
export declare function pendingNoteCids(): string[];
|
|
138
158
|
/** Fresh-session baseline; called by startSession before capture begins. */
|
|
139
159
|
export declare function resetHealth(baseSeq?: number): void;
|
|
140
160
|
export type RecorderHealthState = 'idle' | 'ok' | 'backlog' | 'offline' | 'dead';
|
|
@@ -176,7 +196,8 @@ export declare function capturesSettled(deadlineMs?: number): Promise<boolean>;
|
|
|
176
196
|
/** Is `id` the session currently in state AND still accepting capture? */
|
|
177
197
|
export declare function isSessionLive(id: string): boolean;
|
|
178
198
|
/**
|
|
179
|
-
* Append an event to the durable buffer (drops while
|
|
199
|
+
* Append an event to the durable buffer (drops while dead, and while paused
|
|
200
|
+
* except a note: the tester wrote it on purpose, so it queues and lands).
|
|
180
201
|
* `tabId`/`tabHost`/`ts`/`seq` are filled here; capture layers pass
|
|
181
202
|
* kind+payload plus the route they observed. With no session the event goes
|
|
182
203
|
* to the flight recorder when the idle pill keeps one (memory only — never
|
package/build/recorder/queue.js
CHANGED
|
@@ -91,11 +91,39 @@ export function getState() {
|
|
|
91
91
|
}
|
|
92
92
|
export function setState(rec) {
|
|
93
93
|
recCache = rec;
|
|
94
|
-
if (rec === null)
|
|
94
|
+
if (rec === null) {
|
|
95
95
|
kv().remove(REC_KEY);
|
|
96
|
+
kv().remove(NOTE_LOG_KEY);
|
|
97
|
+
}
|
|
96
98
|
else
|
|
97
99
|
safeSet(REC_KEY, JSON.stringify(stored(rec)));
|
|
98
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* The live recording's notes as the notes sheet lists them (recorder HUD
|
|
103
|
+
* polish D5): every tab's, in this origin's recorder storage, for as long as
|
|
104
|
+
* the recording lives — a recorder token reads nothing back from the
|
|
105
|
+
* server, and the queue already keeps the same text here until delivery.
|
|
106
|
+
* Gone with the session record (`setState(null)`).
|
|
107
|
+
*/
|
|
108
|
+
const NOTE_LOG_KEY = 'notes';
|
|
109
|
+
const MAX_LOGGED_NOTES = 200;
|
|
110
|
+
export function noteLog(sessionId) {
|
|
111
|
+
const log = readJson(NOTE_LOG_KEY, null);
|
|
112
|
+
return log?.sessionId === sessionId && Array.isArray(log.notes) ? log.notes : [];
|
|
113
|
+
}
|
|
114
|
+
export function logNote(sessionId, note) {
|
|
115
|
+
let notes = [...noteLog(sessionId), note];
|
|
116
|
+
while (notes.length > MAX_LOGGED_NOTES) {
|
|
117
|
+
// Evict the oldest ORIGINAL with its whole edit chain — an edit left
|
|
118
|
+
// without its original would list as a note of its own.
|
|
119
|
+
const root = new Map();
|
|
120
|
+
for (const n of notes)
|
|
121
|
+
root.set(n.cid, (n.replaces && root.get(n.replaces)) || n.cid);
|
|
122
|
+
const oldest = root.get(notes[0].cid);
|
|
123
|
+
notes = notes.filter((n) => root.get(n.cid) !== oldest);
|
|
124
|
+
}
|
|
125
|
+
safeSet(NOTE_LOG_KEY, JSON.stringify({ sessionId, notes }));
|
|
126
|
+
}
|
|
99
127
|
/** The session this tab is stopping, its clock at the Stop, and when its mark was last renewed. */
|
|
100
128
|
let stoppingHere = null;
|
|
101
129
|
let stoppingLease = null;
|
|
@@ -437,12 +465,56 @@ function noteFailure(e) {
|
|
|
437
465
|
failures++;
|
|
438
466
|
lastError = String(e instanceof Error ? e.message : e).slice(0, 200);
|
|
439
467
|
}
|
|
468
|
+
let acked = { actions: 0, pages: 0, frames: 0, notes: 0 };
|
|
469
|
+
/** Client ids (`payload.cid`) of notes the server has acknowledged. */
|
|
470
|
+
const ackedNotes = new Set();
|
|
471
|
+
function countAcked(events) {
|
|
472
|
+
const next = { ...acked };
|
|
473
|
+
for (const ev of events) {
|
|
474
|
+
if (ev.kind === 'click')
|
|
475
|
+
next.actions++;
|
|
476
|
+
else if (ev.kind === 'nav')
|
|
477
|
+
next.pages++;
|
|
478
|
+
else if (ev.kind === 'rrweb')
|
|
479
|
+
next.frames += typeof ev.payload?.count === 'number' ? ev.payload.count : 1;
|
|
480
|
+
else if (ev.kind === 'note') {
|
|
481
|
+
next.notes++;
|
|
482
|
+
if (typeof ev.payload?.cid === 'string')
|
|
483
|
+
ackedNotes.add(ev.payload.cid);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
acked = next;
|
|
487
|
+
}
|
|
488
|
+
/** The acknowledged counts; the SAME object until a delivery changes them. */
|
|
489
|
+
export function ackedCounts() {
|
|
490
|
+
return acked;
|
|
491
|
+
}
|
|
492
|
+
/** Whether the server acknowledged the note with this client id. */
|
|
493
|
+
export function noteAcked(cid) {
|
|
494
|
+
return ackedNotes.has(cid);
|
|
495
|
+
}
|
|
496
|
+
/** Client ids of this tab's notes still on their way: waiting for a seq, or buffered. */
|
|
497
|
+
export function pendingNoteCids() {
|
|
498
|
+
const out = [];
|
|
499
|
+
for (const item of pendingAllocations) {
|
|
500
|
+
const { draft } = item;
|
|
501
|
+
if (draft.kind === 'event' && draft.event.kind === 'note' && typeof draft.event.payload?.cid === 'string')
|
|
502
|
+
out.push(draft.event.payload.cid);
|
|
503
|
+
}
|
|
504
|
+
for (const ev of getBuffer()) {
|
|
505
|
+
if (ev.kind === 'note' && typeof ev.payload?.cid === 'string')
|
|
506
|
+
out.push(ev.payload.cid);
|
|
507
|
+
}
|
|
508
|
+
return out;
|
|
509
|
+
}
|
|
440
510
|
/** Fresh-session baseline; called by startSession before capture begins. */
|
|
441
511
|
export function resetHealth(baseSeq = 0) {
|
|
442
512
|
lastSyncAt = Date.now();
|
|
443
513
|
lastError = '';
|
|
444
514
|
failures = 0;
|
|
445
515
|
serverMaxSeq = baseSeq;
|
|
516
|
+
acked = { actions: 0, pages: 0, frames: 0, notes: 0 };
|
|
517
|
+
ackedNotes.clear();
|
|
446
518
|
}
|
|
447
519
|
export function health() {
|
|
448
520
|
const rec = getState();
|
|
@@ -802,7 +874,8 @@ function allocatePending() {
|
|
|
802
874
|
*/
|
|
803
875
|
function queueCapture(draft, journaled) {
|
|
804
876
|
const accepted = getState();
|
|
805
|
-
|
|
877
|
+
const note = draft.kind === 'event' && draft.event.kind === 'note';
|
|
878
|
+
if (!accepted || accepted.dead || (accepted.paused && !note))
|
|
806
879
|
return false;
|
|
807
880
|
recoverAllocations();
|
|
808
881
|
if (kv().withLock) {
|
|
@@ -884,7 +957,8 @@ export function isSessionLive(id) {
|
|
|
884
957
|
return rec !== null && rec.sessionId === id && !rec.dead;
|
|
885
958
|
}
|
|
886
959
|
/**
|
|
887
|
-
* Append an event to the durable buffer (drops while
|
|
960
|
+
* Append an event to the durable buffer (drops while dead, and while paused
|
|
961
|
+
* except a note: the tester wrote it on purpose, so it queues and lands).
|
|
888
962
|
* `tabId`/`tabHost`/`ts`/`seq` are filled here; capture layers pass
|
|
889
963
|
* kind+payload plus the route they observed. With no session the event goes
|
|
890
964
|
* to the flight recorder when the idle pill keeps one (memory only — never
|
|
@@ -899,7 +973,7 @@ export function pushEvent(kind, payload, route, images = []) {
|
|
|
899
973
|
const rec = getState();
|
|
900
974
|
if (!rec)
|
|
901
975
|
return pushFlightEvent(kind, payload, route);
|
|
902
|
-
if (rec.
|
|
976
|
+
if (rec.dead || (rec.paused && kind !== 'note'))
|
|
903
977
|
return null;
|
|
904
978
|
const ts = new Date().toISOString();
|
|
905
979
|
const { tabId, tabHost } = route;
|
|
@@ -1256,12 +1330,15 @@ async function flushInner(opts) {
|
|
|
1256
1330
|
return true;
|
|
1257
1331
|
noteSync();
|
|
1258
1332
|
serverMaxSeq = Math.max(serverMaxSeq, ...batch.map((event) => event.seq));
|
|
1259
|
-
|
|
1333
|
+
countAcked(batch);
|
|
1260
1334
|
// Remove EXACTLY the sent seqs — events pushed during the in-flight POST survive.
|
|
1261
1335
|
const sent = new Set(batch.map((e) => e.seq));
|
|
1262
1336
|
clearStoredCaptures(rec.sessionId, sent);
|
|
1263
1337
|
const rest = getBuffer().filter((e) => !sent.has(e.seq));
|
|
1264
1338
|
setBuffer(rest);
|
|
1339
|
+
// Announced once the buffer no longer holds them: a snapshot built now
|
|
1340
|
+
// must not still list an acknowledged note as pending (the HUD's flash).
|
|
1341
|
+
notify();
|
|
1265
1342
|
// An acknowledged attachment row: its bytes are the server's now.
|
|
1266
1343
|
for (const seq of sent) {
|
|
1267
1344
|
const key = rowBlobs.get(seq);
|
|
@@ -1344,6 +1421,8 @@ export function __resetForTests() {
|
|
|
1344
1421
|
if (key.startsWith(ALLOCATION_PREFIX))
|
|
1345
1422
|
kv().remove(key);
|
|
1346
1423
|
resetIdle();
|
|
1424
|
+
acked = { actions: 0, pages: 0, frames: 0, notes: 0 };
|
|
1425
|
+
ackedNotes.clear();
|
|
1347
1426
|
}
|
|
1348
1427
|
/** Test-only: the recorded events currently buffered (in order). */
|
|
1349
1428
|
export function __bufferForTests() {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* id, so a recent without a board link is refreshed through that reconcile
|
|
7
7
|
* read (`GET /api/v1/sessions/:id`).
|
|
8
8
|
*/
|
|
9
|
-
import type { HudRecent } from './hud/controller';
|
|
9
|
+
import type { HudProjection, HudRecent } from './hud/controller';
|
|
10
10
|
export declare const RECENTS_KEY = "recents";
|
|
11
11
|
export declare const MAX_RECENTS = 5;
|
|
12
12
|
export declare function readRecents(): readonly HudRecent[];
|
|
@@ -24,8 +24,15 @@ interface SessionRead {
|
|
|
24
24
|
};
|
|
25
25
|
projection?: {
|
|
26
26
|
state?: string;
|
|
27
|
+
step?: string;
|
|
28
|
+
done?: number;
|
|
29
|
+
total?: number;
|
|
30
|
+
error?: string;
|
|
31
|
+
retryable?: boolean;
|
|
27
32
|
};
|
|
28
33
|
}
|
|
34
|
+
/** The session answer's board build as the HUD paints it; undefined for an unknown state. */
|
|
35
|
+
export declare function projectionOf(s: SessionRead): HudProjection | undefined;
|
|
29
36
|
/** A session answer's board link: the server's `boardUrl`, or an older server's `board.url`. */
|
|
30
37
|
export declare function boardUrlOf(s: Pick<SessionRead, 'boardUrl' | 'board'> | null | undefined): string | undefined;
|
|
31
38
|
/** How often, and how long, a saved session is read until its board exists (the extension's D11 numbers). */
|
|
@@ -35,14 +42,23 @@ export declare const BOARD_WAIT_MS: number;
|
|
|
35
42
|
* The server answered a stop (or a report) before the session's board was
|
|
36
43
|
* built — it projects after the stop, stills first, 30–60 s. Read the
|
|
37
44
|
* session until it names its board and put the link on the recent, where
|
|
38
|
-
* the Saved face and the menu pick it up
|
|
39
|
-
* projection
|
|
40
|
-
*
|
|
45
|
+
* the Saved face and the menu pick it up; every read in between puts the
|
|
46
|
+
* build's progress (`projection`) there too, for the Building face. Ends on a
|
|
47
|
+
* failed or empty projection (kept on the recent, so the face can say so), a
|
|
48
|
+
* gone or refused session, or after `forMs`; a transient error keeps
|
|
49
|
+
* waiting. Never rejects.
|
|
41
50
|
*/
|
|
42
51
|
export declare function awaitBoard(sessionId: string, { everyMs, forMs }?: {
|
|
43
52
|
everyMs?: number;
|
|
44
53
|
forMs?: number;
|
|
45
54
|
}): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Build a saved session's board again after a retryable failure, then wait
|
|
57
|
+
* for it as a stop does. A recorder token may not call `…/project`; closing
|
|
58
|
+
* the session again (`PATCH {status: done}`) re-requests the same final pass.
|
|
59
|
+
* Rejects with the server's reason.
|
|
60
|
+
*/
|
|
61
|
+
export declare function retryBuild(sessionId: string): Promise<void>;
|
|
46
62
|
/**
|
|
47
63
|
* Fill the board links the list lacks — `live` (the recording in progress)
|
|
48
64
|
* is skipped, its link arrives with its stop. Never rejects.
|
|
@@ -47,6 +47,22 @@ export function updateRecent(sessionId, patch) {
|
|
|
47
47
|
return;
|
|
48
48
|
write(list.map((r) => (r.sessionId === sessionId ? { ...r, ...patch } : r)));
|
|
49
49
|
}
|
|
50
|
+
const PROJECTION_STATES = ['idle', 'queued', 'running', 'ready', 'empty', 'failed'];
|
|
51
|
+
/** The session answer's board build as the HUD paints it; undefined for an unknown state. */
|
|
52
|
+
export function projectionOf(s) {
|
|
53
|
+
const p = s.projection;
|
|
54
|
+
const state = PROJECTION_STATES.find((st) => st === p?.state);
|
|
55
|
+
if (!p || !state)
|
|
56
|
+
return undefined;
|
|
57
|
+
return {
|
|
58
|
+
state,
|
|
59
|
+
...(p.step ? { step: p.step } : {}),
|
|
60
|
+
...(typeof p.done === 'number' ? { done: p.done } : {}),
|
|
61
|
+
...(typeof p.total === 'number' ? { total: p.total } : {}),
|
|
62
|
+
...(p.error ? { error: p.error } : {}),
|
|
63
|
+
...(p.retryable ? { retryable: true } : {}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
50
66
|
/** A session answer's board link: the server's `boardUrl`, or an older server's `board.url`. */
|
|
51
67
|
export function boardUrlOf(s) {
|
|
52
68
|
return s?.boardUrl || s?.board?.url || undefined;
|
|
@@ -59,9 +75,11 @@ const awaiting = new Set();
|
|
|
59
75
|
* The server answered a stop (or a report) before the session's board was
|
|
60
76
|
* built — it projects after the stop, stills first, 30–60 s. Read the
|
|
61
77
|
* session until it names its board and put the link on the recent, where
|
|
62
|
-
* the Saved face and the menu pick it up
|
|
63
|
-
* projection
|
|
64
|
-
*
|
|
78
|
+
* the Saved face and the menu pick it up; every read in between puts the
|
|
79
|
+
* build's progress (`projection`) there too, for the Building face. Ends on a
|
|
80
|
+
* failed or empty projection (kept on the recent, so the face can say so), a
|
|
81
|
+
* gone or refused session, or after `forMs`; a transient error keeps
|
|
82
|
+
* waiting. Never rejects.
|
|
65
83
|
*/
|
|
66
84
|
export async function awaitBoard(sessionId, { everyMs = BOARD_POLL_MS, forMs = BOARD_WAIT_MS } = {}) {
|
|
67
85
|
if (awaiting.has(sessionId))
|
|
@@ -74,11 +92,14 @@ export async function awaitBoard(sessionId, { everyMs = BOARD_POLL_MS, forMs = B
|
|
|
74
92
|
try {
|
|
75
93
|
const s = await api('GET', `/api/v1/sessions/${sessionId}`);
|
|
76
94
|
const boardUrl = boardUrlOf(s);
|
|
95
|
+
const projection = projectionOf(s);
|
|
77
96
|
if (boardUrl)
|
|
78
|
-
return updateRecent(sessionId, { boardUrl });
|
|
97
|
+
return updateRecent(sessionId, { boardUrl, projection: undefined });
|
|
79
98
|
if (s.deletedAt)
|
|
80
|
-
return updateRecent(sessionId, { status: 'deleted' });
|
|
81
|
-
if (
|
|
99
|
+
return updateRecent(sessionId, { status: 'deleted', projection: undefined });
|
|
100
|
+
if (projection && !sameProjection(readRecents().find((r) => r.sessionId === sessionId)?.projection, projection))
|
|
101
|
+
updateRecent(sessionId, { projection });
|
|
102
|
+
if (projection?.state === 'failed' || projection?.state === 'empty')
|
|
82
103
|
return;
|
|
83
104
|
}
|
|
84
105
|
catch (e) {
|
|
@@ -94,6 +115,20 @@ export async function awaitBoard(sessionId, { everyMs = BOARD_POLL_MS, forMs = B
|
|
|
94
115
|
awaiting.delete(sessionId);
|
|
95
116
|
}
|
|
96
117
|
}
|
|
118
|
+
function sameProjection(a, b) {
|
|
119
|
+
return a !== undefined && JSON.stringify(a) === JSON.stringify(b);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Build a saved session's board again after a retryable failure, then wait
|
|
123
|
+
* for it as a stop does. A recorder token may not call `…/project`; closing
|
|
124
|
+
* the session again (`PATCH {status: done}`) re-requests the same final pass.
|
|
125
|
+
* Rejects with the server's reason.
|
|
126
|
+
*/
|
|
127
|
+
export async function retryBuild(sessionId) {
|
|
128
|
+
await api('PATCH', `/api/v1/sessions/${sessionId}`, { status: 'done' });
|
|
129
|
+
updateRecent(sessionId, { projection: { state: 'queued' } });
|
|
130
|
+
void awaitBoard(sessionId);
|
|
131
|
+
}
|
|
97
132
|
/** Ids already asked this document — a refused read is not retried on every menu open. */
|
|
98
133
|
const asked = new Set();
|
|
99
134
|
/**
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { RedactionPolicy } from '@vitrinka/redact';
|
|
15
15
|
import type { SessionDone } from '../protocol';
|
|
16
|
-
import type { HudAttachment } from './hud/controller';
|
|
16
|
+
import type { HudAttachment, HudNote } from './hud/controller';
|
|
17
17
|
import { type SessionState, type StoredChange } from './queue';
|
|
18
18
|
export { currentRoute, notify, subscribe } from './state';
|
|
19
19
|
export { onBeforeStop } from './queue';
|
|
@@ -80,6 +80,17 @@ export declare function createSession(title: string, opts?: {
|
|
|
80
80
|
*/
|
|
81
81
|
export declare function startSession(opts?: StartOptions): Promise<SessionState>;
|
|
82
82
|
export declare function togglePause(): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* A note's identity on the wire (recorder HUD polish D6/D7): `cid` names it,
|
|
85
|
+
* `replaces` supersedes an earlier note's whole content (the board shows the
|
|
86
|
+
* latest, the thread keeps the rest), `refs` points at other notes. All are
|
|
87
|
+
* the HUD's client ids, never seqs — a seq is allocated after the push.
|
|
88
|
+
*/
|
|
89
|
+
export interface NoteLink {
|
|
90
|
+
cid?: string;
|
|
91
|
+
replaces?: string;
|
|
92
|
+
refs?: readonly string[];
|
|
93
|
+
}
|
|
83
94
|
/**
|
|
84
95
|
* A plain note — `{text, route}`, the extension's shape. With attachments
|
|
85
96
|
* (recorder attachments) each image becomes an `attachment` event whose seq
|
|
@@ -87,7 +98,12 @@ export declare function togglePause(): Promise<boolean>;
|
|
|
87
98
|
* lists them: `{text, route, attachments: [seq…]}`; `text` may then be
|
|
88
99
|
* empty. Their bytes upload through `/shot` before their rows ride (queue.ts).
|
|
89
100
|
*/
|
|
90
|
-
export declare function addNote(text: string, attachments?: readonly HudAttachment[]): void;
|
|
101
|
+
export declare function addNote(text: string, attachments?: readonly HudAttachment[], link?: NoteLink): void;
|
|
102
|
+
/**
|
|
103
|
+
* The live recording's notes, every tab's, oldest first (the device log —
|
|
104
|
+
* `noteLog`); null with no live session. Never rejects.
|
|
105
|
+
*/
|
|
106
|
+
export declare function listNotes(): Promise<HudNote[] | null>;
|
|
91
107
|
/** A rect in CSS pixels (viewport coordinates). */
|
|
92
108
|
export interface ViewRect {
|
|
93
109
|
x: number;
|
|
@@ -99,14 +115,17 @@ export interface ViewRect {
|
|
|
99
115
|
export declare function imagePixels(r: ViewRect): ViewRect;
|
|
100
116
|
/**
|
|
101
117
|
* An annotation — the extension's annotate-note `{text, rect, selector,
|
|
102
|
-
* annotate: true}
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
118
|
+
* annotate: true}`; vitrinka projects it into a board annotation. `selector`
|
|
119
|
+
* is '' for a free region. The rect is in device pixels. An empty note is
|
|
120
|
+
* still a valid annotation, matching the extension. `attachments` ride as for
|
|
121
|
+
* `addNote`, `link` as `NoteLink` says. `task` files it as an intake draft
|
|
122
|
+
* too — only a bug report asks for that; the HUD's annotations land on the
|
|
123
|
+
* board alone.
|
|
106
124
|
*/
|
|
107
125
|
export declare function addAnnotation(text: string, rect: ViewRect, selector: string, opts?: {
|
|
108
126
|
task?: boolean;
|
|
109
127
|
attachments?: readonly HudAttachment[];
|
|
128
|
+
link?: NoteLink;
|
|
110
129
|
}): void;
|
|
111
130
|
/**
|
|
112
131
|
* Hooks that run at the top of Stop, before the drain snapshot — the rrweb
|
|
@@ -3,7 +3,7 @@ import { stageAttachments } from './attachments';
|
|
|
3
3
|
import { primeNavigation } from './capture/nav';
|
|
4
4
|
import { redactedRoute, redactUrl, setRedactionPolicy } from './capture/redact';
|
|
5
5
|
import { recorderConfig } from './config';
|
|
6
|
-
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, markStopping, persistNow, pruneBlobJournal, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, runBeforeStopHooks, setState, stoppingElsewhere, } from './queue';
|
|
6
|
+
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, logNote, markStopping, noteLog, persistNow, pruneBlobJournal, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, runBeforeStopHooks, setState, stoppingElsewhere, } from './queue';
|
|
7
7
|
import { claimForStart, settleStart, setLeadStopping } from './lead';
|
|
8
8
|
import { awaitBoard, boardUrlOf, forgetRecents, noteRecent, RECENTS_KEY, updateRecent } from './recents';
|
|
9
9
|
import { currentRoute, notify } from './state';
|
|
@@ -274,6 +274,15 @@ function imagesOf(list) {
|
|
|
274
274
|
}
|
|
275
275
|
return stageAttachments(list);
|
|
276
276
|
}
|
|
277
|
+
function linkOf(link) {
|
|
278
|
+
if (!link)
|
|
279
|
+
return {};
|
|
280
|
+
return {
|
|
281
|
+
...(link.cid ? { cid: link.cid } : {}),
|
|
282
|
+
...(link.replaces ? { replaces: link.replaces } : {}),
|
|
283
|
+
...(link.refs?.length ? { refs: [...link.refs] } : {}),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
277
286
|
/**
|
|
278
287
|
* A plain note — `{text, route}`, the extension's shape. With attachments
|
|
279
288
|
* (recorder attachments) each image becomes an `attachment` event whose seq
|
|
@@ -281,8 +290,30 @@ function imagesOf(list) {
|
|
|
281
290
|
* lists them: `{text, route, attachments: [seq…]}`; `text` may then be
|
|
282
291
|
* empty. Their bytes upload through `/shot` before their rows ride (queue.ts).
|
|
283
292
|
*/
|
|
284
|
-
export function addNote(text, attachments) {
|
|
285
|
-
pushEvent('note', { text, route: redactedRoute() }, route(), imagesOf(attachments));
|
|
293
|
+
export function addNote(text, attachments, link) {
|
|
294
|
+
const at = pushEvent('note', { text, route: redactedRoute(), ...linkOf(link) }, route(), imagesOf(attachments));
|
|
295
|
+
remember(at, { cid: link?.cid ?? '', text, region: false, ...linkFields(link) });
|
|
296
|
+
}
|
|
297
|
+
function linkFields(link) {
|
|
298
|
+
return {
|
|
299
|
+
...(link?.replaces ? { replaces: link.replaces } : {}),
|
|
300
|
+
...(link?.refs?.length ? { refs: [...link.refs] } : {}),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* The live recording's notes, every tab's, oldest first (the device log —
|
|
305
|
+
* `noteLog`); null with no live session. Never rejects.
|
|
306
|
+
*/
|
|
307
|
+
export async function listNotes() {
|
|
308
|
+
const rec = getState();
|
|
309
|
+
return rec ? noteLog(rec.sessionId) : null;
|
|
310
|
+
}
|
|
311
|
+
/** Log a note the queue accepted, under the live session; a note without a `cid` is not listable. */
|
|
312
|
+
function remember(at, note) {
|
|
313
|
+
const rec = getState();
|
|
314
|
+
if (!at || !rec || !note.cid)
|
|
315
|
+
return;
|
|
316
|
+
logNote(rec.sessionId, { ...note, at: Date.parse(at), route: redactedRoute() });
|
|
286
317
|
}
|
|
287
318
|
/** Scale a viewport rect to device pixels — the extension's `imageRect` space. */
|
|
288
319
|
export function imagePixels(r) {
|
|
@@ -296,20 +327,31 @@ export function imagePixels(r) {
|
|
|
296
327
|
}
|
|
297
328
|
/**
|
|
298
329
|
* An annotation — the extension's annotate-note `{text, rect, selector,
|
|
299
|
-
* annotate: true}
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
330
|
+
* annotate: true}`; vitrinka projects it into a board annotation. `selector`
|
|
331
|
+
* is '' for a free region. The rect is in device pixels. An empty note is
|
|
332
|
+
* still a valid annotation, matching the extension. `attachments` ride as for
|
|
333
|
+
* `addNote`, `link` as `NoteLink` says. `task` files it as an intake draft
|
|
334
|
+
* too — only a bug report asks for that; the HUD's annotations land on the
|
|
335
|
+
* board alone.
|
|
303
336
|
*/
|
|
304
337
|
export function addAnnotation(text, rect, selector, opts = {}) {
|
|
305
|
-
pushEvent('note', {
|
|
338
|
+
const at = pushEvent('note', {
|
|
306
339
|
text,
|
|
307
340
|
rect: imagePixels(rect),
|
|
308
341
|
selector,
|
|
309
342
|
annotate: true,
|
|
310
343
|
route: redactedRoute(),
|
|
311
344
|
...(opts.task ? { task: true } : {}),
|
|
345
|
+
...linkOf(opts.link),
|
|
312
346
|
}, route(), imagesOf(opts.attachments));
|
|
347
|
+
remember(at, {
|
|
348
|
+
cid: opts.link?.cid ?? '',
|
|
349
|
+
text,
|
|
350
|
+
region: true,
|
|
351
|
+
w: Math.round(rect.w),
|
|
352
|
+
h: Math.round(rect.h),
|
|
353
|
+
...linkFields(opts.link),
|
|
354
|
+
});
|
|
313
355
|
}
|
|
314
356
|
/**
|
|
315
357
|
* Hooks that run at the top of Stop, before the drain snapshot — the rrweb
|
|
@@ -13,7 +13,9 @@ export declare const currentRoute: {
|
|
|
13
13
|
tabHost: string;
|
|
14
14
|
pathname: string;
|
|
15
15
|
};
|
|
16
|
-
/**
|
|
16
|
+
/** One lane per browser tab: a per-tab id kept in sessionStorage (survives reloads). */
|
|
17
|
+
export declare function browserTabId(): string;
|
|
18
|
+
/** Set the tab identity once per document (provider mount, report face mount). */
|
|
17
19
|
export declare function setTabIdentity(tabId: string, tabHost: string): void;
|
|
18
20
|
/** Update the current pathname; returns true when it actually changed. */
|
|
19
21
|
export declare function setCurrentPath(pathname: string): boolean;
|
|
@@ -31,5 +33,20 @@ export declare function setAnnotating(active: boolean): void;
|
|
|
31
33
|
export declare const leadState: {
|
|
32
34
|
following: 'page' | 'extension' | null;
|
|
33
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Which face drives this document's ONE capture runtime (QA Studio D6): the
|
|
38
|
+
* console and network patches, the flight buffer, the rrweb lane and the
|
|
39
|
+
* redaction rules are page-wide, so only one face may run them. The recorder
|
|
40
|
+
* always wins — a report face that finds any owner captures nothing, and
|
|
41
|
+
* one that holds the runtime yields it (`yieldTo`, synchronously) the moment
|
|
42
|
+
* a recorder mounts. The registry lives on `globalThis` (like the console
|
|
43
|
+
* and network patch marks): the standalone report-widget.mjs and a host's
|
|
44
|
+
* npm recorder carry separate copies of this module, and must agree.
|
|
45
|
+
*/
|
|
46
|
+
export type CaptureFace = 'recorder' | 'report';
|
|
47
|
+
/** Take the runtime for `face`; its release token, or null when a report face finds it taken. */
|
|
48
|
+
export declare function claimCapture(face: CaptureFace, yieldTo?: () => void): string | null;
|
|
49
|
+
/** Give the runtime back — only the claim that `token` names. */
|
|
50
|
+
export declare function releaseCapture(token: string | null | undefined): void;
|
|
34
51
|
export declare function subscribe(fn: () => void): () => void;
|
|
35
52
|
export declare function notify(): void;
|
package/build/recorder/state.js
CHANGED
|
@@ -9,7 +9,23 @@
|
|
|
9
9
|
* tab), `tabHost` the page host; the route itself rides in event payloads.
|
|
10
10
|
*/
|
|
11
11
|
export const currentRoute = { tabId: 'root', tabHost: '/', pathname: '/' };
|
|
12
|
-
|
|
12
|
+
const TAB_KEY = 'vitrinka.tab';
|
|
13
|
+
/** One lane per browser tab: a per-tab id kept in sessionStorage (survives reloads). */
|
|
14
|
+
export function browserTabId() {
|
|
15
|
+
try {
|
|
16
|
+
const ss = globalThis.sessionStorage;
|
|
17
|
+
const have = ss.getItem(TAB_KEY);
|
|
18
|
+
if (have)
|
|
19
|
+
return have;
|
|
20
|
+
const id = Math.random().toString(36).slice(2, 10);
|
|
21
|
+
ss.setItem(TAB_KEY, id);
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return 'root';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Set the tab identity once per document (provider mount, report face mount). */
|
|
13
29
|
export function setTabIdentity(tabId, tabHost) {
|
|
14
30
|
currentRoute.tabId = tabId;
|
|
15
31
|
currentRoute.tabHost = tabHost;
|
|
@@ -37,6 +53,29 @@ export function setAnnotating(active) {
|
|
|
37
53
|
* rrweb stream and the flight recorder check it.
|
|
38
54
|
*/
|
|
39
55
|
export const leadState = { following: null };
|
|
56
|
+
const OWNER_KEY = '__vitrinkaCaptureOwner';
|
|
57
|
+
/** Take the runtime for `face`; its release token, or null when a report face finds it taken. */
|
|
58
|
+
export function claimCapture(face, yieldTo) {
|
|
59
|
+
const g = globalThis;
|
|
60
|
+
const current = g[OWNER_KEY];
|
|
61
|
+
if (current) {
|
|
62
|
+
if (face === 'report')
|
|
63
|
+
return null;
|
|
64
|
+
if (current.face === 'report') {
|
|
65
|
+
g[OWNER_KEY] = null;
|
|
66
|
+
current.yieldTo?.();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const token = `${face}:${Date.now().toString(36)}.${Math.random().toString(36).slice(2, 10)}`;
|
|
70
|
+
g[OWNER_KEY] = { face, token, ...(yieldTo ? { yieldTo } : {}) };
|
|
71
|
+
return token;
|
|
72
|
+
}
|
|
73
|
+
/** Give the runtime back — only the claim that `token` names. */
|
|
74
|
+
export function releaseCapture(token) {
|
|
75
|
+
const g = globalThis;
|
|
76
|
+
if (token && g[OWNER_KEY]?.token === token)
|
|
77
|
+
g[OWNER_KEY] = null;
|
|
78
|
+
}
|
|
40
79
|
// -- change subscription (the HUD re-renders off this) -----------------------
|
|
41
80
|
const listeners = new Set();
|
|
42
81
|
export function subscribe(fn) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The capture store (QA Studio D7, capture profile `storage: browser`): the
|
|
3
|
+
* flight buffer's windows in IndexedDB, so the minutes before a report
|
|
4
|
+
* survive the page loads a multi-page app makes along the way. One database
|
|
5
|
+
* per origin, `vitrinka.capture`:
|
|
6
|
+
*
|
|
7
|
+
* windows {id, tab, scope, kind?, load, startMs, lastMs, count, bytes, href, route} key id
|
|
8
|
+
* chunks {events: <JSON array of rrweb events>, lanes: [...]} key [windowId, part]
|
|
9
|
+
*
|
|
10
|
+
* A `windows` row is an rrweb window (its chunks carry events) or, with
|
|
11
|
+
* `kind: 'lanes'`, a span of console and network entries (its chunks carry
|
|
12
|
+
* lanes) — stored whether or not the profile records a replay.
|
|
13
|
+
*
|
|
14
|
+
* What lands here is already masked: rrweb masks the DOM at emit, the Meta
|
|
15
|
+
* URL is scrubbed and every lane event redacted before the buffer holds it
|
|
16
|
+
* (flight.ts). A window leaves with its window (flight `windowEnd`), every
|
|
17
|
+
* window of a tab after that tab's report is sent (`clear`), and anything
|
|
18
|
+
* past its age on the next load of any tab (`sweep`). Typed drafts never
|
|
19
|
+
* come near it.
|
|
20
|
+
*/
|
|
21
|
+
import type { eventWithTime } from '@rrweb/types';
|
|
22
|
+
import { type FlightLaneEvent, type FlightStore, type StoredWindow } from '../flight';
|
|
23
|
+
export interface CaptureStore extends FlightStore {
|
|
24
|
+
/**
|
|
25
|
+
* The next load's cleanup: drop every window (any tab) whose `windowEnd`
|
|
26
|
+
* is older than `windowMs`, and this tab's windows captured under another
|
|
27
|
+
* `scope` (another project, a laxer masking, wider classes) — fail closed;
|
|
28
|
+
* return this tab's survivors oldest first.
|
|
29
|
+
*/
|
|
30
|
+
sweep(now: number, windowMs: number, tab: string, scope: string): Promise<StoredWindow[]>;
|
|
31
|
+
/** A stored window's events and lane events, in capture order. */
|
|
32
|
+
read(windowId: string): Promise<{
|
|
33
|
+
events: eventWithTime[];
|
|
34
|
+
lanes: FlightLaneEvent[];
|
|
35
|
+
}>;
|
|
36
|
+
close(): void;
|
|
37
|
+
}
|
|
38
|
+
/** Open (creating) the store; rejects where IndexedDB is absent or refuses — the caller stays in memory. */
|
|
39
|
+
export declare function openCaptureStore(idb?: IDBFactory | undefined): Promise<CaptureStore>;
|
|
40
|
+
/**
|
|
41
|
+
* Leave nothing on disk where the profile says memory (a host narrowed it,
|
|
42
|
+
* the project changed it): delete the database if a browser profile left one.
|
|
43
|
+
*/
|
|
44
|
+
export declare function deleteCaptureStore(idb?: IDBFactory | undefined): void;
|