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