@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const JWS = /^[\w-]+\.[\w-]+\.[\w-]+$/;
|
|
2
|
+
/** A clean identity, or null (with one warning) for anything malformed. */
|
|
3
|
+
export function normalizeIdentity(input) {
|
|
4
|
+
if (!input)
|
|
5
|
+
return null;
|
|
6
|
+
if ('token' in input) {
|
|
7
|
+
const token = typeof input.token === 'string' ? input.token.trim() : '';
|
|
8
|
+
if (token.length > 4096 || !JWS.test(token)) {
|
|
9
|
+
console.warn('vitrinka: identify({token}) needs the compact JWS your server signed — reporting anonymously');
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return { token };
|
|
13
|
+
}
|
|
14
|
+
const email = typeof input.email === 'string' ? input.email.trim().slice(0, 254) : '';
|
|
15
|
+
if (!email.includes('@')) {
|
|
16
|
+
console.warn('vitrinka: identify({email}) needs an email address — reporting anonymously');
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const name = typeof input.name === 'string' ? input.name.trim().slice(0, 200) : '';
|
|
20
|
+
return name ? { email, name } : { email };
|
|
21
|
+
}
|
|
22
|
+
let shared = null;
|
|
23
|
+
const listeners = new Set();
|
|
24
|
+
/** Name the person every mounted widget files as (a widget's own `identify` wins). */
|
|
25
|
+
export function identify(input) {
|
|
26
|
+
shared = normalizeIdentity(input);
|
|
27
|
+
for (const l of listeners)
|
|
28
|
+
l();
|
|
29
|
+
}
|
|
30
|
+
export function sharedIdentity() {
|
|
31
|
+
return shared;
|
|
32
|
+
}
|
|
33
|
+
export function onSharedIdentity(fn) {
|
|
34
|
+
listeners.add(fn);
|
|
35
|
+
return () => listeners.delete(fn);
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReportHandle, type ReportOptions } from './element';
|
|
2
|
+
export type { CaptureClass, CaptureNarrowing, CaptureProfile, CaptureStorage } from './profile';
|
|
3
|
+
export type { Locale } from './i18n';
|
|
4
|
+
export type { IdentifyInput, Identity } from './identity';
|
|
5
|
+
export type { Marker, MarkerShape, WireMarker } from './markers';
|
|
6
|
+
export type { ReportEnvelope, SubmitReply } from './wire';
|
|
7
|
+
export type { ReportFace, ReportHandle, ReportOptions, ReportScriptOptions, VitrinkaReportElement } from './element';
|
|
8
|
+
export { identify } from './identity';
|
|
9
|
+
/** Mount Report a problem (default) or the recorder pill (`face: 'recorder'`). */
|
|
10
|
+
export declare function mountReport(opts: ReportOptions): ReportHandle;
|
|
11
|
+
/** Define `<vitrinka-report>` (idempotent; mountReport calls it). */
|
|
12
|
+
export declare function defineReportElement(): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineReportElement as define, mountReport as mount } from './element';
|
|
2
|
+
export { identify } from './identity';
|
|
3
|
+
const faces = {
|
|
4
|
+
loadRecord: () => import('rrweb').then((m) => m.record),
|
|
5
|
+
recorderFace: () => import('./recorder-face').then((m) => m.mountRecorderFace),
|
|
6
|
+
defaultBase: () => '',
|
|
7
|
+
};
|
|
8
|
+
/** Mount Report a problem (default) or the recorder pill (`face: 'recorder'`). */
|
|
9
|
+
export function mountReport(opts) {
|
|
10
|
+
return mount(opts, faces);
|
|
11
|
+
}
|
|
12
|
+
/** Define `<vitrinka-report>` (idempotent; mountReport calls it). */
|
|
13
|
+
export function defineReportElement() {
|
|
14
|
+
define(faces);
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface Keybind {
|
|
2
|
+
code: string;
|
|
3
|
+
alt: boolean;
|
|
4
|
+
ctrl: boolean;
|
|
5
|
+
meta: boolean;
|
|
6
|
+
shift: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type KeyPress = Pick<KeyboardEvent, 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'>;
|
|
9
|
+
/** What a keydown means while the settings record a shortcut. */
|
|
10
|
+
export type KeybindVerdict = {
|
|
11
|
+
kind: 'cancel';
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'wait';
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'bare';
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'bind';
|
|
18
|
+
bind: Keybind;
|
|
19
|
+
};
|
|
20
|
+
export declare const KEYBIND_STORAGE_KEY = "report.keybind";
|
|
21
|
+
export declare function readKeybindPress(e: KeyPress): KeybindVerdict;
|
|
22
|
+
export declare function matchesKeybind(e: KeyPress, b: Keybind): boolean;
|
|
23
|
+
export declare function isMacPlatform(): boolean;
|
|
24
|
+
/** ⌃⌥⇧⌘R on a Mac, Ctrl+Alt+Shift+R elsewhere. */
|
|
25
|
+
export declare function keybindLabel(b: Keybind, mac?: boolean): string;
|
|
26
|
+
export declare function loadKeybind(): Keybind | null;
|
|
27
|
+
export declare function saveKeybind(b: Keybind | null): void;
|
|
28
|
+
/** Hear another tab change the shortcut; returns the unsubscribe. */
|
|
29
|
+
export declare function watchKeybind(on: (b: Keybind | null) => void): () => void;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reporter's own shortcut for Report a problem (QA Studio assumptions:
|
|
3
|
+
* the snap HotKeyRecorder rules). There is no default: the person records
|
|
4
|
+
* one in the widget's settings by pressing it. The next key pressed with a
|
|
5
|
+
* modifier becomes the shortcut; Esc on its own cancels; a bare key is
|
|
6
|
+
* refused with the reason — and so is Shift alone, which in a browser types
|
|
7
|
+
* capitals. Matched by physical key (`code`: ⌥ rewrites `key` on a Mac).
|
|
8
|
+
* Stored in ONE key of the recorder storage (`vitrinka.recorder.report.keybind`
|
|
9
|
+
* in localStorage); every tab hears a change.
|
|
10
|
+
*/
|
|
11
|
+
import { getRecorderStorage } from '../recorder/storage';
|
|
12
|
+
const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta', 'AltGraph', 'OS', 'CapsLock', 'Fn', 'Hyper', 'Super']);
|
|
13
|
+
export const KEYBIND_STORAGE_KEY = 'report.keybind';
|
|
14
|
+
export function readKeybindPress(e) {
|
|
15
|
+
if (MODIFIER_KEYS.has(e.key))
|
|
16
|
+
return { kind: 'wait' };
|
|
17
|
+
if (e.key === 'Escape' && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey)
|
|
18
|
+
return { kind: 'cancel' };
|
|
19
|
+
if (!e.altKey && !e.ctrlKey && !e.metaKey)
|
|
20
|
+
return { kind: 'bare' };
|
|
21
|
+
return { kind: 'bind', bind: { code: e.code, alt: e.altKey, ctrl: e.ctrlKey, meta: e.metaKey, shift: e.shiftKey } };
|
|
22
|
+
}
|
|
23
|
+
export function matchesKeybind(e, b) {
|
|
24
|
+
return e.code === b.code && e.altKey === b.alt && e.ctrlKey === b.ctrl && e.metaKey === b.meta && e.shiftKey === b.shift;
|
|
25
|
+
}
|
|
26
|
+
const NAMED = {
|
|
27
|
+
Space: 'Space',
|
|
28
|
+
Enter: '↵',
|
|
29
|
+
Backspace: '⌫',
|
|
30
|
+
Tab: '⇥',
|
|
31
|
+
ArrowUp: '↑',
|
|
32
|
+
ArrowDown: '↓',
|
|
33
|
+
ArrowLeft: '←',
|
|
34
|
+
ArrowRight: '→',
|
|
35
|
+
Slash: '/',
|
|
36
|
+
Backslash: '\\',
|
|
37
|
+
Period: '.',
|
|
38
|
+
Comma: ',',
|
|
39
|
+
Semicolon: ';',
|
|
40
|
+
Quote: "'",
|
|
41
|
+
BracketLeft: '[',
|
|
42
|
+
BracketRight: ']',
|
|
43
|
+
Minus: '-',
|
|
44
|
+
Equal: '=',
|
|
45
|
+
Backquote: '`',
|
|
46
|
+
};
|
|
47
|
+
function keyLabel(code) {
|
|
48
|
+
const letter = /^Key([A-Z])$/.exec(code);
|
|
49
|
+
if (letter)
|
|
50
|
+
return letter[1];
|
|
51
|
+
const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
|
|
52
|
+
if (digit)
|
|
53
|
+
return digit[1];
|
|
54
|
+
return NAMED[code] ?? code;
|
|
55
|
+
}
|
|
56
|
+
export function isMacPlatform() {
|
|
57
|
+
const nav = globalThis.navigator;
|
|
58
|
+
const platform = nav?.userAgentData?.platform ?? nav?.platform ?? '';
|
|
59
|
+
return /mac|iphone|ipad/i.test(platform);
|
|
60
|
+
}
|
|
61
|
+
/** ⌃⌥⇧⌘R on a Mac, Ctrl+Alt+Shift+R elsewhere. */
|
|
62
|
+
export function keybindLabel(b, mac = isMacPlatform()) {
|
|
63
|
+
const key = keyLabel(b.code);
|
|
64
|
+
if (mac)
|
|
65
|
+
return `${b.ctrl ? '⌃' : ''}${b.alt ? '⌥' : ''}${b.shift ? '⇧' : ''}${b.meta ? '⌘' : ''}${key}`;
|
|
66
|
+
return [b.ctrl && 'Ctrl', b.alt && 'Alt', b.shift && 'Shift', b.meta && 'Meta', key].filter(Boolean).join('+');
|
|
67
|
+
}
|
|
68
|
+
function parseKeybind(raw) {
|
|
69
|
+
if (!raw)
|
|
70
|
+
return null;
|
|
71
|
+
try {
|
|
72
|
+
const v = JSON.parse(raw);
|
|
73
|
+
if (typeof v !== 'object' || v === null)
|
|
74
|
+
return null;
|
|
75
|
+
const b = v;
|
|
76
|
+
if (typeof b.code !== 'string' || !b.code)
|
|
77
|
+
return null;
|
|
78
|
+
const bind = { code: b.code, alt: b.alt === true, ctrl: b.ctrl === true, meta: b.meta === true, shift: b.shift === true };
|
|
79
|
+
return bind.alt || bind.ctrl || bind.meta ? bind : null;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function loadKeybind() {
|
|
86
|
+
return parseKeybind(getRecorderStorage().getString(KEYBIND_STORAGE_KEY));
|
|
87
|
+
}
|
|
88
|
+
export function saveKeybind(b) {
|
|
89
|
+
const s = getRecorderStorage();
|
|
90
|
+
if (b)
|
|
91
|
+
s.set(KEYBIND_STORAGE_KEY, JSON.stringify(b));
|
|
92
|
+
else
|
|
93
|
+
s.remove(KEYBIND_STORAGE_KEY);
|
|
94
|
+
}
|
|
95
|
+
/** Hear another tab change the shortcut; returns the unsubscribe. */
|
|
96
|
+
export function watchKeybind(on) {
|
|
97
|
+
const s = getRecorderStorage();
|
|
98
|
+
return s.watch ? s.watch(KEYBIND_STORAGE_KEY, (v) => on(parseKeybind(v))) : () => undefined;
|
|
99
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markers (QA Studio D12/D21): what a reporter draws on the frozen page —
|
|
3
|
+
* circle, box, arrow, hide — numbered 1, 2, 3… with an optional note. No
|
|
4
|
+
* element selector, ever: a marker is a region of the viewport in CSS
|
|
5
|
+
* pixels (`viewport: {w, h, dpr}` rides on the report's env).
|
|
6
|
+
*
|
|
7
|
+
* `hide` is a masking box: the region is blanked in the capture before it
|
|
8
|
+
* leaves the browser — an opaque box joins every full snapshot of the replay
|
|
9
|
+
* (so every frame and every still shows it blank), and the text and form
|
|
10
|
+
* values of the page's nodes under it (`hiddenNodeIds`, read off rrweb's
|
|
11
|
+
* mirror at send) are emptied in the snapshots and in the mutations and
|
|
12
|
+
* input events that carried them.
|
|
13
|
+
*/
|
|
14
|
+
import type { eventWithTime } from '@rrweb/types';
|
|
15
|
+
export type MarkerShape = 'circle' | 'box' | 'arrow' | 'hide';
|
|
16
|
+
export interface Rect {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
w: number;
|
|
20
|
+
h: number;
|
|
21
|
+
}
|
|
22
|
+
/** Which corner of an arrow's rect its head points into. */
|
|
23
|
+
export type ArrowHead = 'nw' | 'ne' | 'sw' | 'se';
|
|
24
|
+
export interface Marker {
|
|
25
|
+
n: number;
|
|
26
|
+
shape: MarkerShape;
|
|
27
|
+
rect: Rect;
|
|
28
|
+
note: string;
|
|
29
|
+
/** Arrows only: the head's corner (the tail sits in the opposite one). */
|
|
30
|
+
head?: ArrowHead;
|
|
31
|
+
}
|
|
32
|
+
/** A marker on the report wire. */
|
|
33
|
+
export interface WireMarker {
|
|
34
|
+
n: number;
|
|
35
|
+
shape: MarkerShape;
|
|
36
|
+
rect: Rect;
|
|
37
|
+
note?: string;
|
|
38
|
+
head?: ArrowHead;
|
|
39
|
+
}
|
|
40
|
+
export interface Point {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
}
|
|
44
|
+
/** The smallest stroke that counts as a marker; a click without moving is not one. */
|
|
45
|
+
export declare const MIN_MARK_PX = 8;
|
|
46
|
+
export declare function rectBetween(a: Point, b: Point): Rect;
|
|
47
|
+
export declare function arrowHead(tail: Point, head: Point): ArrowHead;
|
|
48
|
+
/** The arrow's two ends from its rect and head corner. */
|
|
49
|
+
export declare function arrowEnds(rect: Rect, head: ArrowHead): {
|
|
50
|
+
tail: Point;
|
|
51
|
+
tip: Point;
|
|
52
|
+
};
|
|
53
|
+
/** Is the stroke from `a` to `b` big enough to be a `shape`? */
|
|
54
|
+
export declare function isMark(shape: MarkerShape, a: Point, b: Point): boolean;
|
|
55
|
+
/** Numbered 1..n in drawing order (after a removal too). */
|
|
56
|
+
export declare function renumber(markers: readonly Marker[]): Marker[];
|
|
57
|
+
export declare function toWire(markers: readonly Marker[]): WireMarker[];
|
|
58
|
+
/** Far above any id rrweb hands out in one recording. */
|
|
59
|
+
export declare const HIDE_NODE_ID_BASE = 2000000000;
|
|
60
|
+
export declare const HIDE_ATTR = "data-vitrinka-hidden";
|
|
61
|
+
/**
|
|
62
|
+
* The capture with every `hide` region blanked: the boxes join each full
|
|
63
|
+
* snapshot, and the nodes in `hiddenIds` lose their text and values in the
|
|
64
|
+
* snapshots, in mutations and in input events. Returns new events; the
|
|
65
|
+
* input is never mutated (the buffer still holds it).
|
|
66
|
+
*/
|
|
67
|
+
export declare function applyHides(events: readonly eventWithTime[], hides: readonly Rect[], hiddenIds: ReadonlySet<number>): eventWithTime[];
|
|
68
|
+
/** What `hiddenNodeIds` needs of rrweb's mirror. */
|
|
69
|
+
export interface NodeIds {
|
|
70
|
+
getId(n: Node): number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The rrweb ids of the page's text nodes and form controls whose box is
|
|
74
|
+
* centred inside a hide region right now (the page is frozen while the
|
|
75
|
+
* reporter marks). Our own surfaces are skipped.
|
|
76
|
+
*/
|
|
77
|
+
export declare function hiddenNodeIds(hides: readonly Rect[], mirror: NodeIds | null, doc?: Document): Set<number>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/** The smallest stroke that counts as a marker; a click without moving is not one. */
|
|
2
|
+
export const MIN_MARK_PX = 8;
|
|
3
|
+
export function rectBetween(a, b) {
|
|
4
|
+
return { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y), w: Math.abs(b.x - a.x), h: Math.abs(b.y - a.y) };
|
|
5
|
+
}
|
|
6
|
+
export function arrowHead(tail, head) {
|
|
7
|
+
return `${head.y < tail.y ? 'n' : 's'}${head.x < tail.x ? 'w' : 'e'}`;
|
|
8
|
+
}
|
|
9
|
+
/** The arrow's two ends from its rect and head corner. */
|
|
10
|
+
export function arrowEnds(rect, head) {
|
|
11
|
+
const left = rect.x;
|
|
12
|
+
const right = rect.x + rect.w;
|
|
13
|
+
const top = rect.y;
|
|
14
|
+
const bottom = rect.y + rect.h;
|
|
15
|
+
const tip = { x: head.endsWith('w') ? left : right, y: head.startsWith('n') ? top : bottom };
|
|
16
|
+
const tail = { x: head.endsWith('w') ? right : left, y: head.startsWith('n') ? bottom : top };
|
|
17
|
+
return { tail, tip };
|
|
18
|
+
}
|
|
19
|
+
/** Is the stroke from `a` to `b` big enough to be a `shape`? */
|
|
20
|
+
export function isMark(shape, a, b) {
|
|
21
|
+
if (shape === 'arrow')
|
|
22
|
+
return Math.hypot(b.x - a.x, b.y - a.y) >= MIN_MARK_PX * 2;
|
|
23
|
+
return Math.abs(b.x - a.x) >= MIN_MARK_PX && Math.abs(b.y - a.y) >= MIN_MARK_PX;
|
|
24
|
+
}
|
|
25
|
+
/** Numbered 1..n in drawing order (after a removal too). */
|
|
26
|
+
export function renumber(markers) {
|
|
27
|
+
return markers.map((m, i) => ({ ...m, n: i + 1 }));
|
|
28
|
+
}
|
|
29
|
+
export function toWire(markers) {
|
|
30
|
+
return markers.map((m) => ({
|
|
31
|
+
n: m.n,
|
|
32
|
+
shape: m.shape,
|
|
33
|
+
rect: { x: Math.round(m.rect.x), y: Math.round(m.rect.y), w: Math.round(m.rect.w), h: Math.round(m.rect.h) },
|
|
34
|
+
...(m.note.trim() ? { note: m.note.trim() } : {}),
|
|
35
|
+
...(m.shape === 'arrow' && m.head ? { head: m.head } : {}),
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
// -- hide: blanking the capture ------------------------------------------------
|
|
39
|
+
/** rrweb's numeric codes (`@rrweb/types` is type-only here). */
|
|
40
|
+
const FULL_SNAPSHOT = 2;
|
|
41
|
+
const INCREMENTAL = 3;
|
|
42
|
+
const SOURCE_MUTATION = 0;
|
|
43
|
+
const SOURCE_INPUT = 5;
|
|
44
|
+
const NODE_ELEMENT = 2;
|
|
45
|
+
const NODE_TEXT = 3;
|
|
46
|
+
/** Far above any id rrweb hands out in one recording. */
|
|
47
|
+
export const HIDE_NODE_ID_BASE = 2_000_000_000;
|
|
48
|
+
export const HIDE_ATTR = 'data-vitrinka-hidden';
|
|
49
|
+
const HIDE_FILL = '#1b1b1f';
|
|
50
|
+
function hideBox(rect, i) {
|
|
51
|
+
const style = `position:fixed;left:${Math.round(rect.x)}px;top:${Math.round(rect.y)}px;` +
|
|
52
|
+
`width:${Math.round(rect.w)}px;height:${Math.round(rect.h)}px;` +
|
|
53
|
+
`background:${HIDE_FILL};z-index:2147483647;pointer-events:none;`;
|
|
54
|
+
return { type: NODE_ELEMENT, id: HIDE_NODE_ID_BASE + i, tagName: 'div', attributes: { [HIDE_ATTR]: '', style }, childNodes: [] };
|
|
55
|
+
}
|
|
56
|
+
/** A copy of the tree with hidden texts and values emptied and the boxes appended to <body>. */
|
|
57
|
+
function blankTree(node, ids, boxes, appended) {
|
|
58
|
+
const out = { ...node };
|
|
59
|
+
if (node.type === NODE_TEXT && ids.has(node.id))
|
|
60
|
+
out.textContent = '';
|
|
61
|
+
if (node.attributes && ids.has(node.id) && 'value' in node.attributes)
|
|
62
|
+
out.attributes = { ...node.attributes, value: '' };
|
|
63
|
+
if (node.childNodes) {
|
|
64
|
+
out.childNodes = node.childNodes.map((c) => blankTree(c, ids, boxes, appended));
|
|
65
|
+
if (!appended.done && node.type === NODE_ELEMENT && node.tagName === 'body') {
|
|
66
|
+
out.childNodes.push(...boxes);
|
|
67
|
+
appended.done = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** The last <html>-ish element to hang the boxes on when a snapshot has no <body> (a frameset). */
|
|
73
|
+
function appendToRoot(root, boxes) {
|
|
74
|
+
const html = root.childNodes?.find((c) => c.type === NODE_ELEMENT);
|
|
75
|
+
(html ?? root).childNodes?.push(...boxes);
|
|
76
|
+
}
|
|
77
|
+
function blankAdded(node, ids) {
|
|
78
|
+
return blankTree(node, ids, [], { done: true });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The capture with every `hide` region blanked: the boxes join each full
|
|
82
|
+
* snapshot, and the nodes in `hiddenIds` lose their text and values in the
|
|
83
|
+
* snapshots, in mutations and in input events. Returns new events; the
|
|
84
|
+
* input is never mutated (the buffer still holds it).
|
|
85
|
+
*/
|
|
86
|
+
export function applyHides(events, hides, hiddenIds) {
|
|
87
|
+
if (!hides.length && !hiddenIds.size)
|
|
88
|
+
return events.slice();
|
|
89
|
+
const boxes = hides.map(hideBox);
|
|
90
|
+
return events.map((ev) => {
|
|
91
|
+
// boundary: rrweb's serialized JSON, read through the fields above.
|
|
92
|
+
const data = ev.data;
|
|
93
|
+
if (ev.type === FULL_SNAPSHOT && data.node) {
|
|
94
|
+
const appended = { done: false };
|
|
95
|
+
const node = blankTree(data.node, hiddenIds, boxes, appended);
|
|
96
|
+
if (!appended.done)
|
|
97
|
+
appendToRoot(node, boxes);
|
|
98
|
+
return { ...ev, data: { ...ev.data, node } };
|
|
99
|
+
}
|
|
100
|
+
if (ev.type !== INCREMENTAL || !hiddenIds.size)
|
|
101
|
+
return ev;
|
|
102
|
+
if (data.source === SOURCE_MUTATION) {
|
|
103
|
+
const m = ev.data;
|
|
104
|
+
const blanked = {
|
|
105
|
+
...m,
|
|
106
|
+
...(m.texts ? { texts: m.texts.map((t) => (hiddenIds.has(t.id) ? { ...t, value: '' } : t)) } : {}),
|
|
107
|
+
...(m.adds ? { adds: m.adds.map((a) => ({ ...a, node: blankAdded(a.node, hiddenIds) })) } : {}),
|
|
108
|
+
...(m.attributes
|
|
109
|
+
? {
|
|
110
|
+
attributes: m.attributes.map((a) => hiddenIds.has(a.id) && 'value' in a.attributes ? { ...a, attributes: { ...a.attributes, value: '' } } : a),
|
|
111
|
+
}
|
|
112
|
+
: {}),
|
|
113
|
+
};
|
|
114
|
+
return { ...ev, data: blanked };
|
|
115
|
+
}
|
|
116
|
+
if (data.source === SOURCE_INPUT) {
|
|
117
|
+
const input = ev.data;
|
|
118
|
+
if (hiddenIds.has(input.id))
|
|
119
|
+
return { ...ev, data: { ...input, text: '' } };
|
|
120
|
+
}
|
|
121
|
+
return ev;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function inside(p, r) {
|
|
125
|
+
return p.x >= r.x && p.x <= r.x + r.w && p.y >= r.y && p.y <= r.y + r.h;
|
|
126
|
+
}
|
|
127
|
+
function centerOf(r) {
|
|
128
|
+
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The rrweb ids of the page's text nodes and form controls whose box is
|
|
132
|
+
* centred inside a hide region right now (the page is frozen while the
|
|
133
|
+
* reporter marks). Our own surfaces are skipped.
|
|
134
|
+
*/
|
|
135
|
+
export function hiddenNodeIds(hides, mirror, doc = document) {
|
|
136
|
+
const ids = new Set();
|
|
137
|
+
if (!hides.length || !mirror || !doc.body)
|
|
138
|
+
return ids;
|
|
139
|
+
const within = (r) => r.width > 0 && r.height > 0 && hides.some((h) => inside(centerOf(r), h));
|
|
140
|
+
const take = (n) => {
|
|
141
|
+
const id = mirror.getId(n);
|
|
142
|
+
if (id > 0)
|
|
143
|
+
ids.add(id);
|
|
144
|
+
};
|
|
145
|
+
const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
|
|
146
|
+
const range = doc.createRange();
|
|
147
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
148
|
+
if (n.nodeType === Node.TEXT_NODE) {
|
|
149
|
+
if (!n.textContent?.trim())
|
|
150
|
+
continue;
|
|
151
|
+
range.selectNodeContents(n);
|
|
152
|
+
if (within(range.getBoundingClientRect()))
|
|
153
|
+
take(n);
|
|
154
|
+
}
|
|
155
|
+
else if (n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement) {
|
|
156
|
+
if (within(n.getBoundingClientRect()))
|
|
157
|
+
take(n);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
range.detach();
|
|
161
|
+
return ids;
|
|
162
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The capture profile (QA Studio D7): what Report a problem keeps before a
|
|
3
|
+
* report, decided per project in vitrinka (`captureProfile` in
|
|
4
|
+
* `GET /api/v1/report-config`). A host's init options can only NARROW it.
|
|
5
|
+
*
|
|
6
|
+
* storage memory | browser (IndexedDB, masked, expiring with the window)
|
|
7
|
+
* windowSec how far back (default 300)
|
|
8
|
+
* maxBytes the replay's size cap
|
|
9
|
+
* classes ⊆ errors · interactions · full · console · network
|
|
10
|
+
*
|
|
11
|
+
* Classes: `interactions` = the masked DOM replay (clicks, scrolls, typing
|
|
12
|
+
* as masked input, each page's view); `errors` = uncaught errors, console
|
|
13
|
+
* errors and failed requests; `console` = every console level; `network` =
|
|
14
|
+
* every request's method, path, status and duration; `full` = all of them.
|
|
15
|
+
* Request and response bodies and headers are never part of a report.
|
|
16
|
+
*/
|
|
17
|
+
import type { RedactionPolicy } from '@vitrinka/redact';
|
|
18
|
+
export type CaptureClass = 'errors' | 'interactions' | 'full' | 'console' | 'network';
|
|
19
|
+
export type CaptureStorage = 'memory' | 'browser';
|
|
20
|
+
export interface CaptureProfile {
|
|
21
|
+
storage: CaptureStorage;
|
|
22
|
+
windowSec: number;
|
|
23
|
+
maxBytes: number;
|
|
24
|
+
classes: CaptureClass[];
|
|
25
|
+
}
|
|
26
|
+
/** What a host may pass to narrow the project's profile; every field optional. */
|
|
27
|
+
export type CaptureNarrowing = Partial<CaptureProfile>;
|
|
28
|
+
/** What each class switches on, `full` expanded. */
|
|
29
|
+
export interface CaptureLanes {
|
|
30
|
+
replay: boolean;
|
|
31
|
+
errors: boolean;
|
|
32
|
+
console: boolean;
|
|
33
|
+
network: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The profile a project gets when its server names one without every field. */
|
|
36
|
+
export declare const PROFILE_DEFAULTS: CaptureProfile;
|
|
37
|
+
/**
|
|
38
|
+
* A server without a capture profile (or an unreachable one): memory, the
|
|
39
|
+
* last minute under 4 MiB, errors and the replay — errors only where the
|
|
40
|
+
* server says `flightRecorder: false`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function legacyProfile(flightRecorder?: boolean): CaptureProfile;
|
|
43
|
+
/** The server's `captureProfile`, field by field; anything missing or malformed takes its default. */
|
|
44
|
+
export declare function parseProfile(raw: unknown, flightRecorder?: boolean): CaptureProfile;
|
|
45
|
+
export declare function lanesOf(classes: readonly CaptureClass[]): CaptureLanes;
|
|
46
|
+
/**
|
|
47
|
+
* The project's profile as the host narrowed it: storage only down to
|
|
48
|
+
* memory, the window and the cap only shorter, the classes only fewer
|
|
49
|
+
* (compared lane by lane, so `full` on either side means all four).
|
|
50
|
+
*/
|
|
51
|
+
export declare function narrowProfile(server: CaptureProfile, host: CaptureNarrowing | undefined): CaptureProfile;
|
|
52
|
+
/** The masking profile a project asked for (`profile` in report-config). */
|
|
53
|
+
export type MaskingProfile = 'strict' | 'balanced' | 'full';
|
|
54
|
+
export declare function maskingOf(raw: unknown): MaskingProfile;
|
|
55
|
+
/**
|
|
56
|
+
* The redaction rules a masking profile means for the shared engine:
|
|
57
|
+
* strict masks every text node and input (a `[data-vitrinka-unmask]`
|
|
58
|
+
* subtree keeps its text), balanced masks inputs, full masks nothing.
|
|
59
|
+
*/
|
|
60
|
+
export declare function maskingPolicy(masking: MaskingProfile): RedactionPolicy;
|
|
61
|
+
/** The attribute a host puts on a subtree whose text a strict replay may keep. */
|
|
62
|
+
export declare const UNMASK_SELECTOR = "[data-vitrinka-unmask]";
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const CLASSES = ['errors', 'interactions', 'full', 'console', 'network'];
|
|
2
|
+
const MIN_WINDOW_SEC = 10;
|
|
3
|
+
const MAX_WINDOW_SEC = 3600;
|
|
4
|
+
const MIN_BYTES = 256 * 1024;
|
|
5
|
+
const MAX_BYTES = 64 * 1024 * 1024;
|
|
6
|
+
/** The profile a project gets when its server names one without every field. */
|
|
7
|
+
export const PROFILE_DEFAULTS = {
|
|
8
|
+
storage: 'memory',
|
|
9
|
+
windowSec: 300,
|
|
10
|
+
maxBytes: 12 * 1024 * 1024,
|
|
11
|
+
classes: ['errors', 'interactions'],
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A server without a capture profile (or an unreachable one): memory, the
|
|
15
|
+
* last minute under 4 MiB, errors and the replay — errors only where the
|
|
16
|
+
* server says `flightRecorder: false`.
|
|
17
|
+
*/
|
|
18
|
+
export function legacyProfile(flightRecorder) {
|
|
19
|
+
return {
|
|
20
|
+
storage: 'memory',
|
|
21
|
+
windowSec: 60,
|
|
22
|
+
maxBytes: 4 * 1024 * 1024,
|
|
23
|
+
classes: flightRecorder === false ? ['errors'] : ['errors', 'interactions'],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function clamp(n, lo, hi) {
|
|
27
|
+
return Math.min(hi, Math.max(lo, n));
|
|
28
|
+
}
|
|
29
|
+
function classesOf(raw) {
|
|
30
|
+
if (!Array.isArray(raw))
|
|
31
|
+
return null;
|
|
32
|
+
return CLASSES.filter((c) => raw.includes(c));
|
|
33
|
+
}
|
|
34
|
+
/** The server's `captureProfile`, field by field; anything missing or malformed takes its default. */
|
|
35
|
+
export function parseProfile(raw, flightRecorder) {
|
|
36
|
+
if (typeof raw !== 'object' || raw === null)
|
|
37
|
+
return legacyProfile(flightRecorder);
|
|
38
|
+
const p = raw;
|
|
39
|
+
return {
|
|
40
|
+
storage: p.storage === 'browser' ? 'browser' : p.storage === 'memory' ? 'memory' : PROFILE_DEFAULTS.storage,
|
|
41
|
+
windowSec: typeof p.windowSec === 'number' && Number.isFinite(p.windowSec)
|
|
42
|
+
? clamp(Math.round(p.windowSec), MIN_WINDOW_SEC, MAX_WINDOW_SEC)
|
|
43
|
+
: PROFILE_DEFAULTS.windowSec,
|
|
44
|
+
maxBytes: typeof p.maxBytes === 'number' && Number.isFinite(p.maxBytes)
|
|
45
|
+
? clamp(Math.round(p.maxBytes), MIN_BYTES, MAX_BYTES)
|
|
46
|
+
: PROFILE_DEFAULTS.maxBytes,
|
|
47
|
+
classes: classesOf(p.classes) ?? PROFILE_DEFAULTS.classes,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function lanesOf(classes) {
|
|
51
|
+
const full = classes.includes('full');
|
|
52
|
+
return {
|
|
53
|
+
replay: full || classes.includes('interactions'),
|
|
54
|
+
errors: full || classes.includes('errors'),
|
|
55
|
+
console: full || classes.includes('console'),
|
|
56
|
+
network: full || classes.includes('network'),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function classesFor(lanes) {
|
|
60
|
+
const out = [];
|
|
61
|
+
if (lanes.errors)
|
|
62
|
+
out.push('errors');
|
|
63
|
+
if (lanes.replay)
|
|
64
|
+
out.push('interactions');
|
|
65
|
+
if (lanes.console)
|
|
66
|
+
out.push('console');
|
|
67
|
+
if (lanes.network)
|
|
68
|
+
out.push('network');
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The project's profile as the host narrowed it: storage only down to
|
|
73
|
+
* memory, the window and the cap only shorter, the classes only fewer
|
|
74
|
+
* (compared lane by lane, so `full` on either side means all four).
|
|
75
|
+
*/
|
|
76
|
+
export function narrowProfile(server, host) {
|
|
77
|
+
if (!host)
|
|
78
|
+
return server;
|
|
79
|
+
const window = typeof host.windowSec === 'number' && host.windowSec > 0 ? Math.min(server.windowSec, host.windowSec) : server.windowSec;
|
|
80
|
+
const bytes = typeof host.maxBytes === 'number' && host.maxBytes > 0 ? Math.min(server.maxBytes, host.maxBytes) : server.maxBytes;
|
|
81
|
+
let classes = server.classes;
|
|
82
|
+
if (host.classes) {
|
|
83
|
+
const s = lanesOf(server.classes);
|
|
84
|
+
const h = lanesOf(host.classes);
|
|
85
|
+
classes = classesFor({
|
|
86
|
+
replay: s.replay && h.replay,
|
|
87
|
+
errors: s.errors && h.errors,
|
|
88
|
+
console: s.console && h.console,
|
|
89
|
+
network: s.network && h.network,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
storage: host.storage === 'memory' ? 'memory' : server.storage,
|
|
94
|
+
windowSec: clamp(window, MIN_WINDOW_SEC, MAX_WINDOW_SEC),
|
|
95
|
+
maxBytes: clamp(bytes, MIN_BYTES, MAX_BYTES),
|
|
96
|
+
classes,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function maskingOf(raw) {
|
|
100
|
+
return raw === 'balanced' || raw === 'full' ? raw : 'strict';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The redaction rules a masking profile means for the shared engine:
|
|
104
|
+
* strict masks every text node and input (a `[data-vitrinka-unmask]`
|
|
105
|
+
* subtree keeps its text), balanced masks inputs, full masks nothing.
|
|
106
|
+
*/
|
|
107
|
+
export function maskingPolicy(masking) {
|
|
108
|
+
if (masking === 'full')
|
|
109
|
+
return { fullFidelity: true };
|
|
110
|
+
if (masking === 'balanced')
|
|
111
|
+
return {};
|
|
112
|
+
return { maskAllText: true };
|
|
113
|
+
}
|
|
114
|
+
/** The attribute a host puts on a subtree whose text a strict replay may keep. */
|
|
115
|
+
export const UNMASK_SELECTOR = '[data-vitrinka-unmask]';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `face: 'recorder'` (QA Studio D6): the same engine with the recorder pill
|
|
3
|
+
* as its face — `VitrinkaRecorderRoot` + `VitrinkaRecorderPill` rendered
|
|
4
|
+
* into a detached root of their own. Loaded lazily by the npm entry only, so
|
|
5
|
+
* a report-only host never pays for React or the recorder.
|
|
6
|
+
*/
|
|
7
|
+
import { createElement } from 'react';
|
|
8
|
+
import { createRoot } from 'react-dom/client';
|
|
9
|
+
import { VitrinkaRecorderPill, VitrinkaRecorderRoot } from '../recorder';
|
|
10
|
+
export function mountRecorderFace(opts) {
|
|
11
|
+
const container = document.createElement('div');
|
|
12
|
+
container.hidden = true;
|
|
13
|
+
document.body.append(container);
|
|
14
|
+
const root = createRoot(container);
|
|
15
|
+
root.render(createElement(VitrinkaRecorderRoot, { url: opts.base, recorderKey: opts.key, appVersion: opts.appVersion, sanitizeUrl: opts.sanitizeUrl }, createElement(VitrinkaRecorderPill)));
|
|
16
|
+
return () => {
|
|
17
|
+
root.unmount();
|
|
18
|
+
container.remove();
|
|
19
|
+
};
|
|
20
|
+
}
|