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