@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,136 @@
|
|
|
1
|
+
import { windowEnd } from '../flight';
|
|
2
|
+
const DB = 'vitrinka.capture';
|
|
3
|
+
const WINDOWS = 'windows';
|
|
4
|
+
const CHUNKS = 'chunks';
|
|
5
|
+
function done(tx) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
tx.oncomplete = () => resolve();
|
|
8
|
+
tx.onabort = tx.onerror = () => reject(tx.error ?? new Error('vitrinka: capture store transaction failed'));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function result(request) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
request.onsuccess = () => resolve(request.result);
|
|
14
|
+
request.onerror = () => reject(request.error ?? new Error('vitrinka: capture store request failed'));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function chunkRange(windowId) {
|
|
18
|
+
return IDBKeyRange.bound([windowId, 0], [windowId, Number.MAX_SAFE_INTEGER]);
|
|
19
|
+
}
|
|
20
|
+
function isStoredWindow(v) {
|
|
21
|
+
if (typeof v !== 'object' || v === null)
|
|
22
|
+
return false;
|
|
23
|
+
const w = v;
|
|
24
|
+
// A record without a scope cannot say what it was captured for: it never comes back (sweep).
|
|
25
|
+
return typeof w.id === 'string' && typeof w.tab === 'string' && typeof w.startMs === 'number' && typeof w.lastMs === 'number';
|
|
26
|
+
}
|
|
27
|
+
/** Open (creating) the store; rejects where IndexedDB is absent or refuses — the caller stays in memory. */
|
|
28
|
+
export function openCaptureStore(idb = globalThis.indexedDB) {
|
|
29
|
+
if (!idb)
|
|
30
|
+
return Promise.reject(new Error('vitrinka: IndexedDB is not available'));
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const request = idb.open(DB, 1);
|
|
33
|
+
request.onupgradeneeded = () => {
|
|
34
|
+
request.result.createObjectStore(WINDOWS, { keyPath: 'id' });
|
|
35
|
+
request.result.createObjectStore(CHUNKS);
|
|
36
|
+
};
|
|
37
|
+
request.onerror = () => reject(request.error ?? new Error('vitrinka: capture store did not open'));
|
|
38
|
+
request.onblocked = () => reject(new Error('vitrinka: capture store is blocked by another tab'));
|
|
39
|
+
request.onsuccess = () => resolve(request.result);
|
|
40
|
+
}).then((db) => {
|
|
41
|
+
db.onversionchange = () => db.close();
|
|
42
|
+
const dropIn = (tx, windowId) => {
|
|
43
|
+
tx.objectStore(WINDOWS).delete(windowId);
|
|
44
|
+
tx.objectStore(CHUNKS).delete(chunkRange(windowId));
|
|
45
|
+
};
|
|
46
|
+
const store = {
|
|
47
|
+
async putWindow(w) {
|
|
48
|
+
const tx = db.transaction(WINDOWS, 'readwrite');
|
|
49
|
+
tx.objectStore(WINDOWS).put(w);
|
|
50
|
+
await done(tx);
|
|
51
|
+
},
|
|
52
|
+
async putChunk(windowId, part, events, lanes) {
|
|
53
|
+
const tx = db.transaction(CHUNKS, 'readwrite');
|
|
54
|
+
const record = { events, lanes: [...lanes] };
|
|
55
|
+
tx.objectStore(CHUNKS).put(record, [windowId, part]);
|
|
56
|
+
await done(tx);
|
|
57
|
+
},
|
|
58
|
+
async putWindowChunk(head, part, events, lanes) {
|
|
59
|
+
const tx = db.transaction([WINDOWS, CHUNKS], 'readwrite');
|
|
60
|
+
const record = { events, lanes: [...lanes] };
|
|
61
|
+
try {
|
|
62
|
+
tx.objectStore(CHUNKS).put(record, [head.id, part]);
|
|
63
|
+
tx.objectStore(WINDOWS).put(head);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
tx.abort();
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
await done(tx);
|
|
70
|
+
},
|
|
71
|
+
async dropWindow(windowId) {
|
|
72
|
+
const tx = db.transaction([WINDOWS, CHUNKS], 'readwrite');
|
|
73
|
+
dropIn(tx, windowId);
|
|
74
|
+
await done(tx);
|
|
75
|
+
},
|
|
76
|
+
async clear(tab) {
|
|
77
|
+
const tx = db.transaction([WINDOWS, CHUNKS], 'readwrite');
|
|
78
|
+
const all = await result(tx.objectStore(WINDOWS).getAll());
|
|
79
|
+
for (const w of all)
|
|
80
|
+
if (isStoredWindow(w) && w.tab === tab)
|
|
81
|
+
dropIn(tx, w.id);
|
|
82
|
+
await done(tx);
|
|
83
|
+
},
|
|
84
|
+
async sweep(now, windowMs, tab, scope) {
|
|
85
|
+
const tx = db.transaction([WINDOWS, CHUNKS], 'readwrite');
|
|
86
|
+
const all = (await result(tx.objectStore(WINDOWS).getAll())).filter(isStoredWindow);
|
|
87
|
+
const kept = [];
|
|
88
|
+
const byTab = new Map();
|
|
89
|
+
for (const w of all)
|
|
90
|
+
byTab.set(w.tab, [...(byTab.get(w.tab) ?? []), w]);
|
|
91
|
+
for (const [owner, list] of byTab) {
|
|
92
|
+
// A replay window lasts until the next replay window of its load; a
|
|
93
|
+
// lane span until its newest entry.
|
|
94
|
+
const replay = list.filter((w) => w.kind !== 'lanes').sort((a, b) => a.startMs - b.startMs);
|
|
95
|
+
const end = (w) => (w.kind === 'lanes' ? w.lastMs : windowEnd(w, replay[replay.indexOf(w) + 1]));
|
|
96
|
+
for (const w of list.sort((a, b) => a.startMs - b.startMs)) {
|
|
97
|
+
const aged = end(w) <= now - windowMs;
|
|
98
|
+
if (aged || (owner === tab && w.scope !== scope))
|
|
99
|
+
dropIn(tx, w.id);
|
|
100
|
+
else if (owner === tab)
|
|
101
|
+
kept.push(w);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
await done(tx);
|
|
105
|
+
return kept;
|
|
106
|
+
},
|
|
107
|
+
async read(windowId) {
|
|
108
|
+
const tx = db.transaction(CHUNKS, 'readonly');
|
|
109
|
+
const records = await result(tx.objectStore(CHUNKS).getAll(chunkRange(windowId)));
|
|
110
|
+
await done(tx);
|
|
111
|
+
const events = [];
|
|
112
|
+
const lanes = [];
|
|
113
|
+
for (const r of records) {
|
|
114
|
+
// boundary: our own JSON, written by putChunk above.
|
|
115
|
+
events.push(...JSON.parse(r.events));
|
|
116
|
+
lanes.push(...r.lanes);
|
|
117
|
+
}
|
|
118
|
+
return { events, lanes };
|
|
119
|
+
},
|
|
120
|
+
close: () => db.close(),
|
|
121
|
+
};
|
|
122
|
+
return store;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Leave nothing on disk where the profile says memory (a host narrowed it,
|
|
127
|
+
* the project changed it): delete the database if a browser profile left one.
|
|
128
|
+
*/
|
|
129
|
+
export function deleteCaptureStore(idb = globalThis.indexedDB) {
|
|
130
|
+
try {
|
|
131
|
+
idb?.deleteDatabase(DB);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
console.warn('vitrinka: could not delete the capture store', e);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
|
|
2
|
-
export declare const RECORDER_VERSION = "0.
|
|
3
|
-
export declare const RECORDER_ID = "web/0.
|
|
2
|
+
export declare const RECORDER_VERSION = "0.7.0";
|
|
3
|
+
export declare const RECORDER_ID = "web/0.7.0";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineReportElement, mountReport as mount } from './element';
|
|
2
|
+
export { identify } from './identity';
|
|
3
|
+
/** The origin this module was served from — the deployment, by default. */
|
|
4
|
+
const SELF_ORIGIN = (() => {
|
|
5
|
+
try {
|
|
6
|
+
return new URL(import.meta.url).origin;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
})();
|
|
12
|
+
/** rrweb's `record` from the deployment's pinned recorder (a default export, or a `record` on it or the module). */
|
|
13
|
+
async function loadVendorRecord(base) {
|
|
14
|
+
// boundary: foreign untyped code — narrowed structurally below.
|
|
15
|
+
const m = await import(/* @vite-ignore */ `${base}/vendor/rrweb-record-1.min.js`);
|
|
16
|
+
const mod = (m ?? {});
|
|
17
|
+
const inner = typeof mod.default === 'object' && mod.default !== null ? mod.default.record : undefined;
|
|
18
|
+
const candidate = typeof mod.default === 'function' ? mod.default : (inner ?? mod.record);
|
|
19
|
+
return typeof candidate === 'function' ? candidate : null;
|
|
20
|
+
}
|
|
21
|
+
const faces = {
|
|
22
|
+
loadRecord: loadVendorRecord,
|
|
23
|
+
recorderFace: null,
|
|
24
|
+
defaultBase: () => SELF_ORIGIN,
|
|
25
|
+
};
|
|
26
|
+
defineReportElement(faces);
|
|
27
|
+
/** Mount Report a problem from script; `base` defaults to this module's origin. */
|
|
28
|
+
export function mountReport(opts) {
|
|
29
|
+
return mount(opts, faces);
|
|
30
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ways in, shared by the npm entry (`@vitrinka/web/report`) and the
|
|
3
|
+
* single-file widget (`build/report-widget.mjs`): the `<vitrinka-report>`
|
|
4
|
+
* custom element and `mountReport(opts)`, which creates one.
|
|
5
|
+
*
|
|
6
|
+
* <vitrinka-report key="vkb_…" base="https://vitrinka.example"
|
|
7
|
+
* locale="cs" button="false" open-selector="#help-report">
|
|
8
|
+
*
|
|
9
|
+
* The element is a configuration holder that renders nothing itself: the
|
|
10
|
+
* widget paints into the shared HUD host on `<html>` (top layer, shadow
|
|
11
|
+
* root). Attributes are live — `locale` repaints in place, `button` shows or
|
|
12
|
+
* hides the floating button, `open-selector` rebinds; a changed `key` or
|
|
13
|
+
* `base` remounts. The face is config (QA Studio D6): `face: 'recorder'`
|
|
14
|
+
* mounts the recorder pill instead (npm entry only — it needs React and a
|
|
15
|
+
* `vkr_` key or a device link).
|
|
16
|
+
*/
|
|
17
|
+
import type { RecordLoader } from './engine';
|
|
18
|
+
import { type Locale } from './i18n';
|
|
19
|
+
import type { IdentifyInput } from './identity';
|
|
20
|
+
import type { CaptureNarrowing } from './profile';
|
|
21
|
+
export declare const REPORT_TAG = "vitrinka-report";
|
|
22
|
+
export type ReportFace = 'report' | 'recorder';
|
|
23
|
+
/** Options a host passes in script, beyond what attributes carry. */
|
|
24
|
+
export interface ReportScriptOptions {
|
|
25
|
+
appVersion?: string;
|
|
26
|
+
/** Narrow the project's capture profile (never widen it). */
|
|
27
|
+
capture?: CaptureNarrowing;
|
|
28
|
+
/** Rewrite captured URLs and routes before redaction (credentials in paths). */
|
|
29
|
+
sanitizeUrl?: (url: string) => string;
|
|
30
|
+
}
|
|
31
|
+
export interface ReportOptions extends ReportScriptOptions {
|
|
32
|
+
/** The project's `vkb_` report key (`face: 'recorder'`: a `vkr_` key, or none for the device link). */
|
|
33
|
+
key: string;
|
|
34
|
+
/** vitrinka's origin; the single-file widget defaults to the origin it was served from. */
|
|
35
|
+
base?: string;
|
|
36
|
+
/** Default `report`. */
|
|
37
|
+
face?: ReportFace;
|
|
38
|
+
/** `cs` | `en`; default: the browser's language. */
|
|
39
|
+
locale?: Locale | string;
|
|
40
|
+
/** The large floating button (default true); false = open it from your own control. */
|
|
41
|
+
button?: boolean;
|
|
42
|
+
/** Your control(s) that open the card, as a CSS selector. */
|
|
43
|
+
openSelector?: string;
|
|
44
|
+
/** Who reports: a token your server signed, or an asserted email. */
|
|
45
|
+
identity?: IdentifyInput;
|
|
46
|
+
/** Where the element goes (default `document.body`). */
|
|
47
|
+
parent?: Element;
|
|
48
|
+
}
|
|
49
|
+
export interface ReportHandle {
|
|
50
|
+
readonly face: ReportFace;
|
|
51
|
+
open(): void;
|
|
52
|
+
close(): void;
|
|
53
|
+
identify(who: IdentifyInput): void;
|
|
54
|
+
setLocale(locale: Locale | string): void;
|
|
55
|
+
unmount(): void;
|
|
56
|
+
}
|
|
57
|
+
/** `<vitrinka-report>` as script sees it. */
|
|
58
|
+
export interface VitrinkaReportElement extends HTMLElement {
|
|
59
|
+
/** Set before the element connects (mountReport does). */
|
|
60
|
+
options: ReportScriptOptions;
|
|
61
|
+
open(): void;
|
|
62
|
+
close(): void;
|
|
63
|
+
identify(who: IdentifyInput): void;
|
|
64
|
+
setLocale(locale: Locale | string): void;
|
|
65
|
+
}
|
|
66
|
+
declare global {
|
|
67
|
+
interface HTMLElementTagNameMap {
|
|
68
|
+
'vitrinka-report': VitrinkaReportElement;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export interface RecorderFaceOptions {
|
|
72
|
+
base: string;
|
|
73
|
+
key: string;
|
|
74
|
+
appVersion?: string;
|
|
75
|
+
sanitizeUrl?: (url: string) => string;
|
|
76
|
+
}
|
|
77
|
+
/** What each build brings: how rrweb loads, the recorder face (npm only), the default base. */
|
|
78
|
+
export interface Faces {
|
|
79
|
+
loadRecord: RecordLoader;
|
|
80
|
+
recorderFace: (() => Promise<(opts: RecorderFaceOptions) => () => void>) | null;
|
|
81
|
+
defaultBase: () => string;
|
|
82
|
+
}
|
|
83
|
+
/** Define `<vitrinka-report>` once per page (the first build to load wins). */
|
|
84
|
+
export declare function defineReportElement(faces: Faces): void;
|
|
85
|
+
/** Mount Report a problem (or, with `face: 'recorder'`, the recorder pill) and get its handle. */
|
|
86
|
+
export declare function mountReport(opts: ReportOptions, faces: Faces): ReportHandle;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { parseLocale } from './i18n';
|
|
2
|
+
import { ReportWidget } from './widget';
|
|
3
|
+
export const REPORT_TAG = 'vitrinka-report';
|
|
4
|
+
const ATTRS = ['key', 'base', 'open-selector', 'locale', 'button'];
|
|
5
|
+
function trimBase(raw) {
|
|
6
|
+
return raw.trim().replace(/\/+$/, '');
|
|
7
|
+
}
|
|
8
|
+
/** Define `<vitrinka-report>` once per page (the first build to load wins). */
|
|
9
|
+
export function defineReportElement(faces) {
|
|
10
|
+
if (typeof customElements === 'undefined' || customElements.get(REPORT_TAG))
|
|
11
|
+
return;
|
|
12
|
+
class ReportElement extends HTMLElement {
|
|
13
|
+
static get observedAttributes() {
|
|
14
|
+
return ATTRS;
|
|
15
|
+
}
|
|
16
|
+
options = {};
|
|
17
|
+
widget = null;
|
|
18
|
+
pendingIdentity = undefined;
|
|
19
|
+
connectedCallback() {
|
|
20
|
+
this.hidden = true;
|
|
21
|
+
this.mountWidget();
|
|
22
|
+
}
|
|
23
|
+
disconnectedCallback() {
|
|
24
|
+
this.widget?.unmount();
|
|
25
|
+
this.widget = null;
|
|
26
|
+
}
|
|
27
|
+
attributeChangedCallback(name, old, value) {
|
|
28
|
+
if (old === value)
|
|
29
|
+
return;
|
|
30
|
+
if (!this.widget) {
|
|
31
|
+
// Connected but waiting for its key or base (a host that configures later): mount now.
|
|
32
|
+
if (this.isConnected && (name === 'key' || name === 'base'))
|
|
33
|
+
this.mountWidget();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (name === 'locale')
|
|
37
|
+
this.widget.setLocale(value);
|
|
38
|
+
else if (name === 'button')
|
|
39
|
+
this.widget.setButton(value !== 'false');
|
|
40
|
+
else if (name === 'open-selector')
|
|
41
|
+
this.widget.setOpenSelector(value);
|
|
42
|
+
else {
|
|
43
|
+
this.widget.unmount();
|
|
44
|
+
this.widget = null;
|
|
45
|
+
this.mountWidget();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
open() {
|
|
49
|
+
this.widget?.open();
|
|
50
|
+
}
|
|
51
|
+
close() {
|
|
52
|
+
this.widget?.close();
|
|
53
|
+
}
|
|
54
|
+
identify(who) {
|
|
55
|
+
this.pendingIdentity = who;
|
|
56
|
+
this.widget?.identify(who);
|
|
57
|
+
}
|
|
58
|
+
setLocale(locale) {
|
|
59
|
+
// The attribute is the one source: it repaints through attributeChangedCallback.
|
|
60
|
+
this.setAttribute('locale', String(locale));
|
|
61
|
+
}
|
|
62
|
+
/** Idempotent: an upgrade runs attributeChangedCallback before connectedCallback, and both land here. */
|
|
63
|
+
mountWidget() {
|
|
64
|
+
if (this.widget)
|
|
65
|
+
return;
|
|
66
|
+
const key = (this.getAttribute('key') ?? '').trim();
|
|
67
|
+
const base = trimBase(this.getAttribute('base') ?? faces.defaultBase());
|
|
68
|
+
if (!key || !base) {
|
|
69
|
+
console.warn(`vitrinka: <${REPORT_TAG}> needs a key${base ? '' : ' and a base'} — nothing mounted`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.widget = new ReportWidget({
|
|
73
|
+
base,
|
|
74
|
+
key,
|
|
75
|
+
locale: parseLocale(this.getAttribute('locale')),
|
|
76
|
+
button: this.getAttribute('button') !== 'false',
|
|
77
|
+
openSelector: this.getAttribute('open-selector'),
|
|
78
|
+
identity: this.pendingIdentity,
|
|
79
|
+
appVersion: this.options.appVersion,
|
|
80
|
+
capture: this.options.capture,
|
|
81
|
+
sanitizeUrl: this.options.sanitizeUrl,
|
|
82
|
+
loadRecord: faces.loadRecord,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
customElements.define(REPORT_TAG, ReportElement);
|
|
87
|
+
}
|
|
88
|
+
/** Mount Report a problem (or, with `face: 'recorder'`, the recorder pill) and get its handle. */
|
|
89
|
+
export function mountReport(opts, faces) {
|
|
90
|
+
if (opts.face === 'recorder')
|
|
91
|
+
return mountRecorder(opts, faces);
|
|
92
|
+
defineReportElement(faces);
|
|
93
|
+
const el = document.createElement(REPORT_TAG);
|
|
94
|
+
el.setAttribute('key', opts.key);
|
|
95
|
+
if (opts.base)
|
|
96
|
+
el.setAttribute('base', opts.base);
|
|
97
|
+
if (opts.locale)
|
|
98
|
+
el.setAttribute('locale', String(opts.locale));
|
|
99
|
+
if (opts.button === false)
|
|
100
|
+
el.setAttribute('button', 'false');
|
|
101
|
+
if (opts.openSelector)
|
|
102
|
+
el.setAttribute('open-selector', opts.openSelector);
|
|
103
|
+
el.options = { appVersion: opts.appVersion, capture: opts.capture, sanitizeUrl: opts.sanitizeUrl };
|
|
104
|
+
// null is a choice (anonymous, whatever the page-wide identity); only undefined defers.
|
|
105
|
+
if (opts.identity !== undefined)
|
|
106
|
+
el.identify(opts.identity);
|
|
107
|
+
(opts.parent ?? document.body).append(el);
|
|
108
|
+
return {
|
|
109
|
+
face: 'report',
|
|
110
|
+
open: () => el.open(),
|
|
111
|
+
close: () => el.close(),
|
|
112
|
+
identify: (who) => el.identify(who),
|
|
113
|
+
setLocale: (l) => el.setLocale(l),
|
|
114
|
+
unmount: () => el.remove(),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function mountRecorder(opts, faces) {
|
|
118
|
+
const base = trimBase(opts.base ?? faces.defaultBase());
|
|
119
|
+
let unmount = null;
|
|
120
|
+
let gone = false;
|
|
121
|
+
if (!faces.recorderFace) {
|
|
122
|
+
console.warn('vitrinka: the recorder face needs the npm package (@vitrinka/web/report) — nothing mounted');
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
faces
|
|
126
|
+
.recorderFace()
|
|
127
|
+
.then((mount) => {
|
|
128
|
+
if (!gone)
|
|
129
|
+
unmount = mount({ base, key: opts.key, appVersion: opts.appVersion, sanitizeUrl: opts.sanitizeUrl });
|
|
130
|
+
})
|
|
131
|
+
.catch((e) => console.warn('vitrinka: the recorder face did not load', e));
|
|
132
|
+
}
|
|
133
|
+
// The pill is always on screen and English-only, and speaks for the device link: no card to open.
|
|
134
|
+
const inert = () => undefined;
|
|
135
|
+
return {
|
|
136
|
+
face: 'recorder',
|
|
137
|
+
open: inert,
|
|
138
|
+
close: inert,
|
|
139
|
+
identify: inert,
|
|
140
|
+
setLocale: inert,
|
|
141
|
+
unmount: () => {
|
|
142
|
+
gone = true;
|
|
143
|
+
unmount?.();
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The report face's capture runtime — the shared engine (QA Studio D6)
|
|
3
|
+
* driven by the project's capture profile instead of a recording:
|
|
4
|
+
*
|
|
5
|
+
* 1. `GET /api/v1/report-config` with the `vkb_` key → the capture profile
|
|
6
|
+
* (narrowed by the host's `capture` option) and the masking profile. An
|
|
7
|
+
* unreachable or older server means the safe fallback: memory, the last
|
|
8
|
+
* minute, strict masking.
|
|
9
|
+
* 2. The redaction rules first, then the lanes — so capture runs under the
|
|
10
|
+
* project's rules from its first byte: the console lane (errors, every
|
|
11
|
+
* level with `console`), the network lane in metadata-only mode
|
|
12
|
+
* (`errors`: failures, `network`: every request), and the rrweb lane
|
|
13
|
+
* into the flight buffer (`interactions`).
|
|
14
|
+
* 3. The flight buffer under the profile's window and cap, in memory or
|
|
15
|
+
* also in IndexedDB (`storage: browser`, storage/capture.ts), whose
|
|
16
|
+
* expired windows the start sweeps.
|
|
17
|
+
*
|
|
18
|
+
* One engine per page however many widgets mount (the lanes and the buffer
|
|
19
|
+
* are page-wide); the last widget to leave stops it. The runtime is the
|
|
20
|
+
* recorder face's whenever one is mounted (state.ts `claimCapture`): then
|
|
21
|
+
* the engine captures nothing, and it never writes the recorder's
|
|
22
|
+
* configuration — every call it makes names its own target.
|
|
23
|
+
*/
|
|
24
|
+
import type { eventWithTime } from '@rrweb/types';
|
|
25
|
+
import { type RecordFn } from '../recorder/capture/rrweb-lane';
|
|
26
|
+
import { type FlightClip, type FlightLaneEvent } from '../recorder/flight';
|
|
27
|
+
import { EVENTS_PER_POST } from '../recorder/queue';
|
|
28
|
+
import { type Marker } from './markers';
|
|
29
|
+
import { type CaptureLanes, type CaptureNarrowing, type CaptureProfile, type MaskingProfile } from './profile';
|
|
30
|
+
export { EVENTS_PER_POST };
|
|
31
|
+
/** Loads rrweb's `record` lazily: `import('rrweb')` from npm, vitrinka's `/vendor` in the single-file widget. */
|
|
32
|
+
export type RecordLoader = (base: string) => Promise<RecordFn | null>;
|
|
33
|
+
export interface EngineOptions {
|
|
34
|
+
/** vitrinka's origin, no trailing slash. */
|
|
35
|
+
base: string;
|
|
36
|
+
/** The project's `vkb_` report key. */
|
|
37
|
+
key: string;
|
|
38
|
+
appVersion?: string;
|
|
39
|
+
sanitizeUrl?: (url: string) => string;
|
|
40
|
+
capture?: CaptureNarrowing;
|
|
41
|
+
loadRecord: RecordLoader;
|
|
42
|
+
}
|
|
43
|
+
export interface ReportConfig {
|
|
44
|
+
project: string;
|
|
45
|
+
/** The profile in force (the project's, narrowed by the host). */
|
|
46
|
+
profile: CaptureProfile;
|
|
47
|
+
lanes: CaptureLanes;
|
|
48
|
+
masking: MaskingProfile;
|
|
49
|
+
/** False when the config read failed: the fallback profile runs. */
|
|
50
|
+
reachable: boolean;
|
|
51
|
+
/** This widget captures (false while the recorder face runs the page's capture). */
|
|
52
|
+
capturing: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ConsoleEntry {
|
|
55
|
+
level: string;
|
|
56
|
+
ts: string;
|
|
57
|
+
text: string;
|
|
58
|
+
}
|
|
59
|
+
export interface NetEntry {
|
|
60
|
+
method: string;
|
|
61
|
+
path: string;
|
|
62
|
+
status: number;
|
|
63
|
+
ms: number;
|
|
64
|
+
}
|
|
65
|
+
/** The capture as frozen when the card opened (the buffer keeps rolling). */
|
|
66
|
+
export interface Frozen {
|
|
67
|
+
clip: FlightClip | null;
|
|
68
|
+
/** Earlier loads' windows of the clip, read when it froze (the buffer may expire them before Send). */
|
|
69
|
+
stored: Promise<Map<string, {
|
|
70
|
+
events: eventWithTime[];
|
|
71
|
+
lanes: FlightLaneEvent[];
|
|
72
|
+
}>>;
|
|
73
|
+
}
|
|
74
|
+
export interface CaptureChunk {
|
|
75
|
+
/** 1..n: the chunk's leaf seq and its `rrweb` row's seq. */
|
|
76
|
+
seq: number;
|
|
77
|
+
/** Its last event's time. */
|
|
78
|
+
ts: string;
|
|
79
|
+
count: number;
|
|
80
|
+
body: string;
|
|
81
|
+
}
|
|
82
|
+
/** What one report sends of the capture. */
|
|
83
|
+
export interface BuiltCapture {
|
|
84
|
+
chunks: CaptureChunk[];
|
|
85
|
+
truncated: boolean;
|
|
86
|
+
console: ConsoleEntry[];
|
|
87
|
+
network: NetEntry[];
|
|
88
|
+
}
|
|
89
|
+
/** A request URL (already through the redaction engine) as the wire's path: pathname only, token runs scrubbed. */
|
|
90
|
+
export declare function reportPath(url: unknown): string;
|
|
91
|
+
/**
|
|
92
|
+
* Whole windows only: rrweb's stream is stateful, so a window holding an
|
|
93
|
+
* event over the wire cap (a huge full snapshot) goes entirely — its
|
|
94
|
+
* incrementals are worthless without it — and the replay says truncated.
|
|
95
|
+
*/
|
|
96
|
+
export declare function wholeWindows(events: readonly eventWithTime[], hardBytes: number): {
|
|
97
|
+
events: eventWithTime[];
|
|
98
|
+
dropped: boolean;
|
|
99
|
+
};
|
|
100
|
+
export declare class CaptureEngine {
|
|
101
|
+
readonly opts: EngineOptions;
|
|
102
|
+
readonly ready: Promise<ReportConfig>;
|
|
103
|
+
private store;
|
|
104
|
+
private stopped;
|
|
105
|
+
/** The release token of this engine's claim on the page's capture runtime. */
|
|
106
|
+
private claim;
|
|
107
|
+
/** The config `ready` resolved with — kept true to what the engine does now. */
|
|
108
|
+
private config;
|
|
109
|
+
private readonly listeners;
|
|
110
|
+
/** …and runs it now: false before the claim, without it, and after it yielded. */
|
|
111
|
+
private capturing;
|
|
112
|
+
/** The engine's own lifetime (its base registration). */
|
|
113
|
+
private readonly offs;
|
|
114
|
+
/** The capture runtime's teardown, run when it yields to a recorder or stops. */
|
|
115
|
+
private readonly capture;
|
|
116
|
+
constructor(opts: EngineOptions);
|
|
117
|
+
private start;
|
|
118
|
+
/** Hear the engine's state change (it stopped capturing): the widget repaints. */
|
|
119
|
+
onChange(fn: () => void): () => void;
|
|
120
|
+
/** The recorder mounted: hand it the runtime — this widget goes on reporting without a capture. */
|
|
121
|
+
private standDown;
|
|
122
|
+
/** Freeze the capture now (the card opened); the buffer rolls on. */
|
|
123
|
+
freeze(): Frozen;
|
|
124
|
+
/**
|
|
125
|
+
* The rrweb ids of the page nodes under a hide right now — taken when the
|
|
126
|
+
* hide is drawn (the page sits frozen under the marking layer); null when
|
|
127
|
+
* the running recorder has no mirror to say (then a hide withholds the replay).
|
|
128
|
+
*/
|
|
129
|
+
hiddenIdsAt(rect: Marker['rect']): Set<number> | null;
|
|
130
|
+
/**
|
|
131
|
+
* What one report sends: the frozen windows (stored ones read back), the
|
|
132
|
+
* hides applied, split under the chunk cap. `markedIds` are the nodes each
|
|
133
|
+
* hide covered when it was drawn; the nodes under it at send join them. A
|
|
134
|
+
* hide whose nodes cannot be named (no mirror) withholds the replay — fail
|
|
135
|
+
* closed, never a box over text that still rides along.
|
|
136
|
+
*/
|
|
137
|
+
build(frozen: Frozen, markers: readonly Marker[], markedIds?: ReadonlySet<number>): Promise<BuiltCapture>;
|
|
138
|
+
/** A report went out: forget what it carried, in memory and in the store. */
|
|
139
|
+
clear(): void;
|
|
140
|
+
stop(): void;
|
|
141
|
+
}
|
|
142
|
+
/** The page's one engine (started by the first widget); null when another base/key already owns it. */
|
|
143
|
+
export declare function acquireEngine(opts: EngineOptions): CaptureEngine | null;
|
|
144
|
+
export declare function releaseEngine(engine: CaptureEngine | null): void;
|