@sentry/replay 7.25.0 → 7.27.0

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.
Files changed (43) hide show
  1. package/cjs/constants.js +4 -6
  2. package/cjs/constants.js.map +1 -1
  3. package/cjs/coreHandlers/handleGlobalEvent.js +14 -5
  4. package/cjs/coreHandlers/handleGlobalEvent.js.map +1 -1
  5. package/cjs/integration.js +2 -2
  6. package/cjs/integration.js.map +1 -1
  7. package/cjs/node_modules/lodash.debounce/index.js +1 -1
  8. package/cjs/node_modules/lodash.debounce/index.js.map +1 -1
  9. package/cjs/replay.js +28 -35
  10. package/cjs/replay.js.map +1 -1
  11. package/cjs/util/createReplayEnvelope.js +3 -7
  12. package/cjs/util/createReplayEnvelope.js.map +1 -1
  13. package/cjs/util/getReplayEvent.js +5 -8
  14. package/cjs/util/getReplayEvent.js.map +1 -1
  15. package/cjs/util/isRrwebError.js +23 -0
  16. package/cjs/util/isRrwebError.js.map +1 -0
  17. package/esm/constants.js +4 -6
  18. package/esm/constants.js.map +1 -1
  19. package/esm/coreHandlers/handleGlobalEvent.js +14 -5
  20. package/esm/coreHandlers/handleGlobalEvent.js.map +1 -1
  21. package/esm/integration.js +3 -3
  22. package/esm/integration.js.map +1 -1
  23. package/esm/node_modules/lodash.debounce/index.js +1 -1
  24. package/esm/node_modules/lodash.debounce/index.js.map +1 -1
  25. package/esm/replay.js +28 -35
  26. package/esm/replay.js.map +1 -1
  27. package/esm/util/createReplayEnvelope.js +4 -8
  28. package/esm/util/createReplayEnvelope.js.map +1 -1
  29. package/esm/util/getReplayEvent.js +5 -8
  30. package/esm/util/getReplayEvent.js.map +1 -1
  31. package/esm/util/isRrwebError.js +19 -0
  32. package/esm/util/isRrwebError.js.map +1 -0
  33. package/package.json +7 -8
  34. package/types/constants.d.ts +3 -5
  35. package/types/constants.d.ts.map +1 -1
  36. package/types/coreHandlers/handleGlobalEvent.d.ts +1 -1
  37. package/types/coreHandlers/handleGlobalEvent.d.ts.map +1 -1
  38. package/types/replay.d.ts.map +1 -1
  39. package/types/util/createReplayEnvelope.d.ts +2 -2
  40. package/types/util/createReplayEnvelope.d.ts.map +1 -1
  41. package/types/util/getReplayEvent.d.ts.map +1 -1
  42. package/types/util/isRrwebError.d.ts +3 -0
  43. package/types/util/isRrwebError.d.ts.map +1 -0
package/esm/replay.js CHANGED
@@ -169,9 +169,10 @@ class ReplayContainer {
169
169
 
170
170
  this.addListeners();
171
171
 
172
- this.startRecording();
173
-
172
+ // Need to set as enabled before we start recording, as `record()` can trigger a flush with a new checkout
174
173
  this._isEnabled = true;
174
+
175
+ this.startRecording();
175
176
  }
176
177
 
177
178
  /**
@@ -216,8 +217,8 @@ class ReplayContainer {
216
217
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Stopping Replays');
217
218
  this._isEnabled = false;
218
219
  this.removeListeners();
219
- _optionalChain([this, 'access', _11 => _11._stopRecording, 'optionalCall', _12 => _12()]);
220
- _optionalChain([this, 'access', _13 => _13.eventBuffer, 'optionalAccess', _14 => _14.destroy, 'call', _15 => _15()]);
220
+ _optionalChain([this, 'access', _8 => _8._stopRecording, 'optionalCall', _9 => _9()]);
221
+ _optionalChain([this, 'access', _10 => _10.eventBuffer, 'optionalAccess', _11 => _11.destroy, 'call', _12 => _12()]);
221
222
  this.eventBuffer = null;
222
223
  } catch (err) {
223
224
  this.handleException(err);
@@ -290,8 +291,8 @@ class ReplayContainer {
290
291
  this.setInitialState();
291
292
  }
292
293
 
293
- if (session.id !== _optionalChain([this, 'access', _16 => _16.session, 'optionalAccess', _17 => _17.id])) {
294
- session.previousSessionId = _optionalChain([this, 'access', _18 => _18.session, 'optionalAccess', _19 => _19.id]);
294
+ if (session.id !== _optionalChain([this, 'access', _13 => _13.session, 'optionalAccess', _14 => _14.id])) {
295
+ session.previousSessionId = _optionalChain([this, 'access', _15 => _15.session, 'optionalAccess', _16 => _16.id]);
295
296
  }
296
297
 
297
298
  this.session = session;
@@ -332,7 +333,7 @@ class ReplayContainer {
332
333
  if (!this._hasInitializedCoreListeners) {
333
334
  // Listeners from core SDK //
334
335
  const scope = getCurrentHub().getScope();
335
- _optionalChain([scope, 'optionalAccess', _20 => _20.addScopeListener, 'call', _21 => _21(this.handleCoreBreadcrumbListener('scope'))]);
336
+ _optionalChain([scope, 'optionalAccess', _17 => _17.addScopeListener, 'call', _18 => _18(this.handleCoreBreadcrumbListener('scope'))]);
336
337
  addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
337
338
  addInstrumentationHandler('fetch', handleFetchSpanListener(this));
338
339
  addInstrumentationHandler('xhr', handleXhrSpanListener(this));
@@ -387,7 +388,7 @@ class ReplayContainer {
387
388
  */
388
389
  addUpdate(cb) {
389
390
  // We need to always run `cb` (e.g. in the case of `this.recordingMode == 'error'`)
390
- const cbResult = _optionalChain([cb, 'optionalCall', _22 => _22()]);
391
+ const cbResult = _optionalChain([cb, 'optionalCall', _19 => _19()]);
391
392
 
392
393
  // If this option is turned on then we will only want to call `flush`
393
394
  // explicitly
@@ -448,7 +449,7 @@ class ReplayContainer {
448
449
  // of the previous session. Do not immediately flush in this case
449
450
  // to avoid capturing only the checkout and instead the replay will
450
451
  // be captured if they perform any follow-up actions.
451
- if (_optionalChain([this, 'access', _23 => _23.session, 'optionalAccess', _24 => _24.previousSessionId])) {
452
+ if (_optionalChain([this, 'access', _20 => _20.session, 'optionalAccess', _21 => _21.previousSessionId])) {
452
453
  return true;
453
454
  }
454
455
 
@@ -459,21 +460,13 @@ class ReplayContainer {
459
460
  this._maybeSaveSession();
460
461
  }
461
462
 
462
- // If the full snapshot is due to an initial load, we will not have
463
- // a previous session ID. In this case, we want to buffer events
464
- // for a set amount of time before flushing. This can help avoid
465
- // capturing replays of users that immediately close the window.
466
- setTimeout(() => this.conditionalFlush(), this._options.initialFlushDelay);
467
-
468
- // Cancel any previously debounced flushes to ensure there are no [near]
469
- // simultaneous flushes happening. The latter request should be
470
- // insignificant in this case, so wait for additional user interaction to
471
- // trigger a new flush.
472
- //
473
- // This can happen because there's no guarantee that a recording event
474
- // happens first. e.g. a mouse click can happen and trigger a debounced
475
- // flush before the checkout.
476
- _optionalChain([this, 'access', _25 => _25._debouncedFlush, 'optionalAccess', _26 => _26.cancel, 'call', _27 => _27()]);
463
+ // Flush immediately so that we do not miss the first segment, otherwise
464
+ // it can prevent loading on the UI. This will cause an increase in short
465
+ // replays (e.g. opening and closing a tab quickly), but these can be
466
+ // filtered on the UI.
467
+ if (this.recordingMode === 'session') {
468
+ void this.flushImmediate();
469
+ }
477
470
 
478
471
  return true;
479
472
  });
@@ -697,7 +690,7 @@ class ReplayContainer {
697
690
  * Returns true if session is not expired, false otherwise.
698
691
  */
699
692
  checkAndHandleExpiredSession({ expiry = SESSION_IDLE_DURATION } = {}) {
700
- const oldSessionId = _optionalChain([this, 'access', _28 => _28.session, 'optionalAccess', _29 => _29.id]);
693
+ const oldSessionId = _optionalChain([this, 'access', _22 => _22.session, 'optionalAccess', _23 => _23.id]);
701
694
 
702
695
  // Prevent starting a new session if the last user activity is older than
703
696
  // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
@@ -714,7 +707,7 @@ class ReplayContainer {
714
707
  this.loadSession({ expiry });
715
708
 
716
709
  // Session was expired if session ids do not match
717
- const expired = oldSessionId !== _optionalChain([this, 'access', _30 => _30.session, 'optionalAccess', _31 => _31.id]);
710
+ const expired = oldSessionId !== _optionalChain([this, 'access', _24 => _24.session, 'optionalAccess', _25 => _25.id]);
718
711
 
719
712
  if (!expired) {
720
713
  return true;
@@ -785,7 +778,7 @@ class ReplayContainer {
785
778
 
786
779
  await this.addPerformanceEntries();
787
780
 
788
- if (!_optionalChain([this, 'access', _32 => _32.eventBuffer, 'optionalAccess', _33 => _33.length])) {
781
+ if (!_optionalChain([this, 'access', _26 => _26.eventBuffer, 'optionalAccess', _27 => _27.length])) {
789
782
  return;
790
783
  }
791
784
 
@@ -832,13 +825,13 @@ class ReplayContainer {
832
825
  return;
833
826
  }
834
827
 
835
- if (!_optionalChain([this, 'access', _34 => _34.session, 'optionalAccess', _35 => _35.id])) {
828
+ if (!_optionalChain([this, 'access', _28 => _28.session, 'optionalAccess', _29 => _29.id])) {
836
829
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] No session found to flush.');
837
830
  return;
838
831
  }
839
832
 
840
833
  // A flush is about to happen, cancel any queued flushes
841
- _optionalChain([this, 'access', _36 => _36._debouncedFlush, 'optionalAccess', _37 => _37.cancel, 'call', _38 => _38()]);
834
+ _optionalChain([this, 'access', _30 => _30._debouncedFlush, 'optionalAccess', _31 => _31.cancel, 'call', _32 => _32()]);
842
835
 
843
836
  // No existing flush in progress, proceed with flushing.
844
837
  // this._flushLock acts as a lock so that future calls to `flush()`
@@ -902,8 +895,9 @@ class ReplayContainer {
902
895
  const client = hub.getClient();
903
896
  const scope = hub.getScope();
904
897
  const transport = client && client.getTransport();
898
+ const dsn = _optionalChain([client, 'optionalAccess', _33 => _33.getDsn, 'call', _34 => _34()]);
905
899
 
906
- if (!client || !scope || !transport) {
900
+ if (!client || !scope || !transport || !dsn) {
907
901
  return;
908
902
  }
909
903
 
@@ -920,12 +914,11 @@ class ReplayContainer {
920
914
  };
921
915
 
922
916
  const replayEvent = await getReplayEvent({ scope, client, replayId, event: baseEvent });
923
-
924
917
  replayEvent.tags = {
925
918
  ...replayEvent.tags,
926
919
  sessionSampleRate: this._options.sessionSampleRate,
927
920
  errorSampleRate: this._options.errorSampleRate,
928
- replayType: _optionalChain([this, 'access', _39 => _39.session, 'optionalAccess', _40 => _40.sampled]),
921
+ replayType: _optionalChain([this, 'access', _35 => _35.session, 'optionalAccess', _36 => _36.sampled]),
929
922
  };
930
923
 
931
924
  /*
@@ -952,8 +945,8 @@ class ReplayContainer {
952
945
  "BrowserTracing",
953
946
  "Replay"
954
947
  ],
955
- "name": "sentry.javascript.integration.replay",
956
- "version": "7.24.2"
948
+ "name": "sentry.javascript.browser",
949
+ "version": "7.25.0"
957
950
  },
958
951
  "sdkProcessingMetadata": {},
959
952
  "tags": {
@@ -964,7 +957,7 @@ class ReplayContainer {
964
957
  }
965
958
  */
966
959
 
967
- const envelope = createReplayEnvelope(replayId, replayEvent, payloadWithSequence);
960
+ const envelope = createReplayEnvelope(replayEvent, payloadWithSequence, dsn, client.getOptions().tunnel);
968
961
 
969
962
  try {
970
963
  return transport.send(envelope);