@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.
Files changed (60) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +127 -4
  3. package/build/hud.iife.js +7 -7
  4. package/build/index.d.ts +1 -0
  5. package/build/recorder/RecorderProvider.js +5 -18
  6. package/build/recorder/api.d.ts +20 -0
  7. package/build/recorder/api.js +21 -9
  8. package/build/recorder/capture/console.d.ts +6 -1
  9. package/build/recorder/capture/console.js +28 -5
  10. package/build/recorder/capture/net.d.ts +10 -1
  11. package/build/recorder/capture/net.js +14 -1
  12. package/build/recorder/capture/redact.d.ts +1 -0
  13. package/build/recorder/capture/redact.js +6 -1
  14. package/build/recorder/capture/rrweb-lane.d.ts +19 -0
  15. package/build/recorder/capture/rrweb-lane.js +109 -0
  16. package/build/recorder/capture/rrweb.d.ts +2 -9
  17. package/build/recorder/capture/rrweb.js +11 -86
  18. package/build/recorder/config.d.ts +3 -1
  19. package/build/recorder/config.js +15 -2
  20. package/build/recorder/flight.d.ts +141 -22
  21. package/build/recorder/flight.js +312 -27
  22. package/build/recorder/hud/host-style.d.ts +14 -0
  23. package/build/recorder/hud/host-style.js +15 -0
  24. package/build/recorder/hud/host.js +1 -1
  25. package/build/recorder/hud/styles.d.ts +1 -11
  26. package/build/recorder/hud/styles.js +1 -12
  27. package/build/recorder/state.d.ts +18 -1
  28. package/build/recorder/state.js +40 -1
  29. package/build/recorder/storage/capture.d.ts +44 -0
  30. package/build/recorder/storage/capture.js +136 -0
  31. package/build/recorder/version.d.ts +2 -2
  32. package/build/recorder/version.js +1 -1
  33. package/build/report/bundle.d.ts +4 -0
  34. package/build/report/bundle.js +30 -0
  35. package/build/report/element.d.ts +86 -0
  36. package/build/report/element.js +146 -0
  37. package/build/report/engine.d.ts +144 -0
  38. package/build/report/engine.js +402 -0
  39. package/build/report/i18n.d.ts +78 -0
  40. package/build/report/i18n.js +151 -0
  41. package/build/report/identity.d.ts +26 -0
  42. package/build/report/identity.js +36 -0
  43. package/build/report/index.d.ts +12 -0
  44. package/build/report/index.js +15 -0
  45. package/build/report/keybind.d.ts +29 -0
  46. package/build/report/keybind.js +99 -0
  47. package/build/report/markers.d.ts +77 -0
  48. package/build/report/markers.js +162 -0
  49. package/build/report/profile.d.ts +62 -0
  50. package/build/report/profile.js +115 -0
  51. package/build/report/recorder-face.d.ts +2 -0
  52. package/build/report/recorder-face.js +20 -0
  53. package/build/report/styles.d.ts +7 -0
  54. package/build/report/styles.js +226 -0
  55. package/build/report/widget.d.ts +111 -0
  56. package/build/report/widget.js +927 -0
  57. package/build/report/wire.d.ts +68 -0
  58. package/build/report/wire.js +96 -0
  59. package/build/report-widget.mjs +229 -0
  60. package/package.json +11 -4
package/build/index.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * subpaths so an app bundles exactly what it imports:
6
6
  *
7
7
  * @vitrinka/web/recorder journey recorder (VitrinkaRecorderRoot, VitrinkaRecorderPill)
8
+ * @vitrinka/web/report Report a problem (mountReport, <vitrinka-report>); one file: report-widget.mjs
8
9
  * @vitrinka/web/next withVitrinkaRecorder (next.config.js build guard, Node-only)
9
10
  * @vitrinka/web/protocol recorder↔server wire types
10
11
  */
@@ -20,30 +20,16 @@ import { startLead } from './lead';
20
20
  import { armReconcile, flush, getState, persistNow, reconcile, scheduleFlush } from './queue';
21
21
  import { dropFlight, syncFlight } from './report';
22
22
  import { addNote, followOtherTabs, onBeforeStop, recoverRedactionPolicy, resyncStoredSession, stopSession, togglePause } from './session';
23
- import { annotateState, leadState, setTabIdentity, subscribe } from './state';
24
- const TAB_KEY = 'vitrinka.tab';
25
- /** One lane per browser tab: a per-tab id kept in sessionStorage (survives reloads). */
26
- function tabId() {
27
- try {
28
- const ss = globalThis.sessionStorage;
29
- const have = ss.getItem(TAB_KEY);
30
- if (have)
31
- return have;
32
- const id = Math.random().toString(36).slice(2, 10);
33
- ss.setItem(TAB_KEY, id);
34
- return id;
35
- }
36
- catch {
37
- return 'root';
38
- }
39
- }
23
+ import { annotateState, browserTabId, claimCapture, leadState, releaseCapture, setTabIdentity, subscribe } from './state';
40
24
  export function RecorderProvider({ config, children, }) {
41
25
  configureRecorder(config);
42
26
  useEffect(() => {
43
27
  configureRecorder(config);
44
28
  }, [config]);
45
29
  useEffect(() => {
46
- setTabIdentity(tabId(), location.host);
30
+ // The recorder owns the page's capture runtime; a report face holding it yields here.
31
+ const captureClaim = claimCapture('recorder');
32
+ setTabIdentity(browserTabId(), location.host);
47
33
  // ONE recorder: mark the document, hear who records, then lead or follow.
48
34
  // A remote command opens this recorder's own doors.
49
35
  const leaveLead = startLead({
@@ -162,6 +148,7 @@ export function RecorderProvider({ config, children, }) {
162
148
  unpatchNetwork();
163
149
  unpatchConsole();
164
150
  leaveLead();
151
+ releaseCapture(captureClaim);
165
152
  };
166
153
  // The lanes install once per mount; config changes are handled above.
167
154
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -35,12 +35,23 @@ export interface RecorderPolicy {
35
35
  * defaults — fail closed, never capture-everything — and no attachments.
36
36
  */
37
37
  export declare function fetchPolicy(): Promise<RecorderPolicy>;
38
+ /** A vitrinka and the bearer to reach it with. */
39
+ export interface ApiTarget {
40
+ url: string;
41
+ key: string;
42
+ }
38
43
  export interface ApiOptions {
39
44
  /**
40
45
  * Survive page unload (the pagehide flush). Browsers cap keepalive bodies at
41
46
  * 64 KiB — callers pass it only for a small tail batch.
42
47
  */
43
48
  keepalive?: boolean;
49
+ /**
50
+ * Call this vitrinka with this bearer instead of the recorder's configured
51
+ * one — the report face binds every call to its own widget's base and key.
52
+ * Its 401 never touches the recorder's device link.
53
+ */
54
+ target?: ApiTarget;
44
55
  }
45
56
  export declare function api<T = Record<string, unknown>>(method: string, path: string, body?: unknown, opts?: ApiOptions): Promise<T>;
46
57
  /**
@@ -60,3 +71,12 @@ export declare function uploadChunk(sessionId: string, seq: number, body: string
60
71
  export declare function uploadImage(sessionId: string, seq: number, blob: Blob): Promise<{
61
72
  blobKey?: string;
62
73
  }>;
74
+ /**
75
+ * POST raw bytes (an rrweb chunk, an image) to a blob leaf under the
76
+ * configured bearer: the session doors above and the report face's
77
+ * `/api/v1/reports/{id}/chunk?seq=N` (with its own `target`). Returns the
78
+ * server's `blobKey`.
79
+ */
80
+ export declare function uploadTo(path: string, contentType: string, body: string | Blob, target?: ApiTarget): Promise<{
81
+ blobKey?: string;
82
+ }>;
@@ -34,9 +34,11 @@ export async function fetchPolicy() {
34
34
  return { policy: null, attachments: false };
35
35
  }
36
36
  }
37
+ function resolveTarget(target) {
38
+ return target ?? { url: recorderConfig().url, key: bearerToken() };
39
+ }
37
40
  export async function api(method, path, body, opts = {}) {
38
- const { url } = recorderConfig();
39
- const key = bearerToken();
41
+ const { url, key } = resolveTarget(opts.target);
40
42
  const res = await fetch(url + path, {
41
43
  method,
42
44
  mode: 'cors',
@@ -50,7 +52,8 @@ export async function api(method, path, body, opts = {}) {
50
52
  });
51
53
  const text = await res.text();
52
54
  if (!res.ok) {
53
- reportStatus(res.status);
55
+ if (!opts.target)
56
+ reportStatus(res.status);
54
57
  throw new VitrinkaApiError(`${method} ${path} → ${res.status}: ${text}`, res.status);
55
58
  }
56
59
  return (text ? JSON.parse(text) : {});
@@ -72,10 +75,18 @@ export function uploadChunk(sessionId, seq, body) {
72
75
  export function uploadImage(sessionId, seq, blob) {
73
76
  return upload(sessionId, 'shot', seq, blob.type, blob);
74
77
  }
75
- async function upload(sessionId, leaf, seq, contentType, body) {
76
- const { url } = recorderConfig();
77
- const key = bearerToken();
78
- const res = await fetch(`${url}/api/v1/sessions/${sessionId}/${leaf}?seq=${seq}`, {
78
+ function upload(sessionId, leaf, seq, contentType, body) {
79
+ return uploadTo(`/api/v1/sessions/${sessionId}/${leaf}?seq=${seq}`, contentType, body);
80
+ }
81
+ /**
82
+ * POST raw bytes (an rrweb chunk, an image) to a blob leaf under the
83
+ * configured bearer: the session doors above and the report face's
84
+ * `/api/v1/reports/{id}/chunk?seq=N` (with its own `target`). Returns the
85
+ * server's `blobKey`.
86
+ */
87
+ export async function uploadTo(path, contentType, body, target) {
88
+ const { url, key } = resolveTarget(target);
89
+ const res = await fetch(url + path, {
79
90
  method: 'POST',
80
91
  mode: 'cors',
81
92
  credentials: 'omit',
@@ -84,8 +95,9 @@ async function upload(sessionId, leaf, seq, contentType, body) {
84
95
  });
85
96
  const text = await res.text();
86
97
  if (!res.ok) {
87
- reportStatus(res.status);
88
- throw new VitrinkaApiError(`POST ${leaf} seq ${seq} → ${res.status}: ${text}`, res.status);
98
+ if (!target)
99
+ reportStatus(res.status);
100
+ throw new VitrinkaApiError(`POST ${path} → ${res.status}: ${text}`, res.status);
89
101
  }
90
102
  try {
91
103
  return JSON.parse(text);
@@ -1,5 +1,10 @@
1
+ /** The console methods beyond `error` a lane may tap. */
2
+ export type ExtraConsoleLevel = 'warn' | 'info' | 'log';
1
3
  /** Restore console.error (while it is still ours) and drop the window listeners. */
2
4
  export declare function unpatchConsole(): void;
3
5
  /** Make this module's wrapper the live one (a no-op when it already is). */
4
6
  export declare function ownConsolePatch(): void;
5
- export declare function patchConsole(): void;
7
+ /** Tap `console.error` and the page's errors — plus `levels` (default none) while this patch lives. */
8
+ export declare function patchConsole(opts?: {
9
+ levels?: readonly ExtraConsoleLevel[];
10
+ }): void;
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Console lane — `console.error` + `window.onerror` + `unhandledrejection`.
2
+ * Console lane — `console.error` + `window.onerror` + `unhandledrejection`,
3
+ * plus `console.warn` / `info` / `log` when the face that patches it asks
4
+ * (`patchConsole({levels})`: the report face's `console` capture class).
3
5
  * The recorder's own logs are prefixed "vitrinka:" and skipped, or a failed
4
6
  * flush would feed itself forever. Shape matches the extension's CDP tap:
5
- * `{level: 'error', text}`.
7
+ * `{level, text}`.
6
8
  */
7
9
  import { pushEvent } from '../queue';
8
10
  import { currentRoute } from '../state';
@@ -26,12 +28,12 @@ function describe(args) {
26
28
  .join(' ')
27
29
  .slice(0, TEXT_CAP);
28
30
  }
29
- function record(text) {
31
+ function record(text, level = 'error') {
30
32
  if (!text || text.startsWith('vitrinka:'))
31
33
  return;
32
34
  // Logged objects routinely carry tokens/headers — same redaction pass as
33
35
  // network bodies.
34
- pushEvent('console', { level: 'error', text: redactText(text) }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
36
+ pushEvent('console', { level, text: redactText(text) }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
35
37
  }
36
38
  const UNPATCH_MARK = '__vitrinkaRecorderConsoleUnpatch';
37
39
  /**
@@ -58,7 +60,8 @@ export function ownConsolePatch() {
58
60
  delete g[PATCH_MARK];
59
61
  patchConsole();
60
62
  }
61
- export function patchConsole() {
63
+ /** Tap `console.error` and the page's errors — plus `levels` (default none) while this patch lives. */
64
+ export function patchConsole(opts = {}) {
62
65
  const g = globalThis;
63
66
  if (g[PATCH_MARK])
64
67
  return;
@@ -75,6 +78,24 @@ export function patchConsole() {
75
78
  }
76
79
  };
77
80
  console.error = patched;
81
+ const extras = (opts.levels ?? []).map((level) => {
82
+ const original = console[level];
83
+ const bound = original.bind(console);
84
+ const wrapper = (...args) => {
85
+ bound(...args);
86
+ try {
87
+ record(describe(args), level);
88
+ }
89
+ catch {
90
+ // capture must never break logging
91
+ }
92
+ };
93
+ console[level] = wrapper;
94
+ return () => {
95
+ if (console[level] === wrapper)
96
+ console[level] = original;
97
+ };
98
+ });
78
99
  const onError = (e) => {
79
100
  try {
80
101
  record(describe([e.error ?? e.message]));
@@ -99,6 +120,8 @@ export function patchConsole() {
99
120
  g[UNPATCH_MARK] = () => {
100
121
  if (console.error === patched)
101
122
  console.error = origError;
123
+ for (const restore of extras)
124
+ restore();
102
125
  if (hasWindow) {
103
126
  removeEventListener('error', onError);
104
127
  removeEventListener('unhandledrejection', onRejection);
@@ -1,5 +1,11 @@
1
1
  /** Test-only: shorten the read deadline so suites don't burn real seconds. */
2
2
  export declare function __setBodyReadDeadlineForTests(ms: number): () => void;
3
+ /**
4
+ * What a request event carries: `'full'` (the recorder: headers and bodies,
5
+ * redacted) or `'meta'` (the report face: method, URL, status, duration —
6
+ * no clone, no body read, nothing else ever leaves the request).
7
+ */
8
+ export type NetworkDetail = 'full' | 'meta';
3
9
  /**
4
10
  * Non-string bodies are recorded as a TYPED PLACEHOLDER, never their bytes:
5
11
  * a FormData routinely carries files and credentials and cannot be scrubbed
@@ -21,4 +27,7 @@ export declare function __readBoundedTextForTests(clone: Response, headers: Head
21
27
  export declare function unpatchNetwork(): void;
22
28
  /** Make this module's wrappers the live ones (a no-op when they already are). */
23
29
  export declare function ownNetworkPatch(): void;
24
- export declare function patchNetwork(): void;
30
+ /** Install the fetch/XHR wrappers; `detail` (default `full`, the recorder) applies while this patch lives. */
31
+ export declare function patchNetwork(opts?: {
32
+ detail?: NetworkDetail;
33
+ }): void;
@@ -38,6 +38,8 @@ export function __setBodyReadDeadlineForTests(ms) {
38
38
  BODY_READ_DEADLINE_MS = prev;
39
39
  };
40
40
  }
41
+ /** The live patch's detail: set by each `patchNetwork` that installs it, so it never outlives its owner. */
42
+ let detail = 'full';
41
43
  /** Is a session (or the idle flight recorder) capturing right now? Gates all body work. */
42
44
  function capturing() {
43
45
  return captureTarget() !== null;
@@ -377,11 +379,13 @@ export function ownNetworkPatch() {
377
379
  delete g[PATCH_MARK];
378
380
  patchNetwork();
379
381
  }
380
- export function patchNetwork() {
382
+ /** Install the fetch/XHR wrappers; `detail` (default `full`, the recorder) applies while this patch lives. */
383
+ export function patchNetwork(opts = {}) {
381
384
  const g = globalThis;
382
385
  if (g[PATCH_MARK])
383
386
  return;
384
387
  g[PATCH_MARK] = OWNER;
388
+ detail = opts.detail ?? 'full';
385
389
  const restores = [];
386
390
  g[UNPATCH_MARK] = () => {
387
391
  for (const r of restores.splice(0))
@@ -403,6 +407,11 @@ export function patchNetwork() {
403
407
  try {
404
408
  const res = await origFetch(input, init);
405
409
  const ms = Date.now() - started;
410
+ if (detail === 'meta') {
411
+ if (stillCapturing(origin))
412
+ recordNet({ method, url, status: res.status, ms, via: 'fetch' });
413
+ return res;
414
+ }
406
415
  // Clone SYNCHRONOUSLY (before the caller can consume the body), then read
407
416
  // and record OFF the caller's critical path: awaiting the body read here
408
417
  // delayed the app's own `await fetch(...)` by however long the recorder
@@ -503,6 +512,10 @@ export function patchNetwork() {
503
512
  // not be attributed to the next one.
504
513
  if (!stillCapturing(origin))
505
514
  return;
515
+ if (detail === 'meta') {
516
+ recordNet({ method: meta.method, url: meta.url, status: this.status, ms: Date.now() - started, via: 'xhr' });
517
+ return;
518
+ }
506
519
  let rawResHeaders;
507
520
  try {
508
521
  rawResHeaders = parseRawHeaders(this.getAllResponseHeaders());
@@ -33,6 +33,7 @@ export declare function redactText(text: string | undefined): string | undefined
33
33
  * generic text scanner.
34
34
  */
35
35
  export declare function redactAndCap(body: string, cap: number, contentType?: string): string | undefined;
36
+ export declare function setCaptureSanitizer(fn: ((url: string) => string) | null | undefined): void;
36
37
  /**
37
38
  * Scrub one URL or route under the active rules: the host's `sanitizeUrl`
38
39
  * first (path credentials), then the engine's query/fragment scrub and
@@ -31,6 +31,11 @@ export function redactAndCap(body, cap, contentType) {
31
31
  }
32
32
  /** The sanitizer whose failure was last reported: once, not on every URL. */
33
33
  let reportedSanitizer = null;
34
+ /** A report face's `sanitizeUrl` while it holds the capture runtime (it never writes the recorder's config). */
35
+ let faceSanitizer = null;
36
+ export function setCaptureSanitizer(fn) {
37
+ faceSanitizer = fn ?? null;
38
+ }
34
39
  /**
35
40
  * The host's `sanitizeUrl` over one captured URL or route. FAIL CLOSED: a
36
41
  * sanitizer that throws or returns a non-string leaves the URL's origin, or
@@ -39,7 +44,7 @@ let reportedSanitizer = null;
39
44
  * about its own URLs, not a workspace redaction rule.
40
45
  */
41
46
  function sanitizeUrl(url) {
42
- const sanitize = recorderConfig().sanitizeUrl;
47
+ const sanitize = faceSanitizer ?? recorderConfig().sanitizeUrl;
43
48
  if (!sanitize)
44
49
  return url;
45
50
  let failure;
@@ -0,0 +1,19 @@
1
+ import type { record as rrwebRecord } from 'rrweb';
2
+ import { RRWEB_BLOCK_ATTR } from '../block';
3
+ export { RRWEB_BLOCK_ATTR };
4
+ /** rrweb's `record` (with its static `takeFullSnapshot` and `mirror`). */
5
+ export type RecordFn = typeof rrwebRecord;
6
+ export interface RRWebLaneOptions {
7
+ /** Under a mask-all-text policy, subtrees matching this keep their text (inputs stay masked). */
8
+ unmaskSelector?: string;
9
+ }
10
+ /** The recorder the lane runs on now (its `mirror` maps live nodes to ids), else null. */
11
+ export declare function runningRecord(): RecordFn | null;
12
+ /** Start recording the DOM into the live session (`'session'`) or the flight buffer; idempotent. */
13
+ export declare function startRecordWith(record: RecordFn, sink: 'session' | 'flight', opts?: RRWebLaneOptions): void;
14
+ /** Ship the tail and stop recording. */
15
+ export declare function stopRRWeb(): void;
16
+ /** Take a fresh full snapshot (resume after pause, policy change, a buffer over its cap). */
17
+ export declare function checkoutRRWeb(): void;
18
+ /** Flush the current batch now (pagehide, stop). */
19
+ export declare function flushRRWeb(): void;
@@ -0,0 +1,109 @@
1
+ import { RRWEB_BLOCK_ATTR } from '../block';
2
+ import { flightProfile, pushFlightRRWeb, setFlightCheckout } from '../flight';
3
+ import { pushRRWebBatch } from '../queue';
4
+ import { currentRoute } from '../state';
5
+ import { maskDirectives, redactRRWebEvent } from './redact';
6
+ export { RRWEB_BLOCK_ATTR };
7
+ const BATCH_MS = 2000;
8
+ /** A fresh full snapshot every 5 min keeps long recordings seekable. */
9
+ const CHECKOUT_MS = 5 * 60 * 1000;
10
+ let stop = null;
11
+ let running = null;
12
+ let buf = [];
13
+ let timer = null;
14
+ function ship() {
15
+ if (!buf.length)
16
+ return;
17
+ const events = buf;
18
+ buf = [];
19
+ // Not capturing (paused): the batch is dropped on purpose — paused means
20
+ // paused, and the next resume starts from a fresh checkout.
21
+ pushRRWebBatch(events, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
22
+ }
23
+ /** The recorder the lane runs on now (its `mirror` maps live nodes to ids), else null. */
24
+ export function runningRecord() {
25
+ return running;
26
+ }
27
+ /** Start recording the DOM into the live session (`'session'`) or the flight buffer; idempotent. */
28
+ export function startRecordWith(record, sink, opts = {}) {
29
+ if (stop)
30
+ return;
31
+ const mask = maskDirectives();
32
+ const unmask = opts.unmaskSelector;
33
+ try {
34
+ const stopFn = record({
35
+ // Scrubbed on the way in: nothing raw ever sits in the buffer.
36
+ emit: sink === 'flight'
37
+ ? (ev) => pushFlightRRWeb(redactRRWebEvent(ev))
38
+ : (ev) => {
39
+ buf.push(redactRRWebEvent(ev));
40
+ },
41
+ checkoutEveryNms: sink === 'flight' ? flightProfile().checkoutMs : CHECKOUT_MS,
42
+ // Never inline: to read a no-CORS cross-origin image rrweb sets
43
+ // crossOrigin='anonymous' on the page's own <img>, the browser refetches
44
+ // it in CORS mode and a host without ACAO shows a broken image — the
45
+ // recorder must never change the page under test. Replay loads by URL.
46
+ inlineImages: false,
47
+ collectFonts: true,
48
+ maskAllInputs: mask.maskAllInputs,
49
+ ...(mask.maskTextSelector ? { maskTextSelector: mask.maskTextSelector } : {}),
50
+ ...(mask.maskTextSelector && unmask
51
+ ? {
52
+ maskTextFn: (text, el) => {
53
+ try {
54
+ if (el?.closest(unmask))
55
+ return text;
56
+ }
57
+ catch {
58
+ // a detached or exotic node: mask it
59
+ }
60
+ return text.replace(/\S/g, '*');
61
+ },
62
+ }
63
+ : {}),
64
+ blockSelector: `[${RRWEB_BLOCK_ATTR}]`,
65
+ });
66
+ stop = stopFn ?? null;
67
+ }
68
+ catch (e) {
69
+ console.warn('vitrinka: rrweb failed to start', e);
70
+ return;
71
+ }
72
+ running = record;
73
+ if (sink === 'flight')
74
+ setFlightCheckout(checkoutRRWeb);
75
+ if (sink === 'session')
76
+ timer = setInterval(ship, BATCH_MS);
77
+ }
78
+ /** Ship the tail and stop recording. */
79
+ export function stopRRWeb() {
80
+ if (timer)
81
+ clearInterval(timer);
82
+ timer = null;
83
+ ship();
84
+ try {
85
+ stop?.();
86
+ }
87
+ catch {
88
+ // already torn down
89
+ }
90
+ stop = null;
91
+ running = null;
92
+ setFlightCheckout(null);
93
+ buf = [];
94
+ }
95
+ /** Take a fresh full snapshot (resume after pause, policy change, a buffer over its cap). */
96
+ export function checkoutRRWeb() {
97
+ if (!stop || !running)
98
+ return;
99
+ try {
100
+ running.takeFullSnapshot?.(true);
101
+ }
102
+ catch {
103
+ // older rrweb — the periodic checkout covers it
104
+ }
105
+ }
106
+ /** Flush the current batch now (pagehide, stop). */
107
+ export function flushRRWeb() {
108
+ ship();
109
+ }
@@ -1,16 +1,9 @@
1
- import { RRWEB_BLOCK_ATTR } from '../block';
2
- export { RRWEB_BLOCK_ATTR };
1
+ export { checkoutRRWeb, flushRRWeb, RRWEB_BLOCK_ATTR, stopRRWeb } from './rrweb-lane';
3
2
  /** Start recording the DOM into the live session; idempotent. */
4
3
  export declare function startRRWeb(): void;
5
4
  /**
6
5
  * Start recording the DOM into the idle pill's flight recorder (flight.ts):
7
- * a checkout every 30 s, each event straight into the in-memory windows.
6
+ * a checkout per the buffer's profile, each event straight into its windows.
8
7
  * Idempotent; `stopRRWeb` stops it.
9
8
  */
10
9
  export declare function startFlightRRWeb(): void;
11
- /** Ship the tail and stop recording. */
12
- export declare function stopRRWeb(): void;
13
- /** Take a fresh full snapshot (resume after pause, policy change). */
14
- export declare function checkoutRRWeb(): void;
15
- /** Flush the current batch now (pagehide, stop). */
16
- export declare function flushRRWeb(): void;
@@ -1,96 +1,21 @@
1
+ /**
2
+ * rrweb lane — the DOM stream is the session's keyframe (no screenshots).
3
+ * The recorder face's binding of the shared lane (rrweb-lane.ts) to the
4
+ * statically imported `rrweb`: the live session's 2 s chunks, or the idle
5
+ * pill's flight recorder (`startFlightRRWeb`) under the buffer's profile.
6
+ */
1
7
  import { record } from 'rrweb';
2
- import { RRWEB_BLOCK_ATTR } from '../block';
3
- import { FLIGHT_CHECKOUT_MS, pushFlightRRWeb } from '../flight';
4
- import { pushRRWebBatch } from '../queue';
5
- import { currentRoute } from '../state';
6
- import { maskDirectives, redactRRWebEvent } from './redact';
7
- export { RRWEB_BLOCK_ATTR };
8
- const BATCH_MS = 2000;
9
- /** A fresh full snapshot every 5 min keeps long recordings seekable. */
10
- const CHECKOUT_MS = 5 * 60 * 1000;
11
- let stop = null;
12
- let buf = [];
13
- let timer = null;
14
- function ship() {
15
- if (!buf.length)
16
- return;
17
- const events = buf;
18
- buf = [];
19
- // Not capturing (paused): the batch is dropped on purpose — paused means
20
- // paused, and the next resume starts from a fresh checkout.
21
- pushRRWebBatch(events, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
22
- }
8
+ import { startRecordWith } from './rrweb-lane';
9
+ export { checkoutRRWeb, flushRRWeb, RRWEB_BLOCK_ATTR, stopRRWeb } from './rrweb-lane';
23
10
  /** Start recording the DOM into the live session; idempotent. */
24
11
  export function startRRWeb() {
25
- startRecord('session');
12
+ startRecordWith(record, 'session');
26
13
  }
27
14
  /**
28
15
  * Start recording the DOM into the idle pill's flight recorder (flight.ts):
29
- * a checkout every 30 s, each event straight into the in-memory windows.
16
+ * a checkout per the buffer's profile, each event straight into its windows.
30
17
  * Idempotent; `stopRRWeb` stops it.
31
18
  */
32
19
  export function startFlightRRWeb() {
33
- startRecord('flight');
34
- }
35
- function startRecord(sink) {
36
- if (stop)
37
- return;
38
- const mask = maskDirectives();
39
- try {
40
- const stopFn = record({
41
- // Scrubbed on the way in: nothing raw ever sits in the buffer.
42
- emit: sink === 'flight'
43
- ? (ev) => pushFlightRRWeb(redactRRWebEvent(ev))
44
- : (ev) => {
45
- buf.push(redactRRWebEvent(ev));
46
- },
47
- checkoutEveryNms: sink === 'flight' ? FLIGHT_CHECKOUT_MS : CHECKOUT_MS,
48
- // Never inline: to read a no-CORS cross-origin image rrweb sets
49
- // crossOrigin='anonymous' on the page's own <img>, the browser refetches
50
- // it in CORS mode and a host without ACAO shows a broken image — the
51
- // recorder must never change the page under test. Replay loads by URL.
52
- inlineImages: false,
53
- collectFonts: true,
54
- maskAllInputs: mask.maskAllInputs,
55
- ...(mask.maskTextSelector ? { maskTextSelector: mask.maskTextSelector } : {}),
56
- blockSelector: `[${RRWEB_BLOCK_ATTR}]`,
57
- });
58
- stop = stopFn ?? null;
59
- }
60
- catch (e) {
61
- console.warn('vitrinka: rrweb failed to start', e);
62
- return;
63
- }
64
- if (sink === 'session')
65
- timer = setInterval(ship, BATCH_MS);
66
- }
67
- /** Ship the tail and stop recording. */
68
- export function stopRRWeb() {
69
- if (timer)
70
- clearInterval(timer);
71
- timer = null;
72
- ship();
73
- try {
74
- stop?.();
75
- }
76
- catch {
77
- // already torn down
78
- }
79
- stop = null;
80
- buf = [];
81
- }
82
- /** Take a fresh full snapshot (resume after pause, policy change). */
83
- export function checkoutRRWeb() {
84
- if (!stop)
85
- return;
86
- try {
87
- record.takeFullSnapshot?.(true);
88
- }
89
- catch {
90
- // older rrweb — the periodic checkout covers it
91
- }
92
- }
93
- /** Flush the current batch now (pagehide, stop). */
94
- export function flushRRWeb() {
95
- ship();
20
+ startRecordWith(record, 'flight');
96
21
  }
@@ -48,7 +48,9 @@ export declare function configureRecorder(next: RecorderConfig): void;
48
48
  export declare function recorderConfig(): Readonly<RecorderConfig>;
49
49
  /** The recorder is enabled by the URL alone; auth comes from a key or a link. */
50
50
  export declare function vitrinkaConfigured(): boolean;
51
- /** Recorder's own traffic — the network capture layer must skip it. */
51
+ /** The capture lanes skip `url`'s traffic too, until the returned release. */
52
+ export declare function addOwnBase(url: string): () => void;
53
+ /** This package's own traffic (the recorder's target, a report face's base) — the network capture layer must skip it. */
52
54
  export declare function isVitrinkaUrl(url: string): boolean;
53
55
  /** Storage key of the linked token (`vitrinka.recorder.link` in localStorage). */
54
56
  export declare const LINK_KEY = "link";
@@ -18,9 +18,22 @@ export function recorderConfig() {
18
18
  export function vitrinkaConfigured() {
19
19
  return config.url !== '';
20
20
  }
21
- /** Recorder's own traffic — the network capture layer must skip it. */
21
+ /** Other vitrinka origins this package talks to (a report face's `base`), never the recorder's target. */
22
+ const ownBases = new Set();
23
+ /** The capture lanes skip `url`'s traffic too, until the returned release. */
24
+ export function addOwnBase(url) {
25
+ const base = url.replace(/\/+$/, '');
26
+ ownBases.add(base);
27
+ return () => ownBases.delete(base);
28
+ }
29
+ /** This package's own traffic (the recorder's target, a report face's base) — the network capture layer must skip it. */
22
30
  export function isVitrinkaUrl(url) {
23
- return config.url !== '' && url.startsWith(config.url);
31
+ if (config.url !== '' && url.startsWith(config.url))
32
+ return true;
33
+ for (const base of ownBases)
34
+ if (base !== '' && url.startsWith(base))
35
+ return true;
36
+ return false;
24
37
  }
25
38
  // -- the stored device link --------------------------------------------------
26
39
  /** Storage key of the linked token (`vitrinka.recorder.link` in localStorage). */