@zaplier/sdk 1.3.3 → 1.3.4

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 CHANGED
@@ -19020,6 +19020,7 @@ class SessionReplayEngine {
19020
19020
  this.events = [];
19021
19021
  this.isActive = false;
19022
19022
  this.hasFullSnapshot = false;
19023
+ this.startTime = 0;
19023
19024
  this.sessionId = sessionId;
19024
19025
  this.config = {
19025
19026
  enabled: true,
@@ -19064,7 +19065,22 @@ class SessionReplayEngine {
19064
19065
  });
19065
19066
  this.isActive = true;
19066
19067
  this.hasFullSnapshot = false;
19068
+ this.startTime = Date.now();
19067
19069
  this.startBatchTimer();
19070
+ // Set timeout to check if FullSnapshot was captured
19071
+ this.snapshotTimeout = window.setTimeout(() => {
19072
+ if (!this.hasFullSnapshot) {
19073
+ console.error("[Zaplier] CRITICAL: FullSnapshot not captured after 5 seconds!", {
19074
+ eventsReceived: this.events.length,
19075
+ eventTypes: this.events.map((e) => e.type).slice(0, 10),
19076
+ });
19077
+ // Don't send batches without FullSnapshot - replay won't work
19078
+ // The issue is likely with rrweb errors preventing snapshot capture
19079
+ }
19080
+ else {
19081
+ console.log("[Zaplier] FullSnapshot confirmed captured");
19082
+ }
19083
+ }, 5000);
19068
19084
  console.log("[Zaplier] Session replay started with rrweb");
19069
19085
  return true;
19070
19086
  }
@@ -19089,6 +19105,10 @@ class SessionReplayEngine {
19089
19105
  clearInterval(this.batchTimer);
19090
19106
  this.batchTimer = undefined;
19091
19107
  }
19108
+ if (this.snapshotTimeout) {
19109
+ clearTimeout(this.snapshotTimeout);
19110
+ this.snapshotTimeout = undefined;
19111
+ }
19092
19112
  // Send final batch
19093
19113
  this.sendBatch();
19094
19114
  }
@@ -19097,13 +19117,47 @@ class SessionReplayEngine {
19097
19117
  */
19098
19118
  handleRRWebEvent(event) {
19099
19119
  try {
19100
- // Check if this is a FullSnapshot (type 2)
19101
- if (event.type === 2) {
19120
+ // Log ALL events until we get FullSnapshot, then log first 5
19121
+ const shouldLog = !this.hasFullSnapshot || this.events.length < 5;
19122
+ if (shouldLog) {
19123
+ const eventTypeNames = {
19124
+ [EventType.DomContentLoaded]: "DomContentLoaded",
19125
+ [EventType.Load]: "Load",
19126
+ [EventType.FullSnapshot]: "FullSnapshot",
19127
+ [EventType.IncrementalSnapshot]: "IncrementalSnapshot",
19128
+ [EventType.Meta]: "Meta",
19129
+ [EventType.Custom]: "Custom",
19130
+ [EventType.Plugin]: "Plugin",
19131
+ };
19132
+ console.log(`[Zaplier] Received event type ${event.type} (${eventTypeNames[event.type] || "Unknown"})`, {
19133
+ timestamp: new Date(event.timestamp).toISOString(),
19134
+ isFirst: this.events.length === 0,
19135
+ totalEvents: this.events.length + 1,
19136
+ });
19137
+ }
19138
+ // Check if this is a FullSnapshot
19139
+ if (event.type === EventType.FullSnapshot) {
19102
19140
  this.hasFullSnapshot = true;
19103
- console.log("[Zaplier] FullSnapshot captured");
19141
+ console.log("[Zaplier] FullSnapshot captured! Replay will work correctly.");
19142
+ // Clear timeout since we got the snapshot
19143
+ if (this.snapshotTimeout) {
19144
+ clearTimeout(this.snapshotTimeout);
19145
+ this.snapshotTimeout = undefined;
19146
+ }
19147
+ }
19148
+ else if (this.events.length === 0) {
19149
+ // First event is NOT a FullSnapshot - this is a problem!
19150
+ console.error(`[Zaplier] ⚠️ WARNING: First event is type ${event.type}, not FullSnapshot! Replay may not work.`);
19104
19151
  }
19105
19152
  // Add event to buffer
19106
19153
  this.addEvent(event);
19154
+ // If we just got the FullSnapshot and have events, try sending immediately
19155
+ if (event.type === EventType.FullSnapshot && this.events.length > 0) {
19156
+ // Small delay to ensure all initial events are captured
19157
+ setTimeout(() => {
19158
+ this.sendBatch();
19159
+ }, 100);
19160
+ }
19107
19161
  }
19108
19162
  catch (error) {
19109
19163
  // Silently ignore errors from rrweb to prevent breaking the app
@@ -19119,7 +19173,7 @@ class SessionReplayEngine {
19119
19173
  // Prevent memory overflow
19120
19174
  if (this.events.length > this.config.maxEventBuffer) {
19121
19175
  // Keep FullSnapshot if present
19122
- const fullSnapshotIndex = this.events.findIndex((e) => e.type === 2);
19176
+ const fullSnapshotIndex = this.events.findIndex((e) => e.type === EventType.FullSnapshot);
19123
19177
  if (fullSnapshotIndex >= 0 &&
19124
19178
  fullSnapshotIndex < this.events.length - this.config.maxEventBuffer) {
19125
19179
  // Keep snapshot and recent events
@@ -19147,15 +19201,19 @@ class SessionReplayEngine {
19147
19201
  if (this.events.length === 0) {
19148
19202
  return;
19149
19203
  }
19150
- // Wait for FullSnapshot before sending first batch
19204
+ // CRITICAL: Never send batches without FullSnapshot - replay won't work!
19151
19205
  if (!this.hasFullSnapshot) {
19152
- console.log("[Zaplier] Waiting for FullSnapshot before sending batch...");
19153
- return;
19206
+ const waitTime = Date.now() - this.startTime;
19207
+ // Only log every 2 seconds to avoid spam
19208
+ if (waitTime % 2000 < 100) {
19209
+ 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));
19210
+ }
19211
+ return; // Don't send without FullSnapshot
19154
19212
  }
19155
19213
  const batch = [...this.events];
19156
19214
  this.events = [];
19157
19215
  // Verify batch has FullSnapshot
19158
- const hasSnapshot = batch.some((e) => e.type === 2);
19216
+ const hasSnapshot = batch.some((e) => e.type === EventType.FullSnapshot);
19159
19217
  if (!hasSnapshot && this.hasFullSnapshot) {
19160
19218
  console.warn("[Zaplier] Batch missing FullSnapshot, but one was captured earlier");
19161
19219
  }