userlens-session-recorder 2.0.0 → 2.0.1

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.js CHANGED
@@ -20673,7 +20673,7 @@ const uploadSessionEvents = async (args) => {
20673
20673
  return "ok";
20674
20674
  };
20675
20675
 
20676
- var _SessionRecorder_instances, _SessionRecorder_trackEventsThrottled, _SessionRecorder_uploading, _SessionRecorder_log, _SessionRecorder_initRecorder, _SessionRecorder_isUserInteraction, _SessionRecorder_handleEvent, _SessionRecorder_resetSession, _SessionRecorder_createSession, _SessionRecorder_handlePageHide, _SessionRecorder_initListeners, _SessionRecorder_throttle, _SessionRecorder_trackEvents, _SessionRecorder_clearEvents;
20676
+ var _SessionRecorder_instances, _SessionRecorder_trackEventsThrottled, _SessionRecorder_uploading, _SessionRecorder_uploadingMaxTs, _SessionRecorder_log, _SessionRecorder_initRecorder, _SessionRecorder_isUserInteraction, _SessionRecorder_handleEvent, _SessionRecorder_resetSession, _SessionRecorder_createSession, _SessionRecorder_handlePageHide, _SessionRecorder_initListeners, _SessionRecorder_throttle, _SessionRecorder_trackEvents, _SessionRecorder_clearEvents;
20677
20677
  class SessionRecorder {
20678
20678
  constructor(config) {
20679
20679
  var _a, _b, _c;
@@ -20683,18 +20683,45 @@ class SessionRecorder {
20683
20683
  this.debug = false;
20684
20684
  _SessionRecorder_trackEventsThrottled.set(this, void 0);
20685
20685
  _SessionRecorder_uploading.set(this, false);
20686
+ _SessionRecorder_uploadingMaxTs.set(this, 0);
20686
20687
  _SessionRecorder_handlePageHide.set(this, () => {
20687
20688
  try {
20688
20689
  if (this.sessionEvents.length === 0)
20689
20690
  return;
20690
- const events = [...this.sessionEvents];
20691
+ let toUpload;
20692
+ if (__classPrivateFieldGet(this, _SessionRecorder_uploading, "f") && __classPrivateFieldGet(this, _SessionRecorder_uploadingMaxTs, "f") > 0) {
20693
+ toUpload = this.sessionEvents.filter((e) => e.timestamp > __classPrivateFieldGet(this, _SessionRecorder_uploadingMaxTs, "f"));
20694
+ }
20695
+ else {
20696
+ toUpload = [...this.sessionEvents];
20697
+ }
20698
+ if (toUpload.length === 0)
20699
+ return;
20700
+ let events;
20701
+ if (toUpload[0].type !== 4) {
20702
+ let snapshotPair = [];
20703
+ for (let i = this.sessionEvents.length - 2; i >= 0; i--) {
20704
+ if (this.sessionEvents[i].type === 4 &&
20705
+ this.sessionEvents[i + 1].type === 2) {
20706
+ snapshotPair = [
20707
+ this.sessionEvents[i],
20708
+ this.sessionEvents[i + 1],
20709
+ ];
20710
+ break;
20711
+ }
20712
+ }
20713
+ events = [...snapshotPair, ...toUpload];
20714
+ }
20715
+ else {
20716
+ events = toUpload;
20717
+ }
20691
20718
  const state = readSessionState();
20692
20719
  if (!state)
20693
20720
  return;
20694
20721
  const chunk_seq = __classPrivateFieldGet(this, _SessionRecorder_uploading, "f") ? state.chunk_seq + 1 : state.chunk_seq;
20695
20722
  writeSessionState({ ...state, chunk_seq: chunk_seq + 1 });
20696
- const start_ts_ms = events[0].timestamp;
20697
- const end_ts_ms = events[events.length - 1].timestamp;
20723
+ const start_ts_ms = toUpload[0].timestamp;
20724
+ const end_ts_ms = toUpload[toUpload.length - 1].timestamp;
20698
20725
  uploadSessionEvents({
20699
20726
  user_id: this.userId,
20700
20727
  session_uuid: this.sessionUuid,
@@ -20773,7 +20800,7 @@ class SessionRecorder {
20773
20800
  }
20774
20801
  }
20775
20802
  }
20776
- _SessionRecorder_trackEventsThrottled = new WeakMap(), _SessionRecorder_uploading = new WeakMap(), _SessionRecorder_handlePageHide = new WeakMap(), _SessionRecorder_instances = new WeakSet(), _SessionRecorder_log = function _SessionRecorder_log(message, error) {
20803
+ _SessionRecorder_trackEventsThrottled = new WeakMap(), _SessionRecorder_uploading = new WeakMap(), _SessionRecorder_uploadingMaxTs = new WeakMap(), _SessionRecorder_handlePageHide = new WeakMap(), _SessionRecorder_instances = new WeakSet(), _SessionRecorder_log = function _SessionRecorder_log(message, error) {
20777
20804
  if (!this.debug)
20778
20805
  return;
20779
20806
  if (error) {
@@ -20796,7 +20823,6 @@ _SessionRecorder_trackEventsThrottled = new WeakMap(), _SessionRecorder_uploadin
20796
20823
  },
20797
20824
  recordCrossOriginIframes: this.recordCrossOriginIframes,
20798
20825
  plugins: [getRecordConsolePlugin()],
20799
- checkoutEveryNth: 100,
20800
20826
  });
20801
20827
  __classPrivateFieldGet(this, _SessionRecorder_instances, "m", _SessionRecorder_initListeners).call(this);
20802
20828
  }, _SessionRecorder_isUserInteraction = function _SessionRecorder_isUserInteraction(event) {
@@ -20871,6 +20897,7 @@ _SessionRecorder_trackEventsThrottled = new WeakMap(), _SessionRecorder_uploadin
20871
20897
  try {
20872
20898
  const events = [...this.sessionEvents];
20873
20899
  const snapshot_count = events.length;
20900
+ __classPrivateFieldSet(this, _SessionRecorder_uploadingMaxTs, events[events.length - 1].timestamp, "f");
20874
20901
  const start_ts_ms = events[0].timestamp;
20875
20902
  const end_ts_ms = events[events.length - 1].timestamp;
20876
20903
  const state = readSessionState();
@@ -20888,10 +20915,22 @@ _SessionRecorder_trackEventsThrottled = new WeakMap(), _SessionRecorder_uploadin
20888
20915
  initial_url: chunk_seq === 0 ? state.initial_url : undefined,
20889
20916
  events,
20890
20917
  });
20891
- this.sessionEvents = this.sessionEvents.slice(snapshot_count);
20918
+ const remaining = this.sessionEvents.slice(snapshot_count);
20919
+ this.sessionEvents = [];
20920
+ try {
20921
+ takeFullSnapshot(true);
20922
+ }
20923
+ catch (err) {
20924
+ __classPrivateFieldGet(this, _SessionRecorder_instances, "m", _SessionRecorder_log).call(this, "takeFullSnapshot failed", err);
20925
+ }
20926
+ if (remaining.length > 0) {
20927
+ this.sessionEvents.push(...remaining);
20928
+ }
20892
20929
  const after = readSessionState();
20893
- if (after && after.session_uuid === state.session_uuid) {
20894
- writeSessionState({ ...after, chunk_seq: after.chunk_seq + 1 });
20930
+ if (after &&
20931
+ after.session_uuid === state.session_uuid &&
20932
+ after.chunk_seq === chunk_seq) {
20933
+ writeSessionState({ ...after, chunk_seq: chunk_seq + 1 });
20895
20934
  }
20896
20935
  }
20897
20936
  catch (err) {
@@ -20899,6 +20938,7 @@ _SessionRecorder_trackEventsThrottled = new WeakMap(), _SessionRecorder_uploadin
20899
20938
  }
20900
20939
  finally {
20901
20940
  __classPrivateFieldSet(this, _SessionRecorder_uploading, false, "f");
20941
+ __classPrivateFieldSet(this, _SessionRecorder_uploadingMaxTs, 0, "f");
20902
20942
  }
20903
20943
  }, _SessionRecorder_clearEvents = function _SessionRecorder_clearEvents() {
20904
20944
  this.sessionEvents = [];