@v-tilt/browser 1.1.5 → 1.3.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/dist/all-external-dependencies.js +2 -0
- package/dist/all-external-dependencies.js.map +1 -0
- package/dist/array.full.js +2 -0
- package/dist/array.full.js.map +1 -0
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/entrypoints/all-external-dependencies.d.ts +8 -0
- package/dist/entrypoints/array.d.ts +1 -0
- package/dist/entrypoints/array.full.d.ts +17 -0
- package/dist/entrypoints/external-scripts-loader.d.ts +24 -0
- package/dist/entrypoints/module.es.d.ts +1 -0
- package/dist/entrypoints/recorder.d.ts +23 -0
- package/dist/entrypoints/web-vitals.d.ts +14 -0
- package/dist/extensions/replay/index.d.ts +13 -0
- package/dist/extensions/replay/session-recording-utils.d.ts +92 -0
- package/dist/extensions/replay/session-recording-wrapper.d.ts +61 -0
- package/dist/extensions/replay/session-recording.d.ts +95 -0
- package/dist/extensions/replay/types.d.ts +211 -0
- package/dist/external-scripts-loader.js +2 -0
- package/dist/external-scripts-loader.js.map +1 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +297 -8
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +297 -8
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/recorder.js +2 -0
- package/dist/recorder.js.map +1 -0
- package/dist/types.d.ts +116 -6
- package/dist/utils/globals.d.ts +69 -0
- package/dist/vtilt.d.ts +36 -0
- package/dist/web-vitals.d.ts +89 -5
- package/dist/web-vitals.js +2 -0
- package/dist/web-vitals.js.map +1 -0
- package/lib/config.js +7 -3
- package/lib/entrypoints/all-external-dependencies.d.ts +8 -0
- package/lib/entrypoints/all-external-dependencies.js +10 -0
- package/lib/entrypoints/array.d.ts +1 -0
- package/lib/entrypoints/array.full.d.ts +17 -0
- package/lib/entrypoints/array.full.js +19 -0
- package/lib/entrypoints/array.js +1 -0
- package/lib/entrypoints/external-scripts-loader.d.ts +24 -0
- package/lib/entrypoints/external-scripts-loader.js +107 -0
- package/lib/entrypoints/module.es.d.ts +1 -0
- package/lib/entrypoints/module.es.js +1 -0
- package/lib/entrypoints/recorder.d.ts +23 -0
- package/lib/entrypoints/recorder.js +42 -0
- package/lib/entrypoints/web-vitals.d.ts +14 -0
- package/lib/entrypoints/web-vitals.js +29 -0
- package/lib/extensions/replay/index.d.ts +13 -0
- package/lib/extensions/replay/index.js +31 -0
- package/lib/extensions/replay/session-recording-utils.d.ts +92 -0
- package/lib/extensions/replay/session-recording-utils.js +212 -0
- package/lib/extensions/replay/session-recording-wrapper.d.ts +61 -0
- package/lib/extensions/replay/session-recording-wrapper.js +149 -0
- package/lib/extensions/replay/session-recording.d.ts +95 -0
- package/lib/extensions/replay/session-recording.js +700 -0
- package/lib/extensions/replay/types.d.ts +211 -0
- package/lib/extensions/replay/types.js +8 -0
- package/lib/types.d.ts +116 -6
- package/lib/types.js +16 -0
- package/lib/utils/globals.d.ts +69 -0
- package/lib/utils/globals.js +2 -0
- package/lib/vtilt.d.ts +36 -0
- package/lib/vtilt.js +106 -0
- package/lib/web-vitals.d.ts +89 -5
- package/lib/web-vitals.js +354 -46
- package/package.json +4 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Session Recording Wrapper
|
|
4
|
+
*
|
|
5
|
+
* Lightweight wrapper that handles the decision of WHEN to load recording.
|
|
6
|
+
* The actual recording logic is in LazyLoadedSessionRecording which is
|
|
7
|
+
* loaded on demand.
|
|
8
|
+
*
|
|
9
|
+
* Based on PostHog's sessionrecording-wrapper.ts
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SessionRecordingWrapper = exports.LAZY_LOADING = void 0;
|
|
13
|
+
const globals_1 = require("../../utils/globals");
|
|
14
|
+
const LOGGER_PREFIX = "[SessionRecording]";
|
|
15
|
+
/** Status when lazy loading is in progress */
|
|
16
|
+
exports.LAZY_LOADING = "lazy_loading";
|
|
17
|
+
/**
|
|
18
|
+
* Session Recording Wrapper
|
|
19
|
+
*
|
|
20
|
+
* This is the lightweight class that lives in the main bundle.
|
|
21
|
+
* It handles:
|
|
22
|
+
* - Deciding if recording should be enabled
|
|
23
|
+
* - Lazy loading the actual recording code
|
|
24
|
+
* - Delegating to LazyLoadedSessionRecording
|
|
25
|
+
*/
|
|
26
|
+
class SessionRecordingWrapper {
|
|
27
|
+
constructor(_instance, config = {}) {
|
|
28
|
+
this._instance = _instance;
|
|
29
|
+
this._config = config;
|
|
30
|
+
}
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// Public API
|
|
33
|
+
// ============================================================================
|
|
34
|
+
get started() {
|
|
35
|
+
var _a;
|
|
36
|
+
return !!((_a = this._lazyLoadedRecording) === null || _a === void 0 ? void 0 : _a.isStarted);
|
|
37
|
+
}
|
|
38
|
+
get status() {
|
|
39
|
+
var _a;
|
|
40
|
+
return (((_a = this._lazyLoadedRecording) === null || _a === void 0 ? void 0 : _a.status) ||
|
|
41
|
+
exports.LAZY_LOADING);
|
|
42
|
+
}
|
|
43
|
+
get sessionId() {
|
|
44
|
+
var _a;
|
|
45
|
+
return ((_a = this._lazyLoadedRecording) === null || _a === void 0 ? void 0 : _a.sessionId) || "";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Start recording if enabled, otherwise stop
|
|
49
|
+
*/
|
|
50
|
+
startIfEnabledOrStop(startReason) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (this._isRecordingEnabled && ((_a = this._lazyLoadedRecording) === null || _a === void 0 ? void 0 : _a.isStarted)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Check browser compatibility
|
|
56
|
+
const canRunReplay = typeof Object.assign !== "undefined" && typeof Array.from !== "undefined";
|
|
57
|
+
if (this._isRecordingEnabled && canRunReplay) {
|
|
58
|
+
this._lazyLoadAndStart(startReason);
|
|
59
|
+
console.info(`${LOGGER_PREFIX} starting`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.stopRecording();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Stop recording
|
|
67
|
+
*/
|
|
68
|
+
stopRecording() {
|
|
69
|
+
var _a;
|
|
70
|
+
(_a = this._lazyLoadedRecording) === null || _a === void 0 ? void 0 : _a.stop();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Log a message to the recording
|
|
74
|
+
*/
|
|
75
|
+
log(message, level = "log") {
|
|
76
|
+
var _a;
|
|
77
|
+
if ((_a = this._lazyLoadedRecording) === null || _a === void 0 ? void 0 : _a.log) {
|
|
78
|
+
this._lazyLoadedRecording.log(message, level);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.warn(`${LOGGER_PREFIX} log called before recorder was ready`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Update configuration
|
|
86
|
+
*/
|
|
87
|
+
updateConfig(config) {
|
|
88
|
+
var _a;
|
|
89
|
+
this._config = { ...this._config, ...config };
|
|
90
|
+
(_a = this._lazyLoadedRecording) === null || _a === void 0 ? void 0 : _a.updateConfig(this._config);
|
|
91
|
+
}
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// Private Methods
|
|
94
|
+
// ============================================================================
|
|
95
|
+
get _isRecordingEnabled() {
|
|
96
|
+
var _a;
|
|
97
|
+
const config = this._instance.getConfig();
|
|
98
|
+
const enabled = (_a = this._config.enabled) !== null && _a !== void 0 ? _a : false;
|
|
99
|
+
const notDisabled = !config.disable_session_recording;
|
|
100
|
+
return !!globals_1.window && enabled && notDisabled;
|
|
101
|
+
}
|
|
102
|
+
get _scriptName() {
|
|
103
|
+
return "recorder";
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Lazy load the recording script and start
|
|
107
|
+
*/
|
|
108
|
+
_lazyLoadAndStart(startReason) {
|
|
109
|
+
var _a, _b, _c, _d;
|
|
110
|
+
if (!this._isRecordingEnabled) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Check if already loaded
|
|
114
|
+
if (((_b = (_a = globals_1.assignableWindow === null || globals_1.assignableWindow === void 0 ? void 0 : globals_1.assignableWindow.__VTiltExtensions__) === null || _a === void 0 ? void 0 : _a.rrweb) === null || _b === void 0 ? void 0 : _b.record) &&
|
|
115
|
+
((_c = globals_1.assignableWindow.__VTiltExtensions__) === null || _c === void 0 ? void 0 : _c.initSessionRecording)) {
|
|
116
|
+
this._onScriptLoaded(startReason);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// Load the recorder script
|
|
120
|
+
const loadExternalDependency = (_d = globals_1.assignableWindow.__VTiltExtensions__) === null || _d === void 0 ? void 0 : _d.loadExternalDependency;
|
|
121
|
+
if (!loadExternalDependency) {
|
|
122
|
+
console.error(`${LOGGER_PREFIX} loadExternalDependency not available. Session recording cannot start.`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
loadExternalDependency(this._instance, this._scriptName, (err) => {
|
|
126
|
+
if (err) {
|
|
127
|
+
console.error(`${LOGGER_PREFIX} could not load recorder:`, err);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this._onScriptLoaded(startReason);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Called after the recording script is loaded
|
|
135
|
+
*/
|
|
136
|
+
_onScriptLoaded(startReason) {
|
|
137
|
+
var _a;
|
|
138
|
+
const initSessionRecording = (_a = globals_1.assignableWindow.__VTiltExtensions__) === null || _a === void 0 ? void 0 : _a.initSessionRecording;
|
|
139
|
+
if (!initSessionRecording) {
|
|
140
|
+
console.error(`${LOGGER_PREFIX} initSessionRecording not available after script load`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!this._lazyLoadedRecording) {
|
|
144
|
+
this._lazyLoadedRecording = initSessionRecording(this._instance, this._config);
|
|
145
|
+
}
|
|
146
|
+
this._lazyLoadedRecording.start(startReason);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.SessionRecordingWrapper = SessionRecordingWrapper;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy Loaded Session Recording
|
|
3
|
+
*
|
|
4
|
+
* The actual rrweb session recording implementation.
|
|
5
|
+
* This is loaded on demand when recording is enabled.
|
|
6
|
+
*
|
|
7
|
+
* Based on PostHog's lazy-loaded-session-recorder.ts
|
|
8
|
+
*/
|
|
9
|
+
import { type eventWithTime } from "@rrweb/types";
|
|
10
|
+
import type { VTilt } from "../../vtilt";
|
|
11
|
+
import { LazyLoadedSessionRecordingInterface } from "../../utils/globals";
|
|
12
|
+
import type { SessionRecordingConfig, SessionRecordingStatus } from "./types";
|
|
13
|
+
export declare const SESSION_RECORDING_BATCH_KEY = "recordings";
|
|
14
|
+
export declare class LazyLoadedSessionRecording implements LazyLoadedSessionRecordingInterface {
|
|
15
|
+
private _instance;
|
|
16
|
+
private _endpoint;
|
|
17
|
+
private _flushBufferTimer?;
|
|
18
|
+
private _fullSnapshotTimer?;
|
|
19
|
+
private _captureStarted;
|
|
20
|
+
private _stopRrweb?;
|
|
21
|
+
private _isIdle;
|
|
22
|
+
private _lastActivityTimestamp;
|
|
23
|
+
private _lastHref?;
|
|
24
|
+
private _sessionId;
|
|
25
|
+
private _windowId;
|
|
26
|
+
private _buffer;
|
|
27
|
+
private _queuedRRWebEvents;
|
|
28
|
+
private _config;
|
|
29
|
+
constructor(instance: VTilt, config?: SessionRecordingConfig);
|
|
30
|
+
get isStarted(): boolean;
|
|
31
|
+
/** @deprecated Use isStarted instead */
|
|
32
|
+
get started(): boolean;
|
|
33
|
+
get sessionId(): string;
|
|
34
|
+
get status(): SessionRecordingStatus;
|
|
35
|
+
/**
|
|
36
|
+
* Start session recording (interface method)
|
|
37
|
+
*/
|
|
38
|
+
start(startReason?: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Stop session recording (interface method)
|
|
41
|
+
*/
|
|
42
|
+
stop(): void;
|
|
43
|
+
/** @deprecated Use stop() instead */
|
|
44
|
+
stopRecording(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Add a custom event to the recording
|
|
47
|
+
*/
|
|
48
|
+
addCustomEvent(tag: string, payload: unknown): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Take a full snapshot
|
|
51
|
+
*/
|
|
52
|
+
takeFullSnapshot(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Log a message to the recording
|
|
55
|
+
*/
|
|
56
|
+
log(message: string, level?: "log" | "warn" | "error"): void;
|
|
57
|
+
/**
|
|
58
|
+
* Update configuration
|
|
59
|
+
*/
|
|
60
|
+
updateConfig(config: Partial<SessionRecordingConfig>): void;
|
|
61
|
+
private _onBeforeUnload;
|
|
62
|
+
private _onOffline;
|
|
63
|
+
private _onOnline;
|
|
64
|
+
private _onVisibilityChange;
|
|
65
|
+
private _isRecordingEnabled;
|
|
66
|
+
private _startCapture;
|
|
67
|
+
private _loadRecorder;
|
|
68
|
+
private _onScriptLoaded;
|
|
69
|
+
private _gatherRRWebPlugins;
|
|
70
|
+
onRRwebEmit(rawEvent: eventWithTime): void;
|
|
71
|
+
private _processQueuedEvents;
|
|
72
|
+
private _updateWindowAndSessionIds;
|
|
73
|
+
private _clearBuffer;
|
|
74
|
+
private _flushBuffer;
|
|
75
|
+
private _captureSnapshotBuffered;
|
|
76
|
+
private _captureSnapshot;
|
|
77
|
+
private _sendSnapshot;
|
|
78
|
+
/**
|
|
79
|
+
* Fetch with exponential backoff retry (PostHog-style)
|
|
80
|
+
* Retries on network errors and 5xx server errors
|
|
81
|
+
*/
|
|
82
|
+
private _fetchWithRetry;
|
|
83
|
+
/**
|
|
84
|
+
* Schedule a retry with exponential backoff and jitter
|
|
85
|
+
*/
|
|
86
|
+
private _scheduleRetry;
|
|
87
|
+
private _scheduleFullSnapshot;
|
|
88
|
+
private _tryRRWebMethod;
|
|
89
|
+
private _tryAddCustomEvent;
|
|
90
|
+
private _tryTakeFullSnapshot;
|
|
91
|
+
private _getCanvasConfig;
|
|
92
|
+
private _getMaskingConfig;
|
|
93
|
+
private _generateId;
|
|
94
|
+
private _reportStarted;
|
|
95
|
+
}
|