@multiplayer-app/session-recorder-browser 2.0.38 → 2.0.39

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.js CHANGED
@@ -24263,7 +24263,7 @@ const CONTINUOUS_DEBUGGING_TIMEOUT = 60000; // 1 minutes
24263
24263
  const DEBUG_SESSION_MAX_DURATION_SECONDS = 10 * 60 + 30; // TODO: move to shared config otel core
24264
24264
  const REMOTE_SESSION_RECORDING_START = 'remote-session-recording:start';
24265
24265
  const REMOTE_SESSION_RECORDING_STOP = 'remote-session-recording:stop';
24266
- const PACKAGE_VERSION_EXPORT = "2.0.38" || 0;
24266
+ const PACKAGE_VERSION_EXPORT = "2.0.39" || 0;
24267
24267
  // Regex patterns for OpenTelemetry ignore URLs
24268
24268
  const OTEL_IGNORE_URLS = [
24269
24269
  // Traces endpoint
@@ -25951,6 +25951,7 @@ if (typeof XMLHttpRequest !== 'undefined') {
25951
25951
 
25952
25952
  class RecorderBrowserSDK {
25953
25953
  constructor() {
25954
+ this.generation = 0;
25954
25955
  this.intervals = {
25955
25956
  restart: null,
25956
25957
  bufferSnapshot: null,
@@ -25986,12 +25987,15 @@ class RecorderBrowserSDK {
25986
25987
  throw new Error('Configuration not initialized. Call init() before start().');
25987
25988
  }
25988
25989
  this.startedAt = new Date().toISOString();
25990
+ const gen = ++this.generation;
25989
25991
  this.stopFn = (0,rrweb__WEBPACK_IMPORTED_MODULE_6__.record)({
25990
25992
  ...this._buildRecordOptions(),
25991
25993
  emit: async (event) => {
25994
+ if (gen !== this.generation)
25995
+ return;
25992
25996
  const ts = event.timestamp;
25993
25997
  if (!sessionId) {
25994
- await this._handleBufferOnlyEvent(event, ts);
25998
+ await this._handleBufferOnlyEvent(event, ts, gen);
25995
25999
  return;
25996
26000
  }
25997
26001
  this._handleLiveSessionEvent(event, ts, sessionId, sessionType);
@@ -26007,6 +26011,7 @@ class RecorderBrowserSDK {
26007
26011
  var _a;
26008
26012
  try {
26009
26013
  (_a = this.stopFn) === null || _a === void 0 ? void 0 : _a.call(this);
26014
+ this.stopFn = undefined;
26010
26015
  this.start(sessionId, sessionType);
26011
26016
  }
26012
26017
  catch (_e) {
@@ -26020,6 +26025,7 @@ class RecorderBrowserSDK {
26020
26025
  var _a, _b, _c;
26021
26026
  (_a = this.stopFn) === null || _a === void 0 ? void 0 : _a.call(this);
26022
26027
  this.stopFn = undefined;
26028
+ this.generation++;
26023
26029
  if (!((_b = this.config) === null || _b === void 0 ? void 0 : _b.useWebsocket)) {
26024
26030
  (_c = this.socketService) === null || _c === void 0 ? void 0 : _c.close();
26025
26031
  }
@@ -26059,13 +26065,15 @@ class RecorderBrowserSDK {
26059
26065
  * @param event - Event.
26060
26066
  * @param ts - Timestamp.
26061
26067
  */
26062
- async _handleBufferOnlyEvent(event, ts) {
26068
+ async _handleBufferOnlyEvent(event, ts, gen) {
26063
26069
  if (!this.crashBuffer)
26064
26070
  return;
26065
26071
  try {
26066
26072
  this._applyConsoleMasking(event);
26067
26073
  const packedEvent = (0,_rrweb_packer__WEBPACK_IMPORTED_MODULE_0__.pack)(event);
26068
26074
  this.stoppedAt = new Date(ts).toISOString();
26075
+ if (gen !== this.generation)
26076
+ return;
26069
26077
  await this.crashBuffer.appendEvent({
26070
26078
  ts,
26071
26079
  isFullSnapshot: event.type === _rrweb_types__WEBPACK_IMPORTED_MODULE_1__.EventType.FullSnapshot,
@@ -28007,7 +28015,11 @@ class SessionRecorder extends lib0_observable__WEBPACK_IMPORTED_MODULE_16__.Obse
28007
28015
  this._tracer.stop();
28008
28016
  this._recorder.stop();
28009
28017
  this._navigationRecorder.stop();
28010
- this._startBufferOnlyRecording();
28018
+ // rrweb assigns new node IDs on each record() call, so the next buffer
28019
+ // segment must not carry events from the previous generation. Await the
28020
+ // clear so its IDB tx can't race past the fresh FullSnapshot.
28021
+ const cleared = this._crashBuffer ? this._crashBuffer.clear() : Promise.resolve();
28022
+ void cleared.catch(() => undefined).then(() => this._startBufferOnlyRecording());
28011
28023
  }
28012
28024
  /**
28013
28025
  * Pause the session tracing and recording