@zaplier/sdk 1.3.3 → 1.3.5
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/index.cjs +87 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +87 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +87 -9
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/modules/session-replay.d.ts +2 -0
- package/dist/src/modules/session-replay.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -19006,6 +19006,7 @@ var n;
|
|
|
19006
19006
|
!function(t2) {
|
|
19007
19007
|
t2[t2.NotStarted = 0] = "NotStarted", t2[t2.Running = 1] = "Running", t2[t2.Stopped = 2] = "Stopped";
|
|
19008
19008
|
}(n || (n = {}));
|
|
19009
|
+
const { takeFullSnapshot } = record;
|
|
19009
19010
|
|
|
19010
19011
|
/**
|
|
19011
19012
|
* Session Replay Engine
|
|
@@ -19016,6 +19017,7 @@ class SessionReplayEngine {
|
|
|
19016
19017
|
this.events = [];
|
|
19017
19018
|
this.isActive = false;
|
|
19018
19019
|
this.hasFullSnapshot = false;
|
|
19020
|
+
this.startTime = 0;
|
|
19019
19021
|
this.sessionId = sessionId;
|
|
19020
19022
|
this.config = {
|
|
19021
19023
|
enabled: true,
|
|
@@ -19060,7 +19062,41 @@ class SessionReplayEngine {
|
|
|
19060
19062
|
});
|
|
19061
19063
|
this.isActive = true;
|
|
19062
19064
|
this.hasFullSnapshot = false;
|
|
19065
|
+
this.startTime = Date.now();
|
|
19063
19066
|
this.startBatchTimer();
|
|
19067
|
+
// WORKAROUND: Force FullSnapshot creation to fix rrweb 2.0.0-alpha bug
|
|
19068
|
+
// where FullSnapshot is sometimes not created as the first event
|
|
19069
|
+
setTimeout(() => {
|
|
19070
|
+
if (!this.hasFullSnapshot) {
|
|
19071
|
+
console.warn("[Zaplier] ⚠️ FullSnapshot not created automatically, forcing manual capture...");
|
|
19072
|
+
try {
|
|
19073
|
+
takeFullSnapshot(true); // Force a new FullSnapshot
|
|
19074
|
+
}
|
|
19075
|
+
catch (error) {
|
|
19076
|
+
console.error("[Zaplier] Failed to force FullSnapshot:", error);
|
|
19077
|
+
}
|
|
19078
|
+
}
|
|
19079
|
+
}, 500); // Give rrweb a chance to create natural FullSnapshot first
|
|
19080
|
+
// Set timeout to check if FullSnapshot was captured
|
|
19081
|
+
this.snapshotTimeout = window.setTimeout(() => {
|
|
19082
|
+
if (!this.hasFullSnapshot) {
|
|
19083
|
+
console.error("[Zaplier] CRITICAL: FullSnapshot not captured after 5 seconds!", {
|
|
19084
|
+
eventsReceived: this.events.length,
|
|
19085
|
+
eventTypes: this.events.map((e) => e.type).slice(0, 10),
|
|
19086
|
+
});
|
|
19087
|
+
// Try one more forced snapshot as last resort
|
|
19088
|
+
try {
|
|
19089
|
+
console.warn("[Zaplier] Last resort: forcing FullSnapshot...");
|
|
19090
|
+
takeFullSnapshot(true);
|
|
19091
|
+
}
|
|
19092
|
+
catch (error) {
|
|
19093
|
+
console.error("[Zaplier] Failed to create emergency FullSnapshot:", error);
|
|
19094
|
+
}
|
|
19095
|
+
}
|
|
19096
|
+
else {
|
|
19097
|
+
console.log("[Zaplier] ✅ FullSnapshot confirmed captured");
|
|
19098
|
+
}
|
|
19099
|
+
}, 5000);
|
|
19064
19100
|
console.log("[Zaplier] Session replay started with rrweb");
|
|
19065
19101
|
return true;
|
|
19066
19102
|
}
|
|
@@ -19085,6 +19121,10 @@ class SessionReplayEngine {
|
|
|
19085
19121
|
clearInterval(this.batchTimer);
|
|
19086
19122
|
this.batchTimer = undefined;
|
|
19087
19123
|
}
|
|
19124
|
+
if (this.snapshotTimeout) {
|
|
19125
|
+
clearTimeout(this.snapshotTimeout);
|
|
19126
|
+
this.snapshotTimeout = undefined;
|
|
19127
|
+
}
|
|
19088
19128
|
// Send final batch
|
|
19089
19129
|
this.sendBatch();
|
|
19090
19130
|
}
|
|
@@ -19093,13 +19133,47 @@ class SessionReplayEngine {
|
|
|
19093
19133
|
*/
|
|
19094
19134
|
handleRRWebEvent(event) {
|
|
19095
19135
|
try {
|
|
19096
|
-
//
|
|
19097
|
-
|
|
19136
|
+
// Log ALL events until we get FullSnapshot, then log first 5
|
|
19137
|
+
const shouldLog = !this.hasFullSnapshot || this.events.length < 5;
|
|
19138
|
+
if (shouldLog) {
|
|
19139
|
+
const eventTypeNames = {
|
|
19140
|
+
[EventType.DomContentLoaded]: "DomContentLoaded",
|
|
19141
|
+
[EventType.Load]: "Load",
|
|
19142
|
+
[EventType.FullSnapshot]: "FullSnapshot",
|
|
19143
|
+
[EventType.IncrementalSnapshot]: "IncrementalSnapshot",
|
|
19144
|
+
[EventType.Meta]: "Meta",
|
|
19145
|
+
[EventType.Custom]: "Custom",
|
|
19146
|
+
[EventType.Plugin]: "Plugin",
|
|
19147
|
+
};
|
|
19148
|
+
console.log(`[Zaplier] Received event type ${event.type} (${eventTypeNames[event.type] || "Unknown"})`, {
|
|
19149
|
+
timestamp: new Date(event.timestamp).toISOString(),
|
|
19150
|
+
isFirst: this.events.length === 0,
|
|
19151
|
+
totalEvents: this.events.length + 1,
|
|
19152
|
+
});
|
|
19153
|
+
}
|
|
19154
|
+
// Check if this is a FullSnapshot
|
|
19155
|
+
if (event.type === EventType.FullSnapshot) {
|
|
19098
19156
|
this.hasFullSnapshot = true;
|
|
19099
|
-
console.log("[Zaplier] FullSnapshot captured");
|
|
19157
|
+
console.log("[Zaplier] ✅ FullSnapshot captured! Replay will work correctly.");
|
|
19158
|
+
// Clear timeout since we got the snapshot
|
|
19159
|
+
if (this.snapshotTimeout) {
|
|
19160
|
+
clearTimeout(this.snapshotTimeout);
|
|
19161
|
+
this.snapshotTimeout = undefined;
|
|
19162
|
+
}
|
|
19163
|
+
}
|
|
19164
|
+
else if (this.events.length === 0) {
|
|
19165
|
+
// First event is NOT a FullSnapshot - this is a problem!
|
|
19166
|
+
console.error(`[Zaplier] ⚠️ WARNING: First event is type ${event.type}, not FullSnapshot! Replay may not work.`);
|
|
19100
19167
|
}
|
|
19101
19168
|
// Add event to buffer
|
|
19102
19169
|
this.addEvent(event);
|
|
19170
|
+
// If we just got the FullSnapshot and have events, try sending immediately
|
|
19171
|
+
if (event.type === EventType.FullSnapshot && this.events.length > 0) {
|
|
19172
|
+
// Small delay to ensure all initial events are captured
|
|
19173
|
+
setTimeout(() => {
|
|
19174
|
+
this.sendBatch();
|
|
19175
|
+
}, 100);
|
|
19176
|
+
}
|
|
19103
19177
|
}
|
|
19104
19178
|
catch (error) {
|
|
19105
19179
|
// Silently ignore errors from rrweb to prevent breaking the app
|
|
@@ -19115,7 +19189,7 @@ class SessionReplayEngine {
|
|
|
19115
19189
|
// Prevent memory overflow
|
|
19116
19190
|
if (this.events.length > this.config.maxEventBuffer) {
|
|
19117
19191
|
// Keep FullSnapshot if present
|
|
19118
|
-
const fullSnapshotIndex = this.events.findIndex((e) => e.type ===
|
|
19192
|
+
const fullSnapshotIndex = this.events.findIndex((e) => e.type === EventType.FullSnapshot);
|
|
19119
19193
|
if (fullSnapshotIndex >= 0 &&
|
|
19120
19194
|
fullSnapshotIndex < this.events.length - this.config.maxEventBuffer) {
|
|
19121
19195
|
// Keep snapshot and recent events
|
|
@@ -19143,15 +19217,19 @@ class SessionReplayEngine {
|
|
|
19143
19217
|
if (this.events.length === 0) {
|
|
19144
19218
|
return;
|
|
19145
19219
|
}
|
|
19146
|
-
//
|
|
19220
|
+
// CRITICAL: Never send batches without FullSnapshot - replay won't work!
|
|
19147
19221
|
if (!this.hasFullSnapshot) {
|
|
19148
|
-
|
|
19149
|
-
|
|
19222
|
+
const waitTime = Date.now() - this.startTime;
|
|
19223
|
+
// Only log every 2 seconds to avoid spam
|
|
19224
|
+
if (waitTime % 2000 < 100) {
|
|
19225
|
+
console.warn(`[Zaplier] Waiting for FullSnapshot before sending batch... (${Math.floor(waitTime / 1000)}s). Events so far: ${this.events.length}, types:`, this.events.map((e) => e.type).slice(0, 5));
|
|
19226
|
+
}
|
|
19227
|
+
return; // Don't send without FullSnapshot
|
|
19150
19228
|
}
|
|
19151
19229
|
const batch = [...this.events];
|
|
19152
19230
|
this.events = [];
|
|
19153
19231
|
// Verify batch has FullSnapshot
|
|
19154
|
-
const hasSnapshot = batch.some((e) => e.type ===
|
|
19232
|
+
const hasSnapshot = batch.some((e) => e.type === EventType.FullSnapshot);
|
|
19155
19233
|
if (!hasSnapshot && this.hasFullSnapshot) {
|
|
19156
19234
|
console.warn("[Zaplier] Batch missing FullSnapshot, but one was captured earlier");
|
|
19157
19235
|
}
|
|
@@ -19257,7 +19335,7 @@ const DEFAULT_CONFIG = {
|
|
|
19257
19335
|
*/
|
|
19258
19336
|
class ZaplierSDK {
|
|
19259
19337
|
constructor(userConfig) {
|
|
19260
|
-
this.version = "1.3.
|
|
19338
|
+
this.version = "1.3.5";
|
|
19261
19339
|
this.isInitialized = false;
|
|
19262
19340
|
this.eventQueue = [];
|
|
19263
19341
|
/**
|