@vitrinka/web 0.2.2 → 0.3.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 +39 -0
- package/README.md +48 -4
- package/build/hud.d.ts +1 -1
- package/build/hud.iife.js +9 -8
- package/build/recorder/RecorderProvider.d.ts +2 -1
- package/build/recorder/RecorderProvider.js +18 -4
- package/build/recorder/capture/net.js +16 -10
- package/build/recorder/capture/redact.d.ts +3 -1
- package/build/recorder/capture/redact.js +2 -1
- package/build/recorder/capture/rrweb.d.ts +7 -1
- package/build/recorder/capture/rrweb.js +21 -6
- package/build/recorder/config.d.ts +6 -0
- package/build/recorder/config.js +1 -0
- package/build/recorder/flight.d.ts +66 -0
- package/build/recorder/flight.js +99 -0
- package/build/recorder/hud/Hud.d.ts +2 -1
- package/build/recorder/hud/Hud.js +113 -11
- package/build/recorder/hud/Menu.d.ts +4 -2
- package/build/recorder/hud/Menu.js +2 -2
- package/build/recorder/hud/RecorderPill.d.ts +2 -1
- package/build/recorder/hud/RecorderPill.js +11 -5
- package/build/recorder/hud/Sheet.d.ts +11 -2
- package/build/recorder/hud/Sheet.js +13 -4
- package/build/recorder/hud/controller.d.ts +29 -0
- package/build/recorder/hud/flow.d.ts +13 -3
- package/build/recorder/hud/flow.js +17 -6
- package/build/recorder/hud/icons.d.ts +1 -0
- package/build/recorder/hud/icons.js +3 -0
- package/build/recorder/hud/styles.d.ts +1 -1
- package/build/recorder/hud/styles.js +1 -0
- package/build/recorder/index.d.ts +5 -0
- package/build/recorder/index.js +9 -1
- package/build/recorder/page-controller.js +4 -0
- package/build/recorder/queue.d.ts +11 -4
- package/build/recorder/queue.js +15 -8
- package/build/recorder/report.d.ts +36 -0
- package/build/recorder/report.js +264 -0
- package/build/recorder/session.d.ts +12 -2
- package/build/recorder/session.js +23 -10
- package/package.json +1 -1
package/build/recorder/queue.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { api, permanentStatus, uploadChunk, VitrinkaApiError } from './api';
|
|
2
|
+
import { pushFlightEvent } from './flight';
|
|
2
3
|
import { notify } from './state';
|
|
3
4
|
import { getRecorderStorage } from './storage';
|
|
4
5
|
const FLUSH_MS = 2000;
|
|
@@ -13,7 +14,9 @@ const MAX_PENDING = 200; // rrweb chunks in memory; oldest evicted loudly
|
|
|
13
14
|
* dropped.
|
|
14
15
|
*/
|
|
15
16
|
const WIRE_BODY_CAP = 4 * 1024 * 1024;
|
|
16
|
-
const MAX_BATCH_BYTES = 3 * 1024 * 1024; // pack margin
|
|
17
|
+
export const MAX_BATCH_BYTES = 3 * 1024 * 1024; // pack margin
|
|
18
|
+
/** The server's per-POST event cap. */
|
|
19
|
+
export const EVENTS_PER_POST = 500;
|
|
17
20
|
const MAX_EVENT_BYTES = WIRE_BODY_CAP - 1024; // solo cap; headroom for the {"events":[…]} envelope
|
|
18
21
|
/**
|
|
19
22
|
* rrweb chunk budgets (extension `splitRRWebEvents`): the server's chunk cap
|
|
@@ -27,7 +30,7 @@ const CHUNK_HARD_BYTES = CHUNK_WIRE_CAP - 64;
|
|
|
27
30
|
const CHUNK_PERSIST_BUDGET = 1024 * 1024;
|
|
28
31
|
const encoder = new TextEncoder();
|
|
29
32
|
/** UTF-8 byte length of a string — the unit the server's body limit counts. */
|
|
30
|
-
function utf8Bytes(s) {
|
|
33
|
+
export function utf8Bytes(s) {
|
|
31
34
|
return encoder.encode(s).length;
|
|
32
35
|
}
|
|
33
36
|
/** How often a live session reconciles against the server (extension D5). */
|
|
@@ -311,14 +314,18 @@ export function isSessionLive(id) {
|
|
|
311
314
|
return rec !== null && rec.sessionId === id && !rec.dead;
|
|
312
315
|
}
|
|
313
316
|
/**
|
|
314
|
-
* Append an event to the durable buffer (drops
|
|
315
|
-
*
|
|
316
|
-
* kind+payload plus the route they observed.
|
|
317
|
-
* when
|
|
317
|
+
* Append an event to the durable buffer (drops while paused or dead).
|
|
318
|
+
* `tabId`/`tabHost`/`ts`/`seq` are filled here; capture layers pass
|
|
319
|
+
* kind+payload plus the route they observed. With no session the event goes
|
|
320
|
+
* to the flight recorder when the idle pill keeps one (memory only — never
|
|
321
|
+
* storage, never the network), else it is dropped. Returns the stamped ts
|
|
322
|
+
* (null when dropped).
|
|
318
323
|
*/
|
|
319
324
|
export function pushEvent(kind, payload, route) {
|
|
320
325
|
const rec = getState();
|
|
321
|
-
if (!rec
|
|
326
|
+
if (!rec)
|
|
327
|
+
return pushFlightEvent(kind, payload, route);
|
|
328
|
+
if (rec.paused || rec.dead)
|
|
322
329
|
return null;
|
|
323
330
|
rec.seq++;
|
|
324
331
|
const ts = new Date().toISOString();
|
|
@@ -527,7 +534,7 @@ async function flushInner(opts) {
|
|
|
527
534
|
// A keepalive POST (pagehide) is capped by the browser at 64 KiB.
|
|
528
535
|
const packCap = opts.keepalive ? 60 * 1024 : MAX_BATCH_BYTES;
|
|
529
536
|
for (const ev of buffer) {
|
|
530
|
-
if (batch.length >=
|
|
537
|
+
if (batch.length >= EVENTS_PER_POST)
|
|
531
538
|
break;
|
|
532
539
|
const b = utf8Bytes(JSON.stringify(ev)) + 1;
|
|
533
540
|
if (b > MAX_EVENT_BYTES) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ViewRect } from './session';
|
|
2
|
+
/** A mounted pill wants the flight recorder; returns the release. */
|
|
3
|
+
export declare function wantFlight(): () => void;
|
|
4
|
+
/**
|
|
5
|
+
* Arm or disarm the flight recorder to match the gate; the provider calls it
|
|
6
|
+
* on every recorder change. Resolves once a pending arm has settled.
|
|
7
|
+
*/
|
|
8
|
+
export declare function syncFlight(): Promise<void>;
|
|
9
|
+
/** Can the pill offer "Report a bug" now — into the live session, or with the idle clip? */
|
|
10
|
+
export declare function canReport(): boolean;
|
|
11
|
+
export interface ReportNote {
|
|
12
|
+
/** The description; its first line titles the report session. */
|
|
13
|
+
text: string;
|
|
14
|
+
/** The region the reporter marked, viewport CSS px; null = the whole viewport. */
|
|
15
|
+
rect: ViewRect | null;
|
|
16
|
+
/** The marked element's selector; '' for a region or no mark. */
|
|
17
|
+
selector: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The report sheet opened (freeze the last minute — the buffer itself keeps
|
|
21
|
+
* rolling) or was dismissed (drop it, and a report whose send failed). A
|
|
22
|
+
* send in flight is never dropped. Idle only.
|
|
23
|
+
*/
|
|
24
|
+
export declare function holdReport(on: boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* File the report. While recording: a task annotation in the live session.
|
|
27
|
+
* Idle: the held clip as a `kind: "report"` session — rejects with the
|
|
28
|
+
* failing step's error, and a second call (Retry) resumes the same job.
|
|
29
|
+
*/
|
|
30
|
+
export declare function sendReport(note: ReportNote): Promise<{
|
|
31
|
+
boardUrl?: string;
|
|
32
|
+
}>;
|
|
33
|
+
/** The provider unmounted: forget the buffer and any held clip; a remount re-arms. */
|
|
34
|
+
export declare function dropFlight(): void;
|
|
35
|
+
/** Test-only. */
|
|
36
|
+
export declare function __resetReportForTests(): void;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { api, fetchPolicy, uploadChunk } from './api';
|
|
2
|
+
import { setRedactionPolicy } from './capture/redact';
|
|
3
|
+
import { checkoutRRWeb } from './capture/rrweb';
|
|
4
|
+
import { recorderConfig, vitrinkaLinked } from './config';
|
|
5
|
+
import { clipHasSnapshot, flightActive, startFlightBuffer, stopFlightBuffer, takeFlightClip } from './flight';
|
|
6
|
+
import { EVENTS_PER_POST, getState, MAX_BATCH_BYTES, splitRRWebEvents, utf8Bytes } from './queue';
|
|
7
|
+
import { noteRecent } from './recents';
|
|
8
|
+
import { addAnnotation, createSession, imagePixels } from './session';
|
|
9
|
+
import { currentRoute, notify } from './state';
|
|
10
|
+
// -- the gate ----------------------------------------------------------------
|
|
11
|
+
let pills = 0;
|
|
12
|
+
let armed = false;
|
|
13
|
+
let generation = 0;
|
|
14
|
+
let arming = Promise.resolve();
|
|
15
|
+
/** A mounted pill wants the flight recorder; returns the release. */
|
|
16
|
+
export function wantFlight() {
|
|
17
|
+
pills++;
|
|
18
|
+
notify();
|
|
19
|
+
let released = false;
|
|
20
|
+
return () => {
|
|
21
|
+
if (released)
|
|
22
|
+
return;
|
|
23
|
+
released = true;
|
|
24
|
+
pills--;
|
|
25
|
+
notify();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function flightWanted() {
|
|
29
|
+
return pills > 0 && getState() === null && vitrinkaLinked() && recorderConfig().flightRecorder !== false;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Arm or disarm the flight recorder to match the gate; the provider calls it
|
|
33
|
+
* on every recorder change. Resolves once a pending arm has settled.
|
|
34
|
+
*/
|
|
35
|
+
export function syncFlight() {
|
|
36
|
+
const want = flightWanted();
|
|
37
|
+
if (want && !armed) {
|
|
38
|
+
armed = true;
|
|
39
|
+
const gen = ++generation;
|
|
40
|
+
setRedactionPolicy(null);
|
|
41
|
+
// fetchPolicy never rejects: null is the engine's safe defaults.
|
|
42
|
+
arming = fetchPolicy().then((policy) => {
|
|
43
|
+
if (!armed || gen !== generation)
|
|
44
|
+
return;
|
|
45
|
+
setRedactionPolicy(policy);
|
|
46
|
+
startFlightBuffer();
|
|
47
|
+
notify();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else if (!want && armed) {
|
|
51
|
+
armed = false;
|
|
52
|
+
generation++;
|
|
53
|
+
stopFlightBuffer();
|
|
54
|
+
// A session that just started owns the rules now; only an idle page resets them.
|
|
55
|
+
if (getState() === null)
|
|
56
|
+
setRedactionPolicy(null);
|
|
57
|
+
}
|
|
58
|
+
return arming;
|
|
59
|
+
}
|
|
60
|
+
/** Can the pill offer "Report a bug" now — into the live session, or with the idle clip? */
|
|
61
|
+
export function canReport() {
|
|
62
|
+
const rec = getState();
|
|
63
|
+
if (rec)
|
|
64
|
+
return !rec.paused && !rec.dead;
|
|
65
|
+
return flightWanted() && flightActive();
|
|
66
|
+
}
|
|
67
|
+
let held = null;
|
|
68
|
+
let job = null;
|
|
69
|
+
let sending = false;
|
|
70
|
+
/**
|
|
71
|
+
* The report sheet opened (freeze the last minute — the buffer itself keeps
|
|
72
|
+
* rolling) or was dismissed (drop it, and a report whose send failed). A
|
|
73
|
+
* send in flight is never dropped. Idle only.
|
|
74
|
+
*/
|
|
75
|
+
export function holdReport(on) {
|
|
76
|
+
if (!sending)
|
|
77
|
+
job = null;
|
|
78
|
+
let clip = on && getState() === null ? takeFlightClip() : null;
|
|
79
|
+
// No window to replay — a window over a cap was dropped and the next 30 s
|
|
80
|
+
// checkout has not come, or the first snapshot never did. The server
|
|
81
|
+
// renders stills only from rrweb, so such a report would reach no board
|
|
82
|
+
// and its annotation no intake. Take a checkout now (rrweb emits it
|
|
83
|
+
// synchronously into the buffer) so the clip carries at least the current
|
|
84
|
+
// screen. Never when a window is held: a checkout rotates the older one out
|
|
85
|
+
// and would shrink a good clip. With rrweb not running the checkout is a
|
|
86
|
+
// no-op and the report still sends, without a DOM recording.
|
|
87
|
+
if (clip && !clipHasSnapshot(clip)) {
|
|
88
|
+
checkoutRRWeb();
|
|
89
|
+
clip = takeFlightClip();
|
|
90
|
+
}
|
|
91
|
+
held = clip;
|
|
92
|
+
}
|
|
93
|
+
const TITLE_LINE_CAP = 100;
|
|
94
|
+
function reportTitle(text) {
|
|
95
|
+
const line = text.split('\n')[0]?.trim() ?? '';
|
|
96
|
+
return `Bug report: ${line.length > TITLE_LINE_CAP ? `${line.slice(0, TITLE_LINE_CAP - 1)}…` : line}`;
|
|
97
|
+
}
|
|
98
|
+
function viewportRect() {
|
|
99
|
+
return { x: 0, y: 0, w: globalThis.innerWidth || 0, h: globalThis.innerHeight || 0 };
|
|
100
|
+
}
|
|
101
|
+
function pathOf(href) {
|
|
102
|
+
try {
|
|
103
|
+
return new URL(href).pathname;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return currentRoute.pathname;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function buildJob(clip, note) {
|
|
110
|
+
const tab = { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost };
|
|
111
|
+
const events = [];
|
|
112
|
+
let seq = 0;
|
|
113
|
+
const first = clip.windows[0];
|
|
114
|
+
const startMs = first?.events[0]?.timestamp;
|
|
115
|
+
if (first && startMs !== undefined) {
|
|
116
|
+
events.push({ seq: ++seq, ts: new Date(startMs).toISOString(), ...tab, kind: 'nav', payload: { url: first.href, route: pathOf(first.href) } });
|
|
117
|
+
}
|
|
118
|
+
for (const e of clip.lanes) {
|
|
119
|
+
events.push({ seq: ++seq, ts: e.ts, tabId: e.tabId, tabHost: e.tabHost, kind: e.kind, ...(e.payload ? { payload: e.payload } : {}) });
|
|
120
|
+
}
|
|
121
|
+
const chunks = [];
|
|
122
|
+
let endMs = startMs ?? 0;
|
|
123
|
+
for (const w of clip.windows) {
|
|
124
|
+
// A window is ≤ 4 MiB (the flight cap), far under the chunk cap: nothing drops.
|
|
125
|
+
let at = 0;
|
|
126
|
+
for (const p of splitRRWebEvents(w.events).parts) {
|
|
127
|
+
at += p.count;
|
|
128
|
+
const lastMs = w.events[at - 1]?.timestamp ?? endMs;
|
|
129
|
+
endMs = Math.max(endMs, lastMs);
|
|
130
|
+
chunks.push({ seq: ++seq, ts: new Date(lastMs).toISOString(), ...tab, count: p.count, body: p.body });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const lastLane = clip.lanes.at(-1);
|
|
134
|
+
if (lastLane)
|
|
135
|
+
endMs = Math.max(endMs, Date.parse(lastLane.ts));
|
|
136
|
+
return {
|
|
137
|
+
title: reportTitle(note.text),
|
|
138
|
+
events,
|
|
139
|
+
chunks,
|
|
140
|
+
note: {
|
|
141
|
+
seq: ++seq,
|
|
142
|
+
ts: new Date().toISOString(),
|
|
143
|
+
...tab,
|
|
144
|
+
kind: 'note',
|
|
145
|
+
payload: {
|
|
146
|
+
text: note.text,
|
|
147
|
+
rect: imagePixels(note.rect ?? viewportRect()),
|
|
148
|
+
selector: note.selector,
|
|
149
|
+
annotate: true,
|
|
150
|
+
task: true,
|
|
151
|
+
route: currentRoute.pathname,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
durationMs: startMs !== undefined ? Math.max(0, endMs - startMs) : 0,
|
|
155
|
+
sessionId: '',
|
|
156
|
+
done: 0,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** POST events in batches under the server's per-POST count and the queue's pack margin. */
|
|
160
|
+
async function postEvents(sessionId, events) {
|
|
161
|
+
let batch = [];
|
|
162
|
+
let bytes = 0;
|
|
163
|
+
const send = async () => {
|
|
164
|
+
if (!batch.length)
|
|
165
|
+
return;
|
|
166
|
+
await api('POST', `/api/v1/sessions/${sessionId}/events`, { events: batch });
|
|
167
|
+
batch = [];
|
|
168
|
+
bytes = 0;
|
|
169
|
+
};
|
|
170
|
+
for (const ev of events) {
|
|
171
|
+
const b = utf8Bytes(JSON.stringify(ev)) + 1;
|
|
172
|
+
if (batch.length >= EVENTS_PER_POST || (batch.length > 0 && bytes + b > MAX_BATCH_BYTES))
|
|
173
|
+
await send();
|
|
174
|
+
batch.push(ev);
|
|
175
|
+
bytes += b;
|
|
176
|
+
}
|
|
177
|
+
await send();
|
|
178
|
+
}
|
|
179
|
+
const steps = [
|
|
180
|
+
async (j) => {
|
|
181
|
+
const ses = await createSession(j.title, { meta: { kind: 'report' } });
|
|
182
|
+
j.sessionId = ses.id;
|
|
183
|
+
if (ses.boardUrl)
|
|
184
|
+
j.boardUrl = ses.boardUrl;
|
|
185
|
+
},
|
|
186
|
+
(j) => postEvents(j.sessionId, j.events),
|
|
187
|
+
async (j) => {
|
|
188
|
+
// The extension's chunk path: upload under the pre-allocated seq, then the row.
|
|
189
|
+
const rows = [];
|
|
190
|
+
for (const c of j.chunks) {
|
|
191
|
+
const up = await uploadChunk(j.sessionId, c.seq, c.body);
|
|
192
|
+
rows.push({ seq: c.seq, ts: c.ts, tabId: c.tabId, tabHost: c.tabHost, kind: 'rrweb', payload: { count: c.count }, blobKey: up.blobKey });
|
|
193
|
+
}
|
|
194
|
+
await postEvents(j.sessionId, rows);
|
|
195
|
+
},
|
|
196
|
+
(j) => postEvents(j.sessionId, [j.note]),
|
|
197
|
+
async (j) => {
|
|
198
|
+
const done = await api('PATCH', `/api/v1/sessions/${j.sessionId}`, { status: 'done' });
|
|
199
|
+
const url = done.board?.url;
|
|
200
|
+
if (url)
|
|
201
|
+
j.boardUrl = url;
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
/**
|
|
205
|
+
* File the report. While recording: a task annotation in the live session.
|
|
206
|
+
* Idle: the held clip as a `kind: "report"` session — rejects with the
|
|
207
|
+
* failing step's error, and a second call (Retry) resumes the same job.
|
|
208
|
+
*/
|
|
209
|
+
export async function sendReport(note) {
|
|
210
|
+
const rec = getState();
|
|
211
|
+
if (rec) {
|
|
212
|
+
if (rec.paused || rec.dead)
|
|
213
|
+
throw new Error('the recording is not capturing — resume it to report');
|
|
214
|
+
addAnnotation(note.text, note.rect ?? viewportRect(), note.selector, { task: true });
|
|
215
|
+
return rec.boardUrl ? { boardUrl: rec.boardUrl } : {};
|
|
216
|
+
}
|
|
217
|
+
if (sending)
|
|
218
|
+
throw new Error('a report is already being sent');
|
|
219
|
+
if (!job) {
|
|
220
|
+
if (!held)
|
|
221
|
+
throw new Error('nothing to report — the last minute was not recorded');
|
|
222
|
+
job = buildJob(held, note);
|
|
223
|
+
held = null;
|
|
224
|
+
}
|
|
225
|
+
const j = job;
|
|
226
|
+
sending = true;
|
|
227
|
+
try {
|
|
228
|
+
for (; j.done < steps.length; j.done++) {
|
|
229
|
+
const step = steps[j.done];
|
|
230
|
+
if (step)
|
|
231
|
+
await step(j);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
sending = false;
|
|
236
|
+
}
|
|
237
|
+
if (job === j)
|
|
238
|
+
job = null;
|
|
239
|
+
noteRecent({
|
|
240
|
+
sessionId: j.sessionId,
|
|
241
|
+
title: j.title,
|
|
242
|
+
startedAt: Date.now(),
|
|
243
|
+
durationMs: j.durationMs,
|
|
244
|
+
status: 'saved',
|
|
245
|
+
...(j.boardUrl ? { boardUrl: j.boardUrl } : {}),
|
|
246
|
+
});
|
|
247
|
+
return j.boardUrl ? { boardUrl: j.boardUrl } : {};
|
|
248
|
+
}
|
|
249
|
+
/** The provider unmounted: forget the buffer and any held clip; a remount re-arms. */
|
|
250
|
+
export function dropFlight() {
|
|
251
|
+
armed = false;
|
|
252
|
+
generation++;
|
|
253
|
+
arming = Promise.resolve();
|
|
254
|
+
held = null;
|
|
255
|
+
if (!sending)
|
|
256
|
+
job = null;
|
|
257
|
+
stopFlightBuffer();
|
|
258
|
+
}
|
|
259
|
+
/** Test-only. */
|
|
260
|
+
export function __resetReportForTests() {
|
|
261
|
+
pills = 0;
|
|
262
|
+
sending = false;
|
|
263
|
+
dropFlight();
|
|
264
|
+
}
|
|
@@ -17,8 +17,8 @@ import { type SessionState } from './queue';
|
|
|
17
17
|
export { currentRoute, notify, subscribe } from './state';
|
|
18
18
|
export type { SessionDone } from '../protocol';
|
|
19
19
|
/** Sent as `meta.recorder`; bumped with the package version. */
|
|
20
|
-
export declare const RECORDER_VERSION = "0.
|
|
21
|
-
export declare const RECORDER_ID = "web/0.
|
|
20
|
+
export declare const RECORDER_VERSION = "0.3.1";
|
|
21
|
+
export declare const RECORDER_ID = "web/0.3.1";
|
|
22
22
|
/** What `POST /api/v1/sessions` answers (the fields this recorder keeps). */
|
|
23
23
|
export interface SessionOut {
|
|
24
24
|
id: string;
|
|
@@ -40,6 +40,16 @@ export interface StartOptions {
|
|
|
40
40
|
/** Tags to attach right after create (non-fatal). */
|
|
41
41
|
tags?: string[];
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* `POST /api/v1/sessions` as every web session makes it — a recording and a
|
|
45
|
+
* bug report alike: the page's `host`, the configured project and lane, and
|
|
46
|
+
* the recorder meta. `devicePixelRatio` is the scale every rect is recorded
|
|
47
|
+
* in (`imagePixels`), so the server shoots its stills at it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createSession(title: string, opts?: {
|
|
50
|
+
environment?: string;
|
|
51
|
+
meta?: Record<string, unknown>;
|
|
52
|
+
}): Promise<SessionOut>;
|
|
43
53
|
export declare function startSession(opts?: StartOptions): Promise<SessionState>;
|
|
44
54
|
export declare function togglePause(): Promise<boolean>;
|
|
45
55
|
/** A plain note — `{text, route}`, the extension's shape. */
|
|
@@ -6,7 +6,7 @@ import { noteRecent, updateRecent } from './recents';
|
|
|
6
6
|
import { currentRoute, notify } from './state';
|
|
7
7
|
export { currentRoute, notify, subscribe } from './state';
|
|
8
8
|
/** Sent as `meta.recorder`; bumped with the package version. */
|
|
9
|
-
export const RECORDER_VERSION = '0.
|
|
9
|
+
export const RECORDER_VERSION = '0.3.1';
|
|
10
10
|
export const RECORDER_ID = `web/${RECORDER_VERSION}`;
|
|
11
11
|
/**
|
|
12
12
|
* Re-apply a RECOVERED session's redaction policy after a reload — and
|
|
@@ -54,27 +54,40 @@ function pageHost() {
|
|
|
54
54
|
return '';
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
/**
|
|
58
|
+
* `POST /api/v1/sessions` as every web session makes it — a recording and a
|
|
59
|
+
* bug report alike: the page's `host`, the configured project and lane, and
|
|
60
|
+
* the recorder meta. `devicePixelRatio` is the scale every rect is recorded
|
|
61
|
+
* in (`imagePixels`), so the server shoots its stills at it.
|
|
62
|
+
*/
|
|
63
|
+
export function createSession(title, opts = {}) {
|
|
58
64
|
const cfg = recorderConfig();
|
|
59
|
-
// The safe defaults apply from the first captured byte; the workspace
|
|
60
|
-
// policy (fetched in parallel — fetchPolicy never rejects) can only ADD
|
|
61
|
-
// rules or, self-host only, fullFidelity.
|
|
62
|
-
setRedactionPolicy(null);
|
|
63
|
-
const policyPromise = fetchPolicy();
|
|
64
65
|
const environment = opts.environment ?? cfg.environment;
|
|
65
|
-
|
|
66
|
+
return api('POST', '/api/v1/sessions', {
|
|
66
67
|
host: pageHost(),
|
|
67
|
-
title
|
|
68
|
+
title,
|
|
68
69
|
...(cfg.project ? { project: cfg.project } : {}),
|
|
69
70
|
...(environment ? { environment } : {}),
|
|
70
71
|
meta: {
|
|
71
72
|
recorder: RECORDER_ID,
|
|
72
73
|
userAgent: globalThis.navigator?.userAgent ?? '',
|
|
73
74
|
platform: 'web',
|
|
75
|
+
devicePixelRatio: globalThis.devicePixelRatio || 1,
|
|
74
76
|
...(cfg.appVersion ? { appVersion: cfg.appVersion } : {}),
|
|
75
|
-
...
|
|
77
|
+
...opts.meta,
|
|
76
78
|
},
|
|
77
79
|
});
|
|
80
|
+
}
|
|
81
|
+
export async function startSession(opts = {}) {
|
|
82
|
+
// The safe defaults apply from the first captured byte; the workspace
|
|
83
|
+
// policy (fetched in parallel — fetchPolicy never rejects) can only ADD
|
|
84
|
+
// rules or, self-host only, fullFidelity.
|
|
85
|
+
setRedactionPolicy(null);
|
|
86
|
+
const policyPromise = fetchPolicy();
|
|
87
|
+
const ses = await createSession(opts.title || '', {
|
|
88
|
+
...(opts.environment ? { environment: opts.environment } : {}),
|
|
89
|
+
...(opts.driver ? { meta: { driver: opts.driver } } : {}),
|
|
90
|
+
});
|
|
78
91
|
void policyPromise.then((policy) => {
|
|
79
92
|
const rec = getState();
|
|
80
93
|
if (rec?.sessionId !== ses.id)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitrinka/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "vitrinka toolkit for React DOM apps — the journey recorder: capture manual-testing sessions (rrweb DOM stream, clicks, navigation, network, console, notes) straight into vitrinka boards.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"repository": {
|