@sentry/replay 7.40.0 → 7.42.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.
package/esm/index.js CHANGED
@@ -14,9 +14,6 @@ const UNABLE_TO_SEND_REPLAY = 'Unable to send Replay';
14
14
  // The idle limit for a session
15
15
  const SESSION_IDLE_DURATION = 300000; // 5 minutes in ms
16
16
 
17
- // Grace period to keep a session when a user changes tabs or hides window
18
- const VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
19
-
20
17
  // The maximum length of a session
21
18
  const MAX_SESSION_LIFE = 3600000; // 60 minutes
22
19
 
@@ -267,7 +264,7 @@ function getHref() {
267
264
  a.href = '';
268
265
  return a.href;
269
266
  }
270
- function transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn) {
267
+ function transformAttribute(doc, element, tagName, name, value, maskAllText, maskTextFn) {
271
268
  if (!value) {
272
269
  return value;
273
270
  }
@@ -291,7 +288,11 @@ function transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn)
291
288
  return absoluteToDoc(doc, value);
292
289
  }
293
290
  else if (maskAllText &&
294
- ['placeholder', 'title', 'aria-label'].indexOf(name) > -1) {
291
+ (['placeholder', 'title', 'aria-label'].indexOf(name) > -1 ||
292
+ (tagName === 'input' &&
293
+ name === 'value' &&
294
+ element.getAttribute('type') &&
295
+ ['submit', 'button'].indexOf(element.getAttribute('type').toLowerCase()) > -1))) {
295
296
  return maskTextFn ? maskTextFn(value) : defaultMaskFn(value);
296
297
  }
297
298
  return value;
@@ -429,7 +430,7 @@ function serializeNode(n, options) {
429
430
  let attributes = {};
430
431
  for (const { name, value } of Array.from(n.attributes)) {
431
432
  if (!skipAttribute(tagName, name)) {
432
- attributes[name] = transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn);
433
+ attributes[name] = transformAttribute(doc, n, tagName, name, value, maskAllText, maskTextFn);
433
434
  }
434
435
  }
435
436
  if (tagName === 'link' && inlineStylesheet) {
@@ -1589,7 +1590,8 @@ class MutationBuffer {
1589
1590
  }
1590
1591
  }
1591
1592
  else {
1592
- item.attributes[m.attributeName] = transformAttribute(this.doc, m.target.tagName, m.attributeName, value, this.maskAllText, this.maskTextFn);
1593
+ const element = m.target;
1594
+ item.attributes[m.attributeName] = transformAttribute(this.doc, element, element.tagName, m.attributeName, value, this.maskAllText, this.maskTextFn);
1593
1595
  }
1594
1596
  break;
1595
1597
  }
@@ -1776,7 +1778,12 @@ function initMutationObserver(options, rootEl) {
1776
1778
  window[angularZoneSymbol]) {
1777
1779
  mutationObserverCtor = window[angularZoneSymbol];
1778
1780
  }
1779
- const observer = new mutationObserverCtor(callbackWrapper(mutationBuffer.processMutations.bind(mutationBuffer)));
1781
+ const observer = new mutationObserverCtor(callbackWrapper((mutations) => {
1782
+ if (options.onMutation && options.onMutation(mutations) === false) {
1783
+ return;
1784
+ }
1785
+ mutationBuffer.processMutations(mutations);
1786
+ }));
1780
1787
  observer.observe(rootEl, {
1781
1788
  attributes: true,
1782
1789
  attributeOldValue: true,
@@ -2825,7 +2832,7 @@ let wrappedEmit;
2825
2832
  let takeFullSnapshot;
2826
2833
  const mirror = createMirror();
2827
2834
  function record(options = {}) {
2828
- const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, unblockSelector = null, ignoreClass = 'rr-ignore', ignoreSelector = null, maskTextClass = 'rr-mask', maskTextSelector = null, maskInputSelector = null, unmaskTextSelector = null, unmaskInputSelector = null, inlineStylesheet = true, maskAllText = false, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, mousemoveWait, recordCanvas = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, } = options;
2835
+ const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, unblockSelector = null, ignoreClass = 'rr-ignore', ignoreSelector = null, maskTextClass = 'rr-mask', maskTextSelector = null, maskInputSelector = null, unmaskTextSelector = null, unmaskInputSelector = null, inlineStylesheet = true, maskAllText = false, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, mousemoveWait, recordCanvas = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, onMutation, } = options;
2829
2836
  if (!emit) {
2830
2837
  throw new Error('emit function is required');
2831
2838
  }
@@ -2941,6 +2948,7 @@ function record(options = {}) {
2941
2948
  mutationCb: wrappedMutationEmit,
2942
2949
  scrollCb: wrappedScrollEmit,
2943
2950
  bypassOptions: {
2951
+ onMutation,
2944
2952
  blockClass,
2945
2953
  blockSelector,
2946
2954
  unblockSelector,
@@ -3041,6 +3049,7 @@ function record(options = {}) {
3041
3049
  const observe = (doc) => {
3042
3050
  var _a;
3043
3051
  return callbackWrapper(initObservers)({
3052
+ onMutation,
3044
3053
  mutationCb: wrappedMutationEmit,
3045
3054
  mousemoveCb: (positions, source) => wrappedEmit(wrapEvent({
3046
3055
  type: EventType.IncrementalSnapshot,
@@ -3663,13 +3672,13 @@ function isExpired(
3663
3672
  /**
3664
3673
  * Checks to see if session is expired
3665
3674
  */
3666
- function isSessionExpired(session, idleTimeout, targetTime = +new Date()) {
3675
+ function isSessionExpired(session, timeouts, targetTime = +new Date()) {
3667
3676
  return (
3668
3677
  // First, check that maximum session length has not been exceeded
3669
- isExpired(session.started, MAX_SESSION_LIFE, targetTime) ||
3678
+ isExpired(session.started, timeouts.maxSessionLife, targetTime) ||
3670
3679
  // check that the idle timeout has not been exceeded (i.e. user has
3671
3680
  // performed an action within the last `idleTimeout` ms)
3672
- isExpired(session.lastActivity, idleTimeout, targetTime)
3681
+ isExpired(session.lastActivity, timeouts.sessionIdle, targetTime)
3673
3682
  );
3674
3683
  }
3675
3684
 
@@ -3782,7 +3791,7 @@ function fetchSession() {
3782
3791
  * Get or create a session
3783
3792
  */
3784
3793
  function getSession({
3785
- expiry,
3794
+ timeouts,
3786
3795
  currentSession,
3787
3796
  stickySession,
3788
3797
  sessionSampleRate,
@@ -3795,7 +3804,7 @@ function getSession({
3795
3804
  // If there is a session, check if it is valid (e.g. "last activity" time
3796
3805
  // should be within the "session idle time", and "session started" time is
3797
3806
  // within "max session time").
3798
- const isExpired = isSessionExpired(session, expiry);
3807
+ const isExpired = isSessionExpired(session, timeouts);
3799
3808
 
3800
3809
  if (!isExpired) {
3801
3810
  return { type: 'saved', session };
@@ -3819,7 +3828,8 @@ function getSession({
3819
3828
  }
3820
3829
 
3821
3830
  /**
3822
- * Add an event to the event buffer
3831
+ * Add an event to the event buffer.
3832
+ * `isCheckout` is true if this is either the very first event, or an event triggered by `checkoutEveryNms`.
3823
3833
  */
3824
3834
  async function addEvent(
3825
3835
  replay,
@@ -3845,7 +3855,7 @@ async function addEvent(
3845
3855
  // page has been left open and idle for a long period of time and user
3846
3856
  // comes back to trigger a new session. The performance entries rely on
3847
3857
  // `performance.timeOrigin`, which is when the page first opened.
3848
- if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
3858
+ if (timestampInMs + replay.timeouts.sessionIdle < new Date().getTime()) {
3849
3859
  return null;
3850
3860
  }
3851
3861
 
@@ -3891,7 +3901,7 @@ function addBreadcrumbEvent(replay, breadcrumb) {
3891
3901
  return;
3892
3902
  }
3893
3903
 
3894
- if (breadcrumb.category === 'ui.click') {
3904
+ if (['ui.click', 'ui.input'].includes(breadcrumb.category )) {
3895
3905
  replay.triggerUserActivity();
3896
3906
  } else {
3897
3907
  replay.checkAndHandleExpiredSession();
@@ -4593,6 +4603,85 @@ function debounce(func, wait, options) {
4593
4603
  return debounced;
4594
4604
  }
4595
4605
 
4606
+ /**
4607
+ * Handler for recording events.
4608
+ *
4609
+ * Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
4610
+ */
4611
+ function getHandleRecordingEmit(replay) {
4612
+ let hadFirstEvent = false;
4613
+
4614
+ return (event, _isCheckout) => {
4615
+ // If this is false, it means session is expired, create and a new session and wait for checkout
4616
+ if (!replay.checkAndHandleExpiredSession()) {
4617
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('[Replay] Received replay event after session expired.');
4618
+
4619
+ return;
4620
+ }
4621
+
4622
+ // `_isCheckout` is only set when the checkout is due to `checkoutEveryNms`
4623
+ // We also want to treat the first event as a checkout, so we handle this specifically here
4624
+ const isCheckout = _isCheckout || !hadFirstEvent;
4625
+ hadFirstEvent = true;
4626
+
4627
+ // The handler returns `true` if we do not want to trigger debounced flush, `false` if we want to debounce flush.
4628
+ replay.addUpdate(() => {
4629
+ // The session is always started immediately on pageload/init, but for
4630
+ // error-only replays, it should reflect the most recent checkout
4631
+ // when an error occurs. Clear any state that happens before this current
4632
+ // checkout. This needs to happen before `addEvent()` which updates state
4633
+ // dependent on this reset.
4634
+ if (replay.recordingMode === 'error' && isCheckout) {
4635
+ replay.setInitialState();
4636
+ }
4637
+
4638
+ // We need to clear existing events on a checkout, otherwise they are
4639
+ // incremental event updates and should be appended
4640
+ void addEvent(replay, event, isCheckout);
4641
+
4642
+ // Different behavior for full snapshots (type=2), ignore other event types
4643
+ // See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
4644
+ if (!isCheckout) {
4645
+ return false;
4646
+ }
4647
+
4648
+ // If there is a previousSessionId after a full snapshot occurs, then
4649
+ // the replay session was started due to session expiration. The new session
4650
+ // is started before triggering a new checkout and contains the id
4651
+ // of the previous session. Do not immediately flush in this case
4652
+ // to avoid capturing only the checkout and instead the replay will
4653
+ // be captured if they perform any follow-up actions.
4654
+ if (replay.session && replay.session.previousSessionId) {
4655
+ return true;
4656
+ }
4657
+
4658
+ // See note above re: session start needs to reflect the most recent
4659
+ // checkout.
4660
+ if (replay.recordingMode === 'error' && replay.session) {
4661
+ const { earliestEvent } = replay.getContext();
4662
+ if (earliestEvent) {
4663
+ replay.session.started = earliestEvent;
4664
+
4665
+ if (replay.getOptions().stickySession) {
4666
+ saveSession(replay.session);
4667
+ }
4668
+ }
4669
+ }
4670
+
4671
+ // Flush immediately so that we do not miss the first segment, otherwise
4672
+ // it can prevent loading on the UI. This will cause an increase in short
4673
+ // replays (e.g. opening and closing a tab quickly), but these can be
4674
+ // filtered on the UI.
4675
+ if (replay.recordingMode === 'session') {
4676
+ // We want to ensure the worker is ready, as otherwise we'd always send the first event uncompressed
4677
+ void replay.flushImmediate();
4678
+ }
4679
+
4680
+ return true;
4681
+ });
4682
+ };
4683
+ }
4684
+
4596
4685
  let _originalRecordDroppedEvent;
4597
4686
 
4598
4687
  /**
@@ -4847,8 +4936,17 @@ async function sendReplayRequest({
4847
4936
 
4848
4937
  try {
4849
4938
  response = await transport.send(envelope);
4850
- } catch (e) {
4851
- throw new Error(UNABLE_TO_SEND_REPLAY);
4939
+ } catch (err) {
4940
+ const error = new Error(UNABLE_TO_SEND_REPLAY);
4941
+
4942
+ try {
4943
+ // In case browsers don't allow this property to be writable
4944
+ // @ts-ignore This needs lib es2022 and newer
4945
+ error.cause = err;
4946
+ } catch (e) {
4947
+ // nothing to do
4948
+ }
4949
+ throw error;
4852
4950
  }
4853
4951
 
4854
4952
  // TODO (v8): we can remove this guard once transport.send's type signature doesn't include void anymore
@@ -4910,7 +5008,17 @@ async function sendReplay(
4910
5008
  // If an error happened here, it's likely that uploading the attachment
4911
5009
  // failed, we'll can retry with the same events payload
4912
5010
  if (retryConfig.count >= RETRY_MAX_COUNT) {
4913
- throw new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);
5011
+ const error = new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);
5012
+
5013
+ try {
5014
+ // In case browsers don't allow this property to be writable
5015
+ // @ts-ignore This needs lib es2022 and newer
5016
+ error.cause = err;
5017
+ } catch (e) {
5018
+ // nothing to do
5019
+ }
5020
+
5021
+ throw error;
4914
5022
  }
4915
5023
 
4916
5024
  // will retry in intervals of 5, 10, 30
@@ -4949,43 +5057,52 @@ class ReplayContainer {
4949
5057
  */
4950
5058
  __init3() {this.recordingMode = 'session';}
4951
5059
 
5060
+ /**
5061
+ * These are here so we can overwrite them in tests etc.
5062
+ * @hidden
5063
+ */
5064
+ __init4() {this.timeouts = {
5065
+ sessionIdle: SESSION_IDLE_DURATION,
5066
+ maxSessionLife: MAX_SESSION_LIFE,
5067
+ }; }
5068
+
4952
5069
  /**
4953
5070
  * Options to pass to `rrweb.record()`
4954
5071
  */
4955
5072
 
4956
- __init4() {this._performanceObserver = null;}
5073
+ __init5() {this._performanceObserver = null;}
4957
5074
 
4958
- __init5() {this._flushLock = null;}
5075
+ __init6() {this._flushLock = null;}
4959
5076
 
4960
5077
  /**
4961
5078
  * Timestamp of the last user activity. This lives across sessions.
4962
5079
  */
4963
- __init6() {this._lastActivity = new Date().getTime();}
5080
+ __init7() {this._lastActivity = new Date().getTime();}
4964
5081
 
4965
5082
  /**
4966
5083
  * Is the integration currently active?
4967
5084
  */
4968
- __init7() {this._isEnabled = false;}
5085
+ __init8() {this._isEnabled = false;}
4969
5086
 
4970
5087
  /**
4971
5088
  * Paused is a state where:
4972
5089
  * - DOM Recording is not listening at all
4973
5090
  * - Nothing will be added to event buffer (e.g. core SDK events)
4974
5091
  */
4975
- __init8() {this._isPaused = false;}
5092
+ __init9() {this._isPaused = false;}
4976
5093
 
4977
5094
  /**
4978
5095
  * Have we attached listeners to the core SDK?
4979
5096
  * Note we have to track this as there is no way to remove instrumentation handlers.
4980
5097
  */
4981
- __init9() {this._hasInitializedCoreListeners = false;}
5098
+ __init10() {this._hasInitializedCoreListeners = false;}
4982
5099
 
4983
5100
  /**
4984
5101
  * Function to stop recording
4985
5102
  */
4986
- __init10() {this._stopRecording = null;}
5103
+ __init11() {this._stopRecording = null;}
4987
5104
 
4988
- __init11() {this._context = {
5105
+ __init12() {this._context = {
4989
5106
  errorIds: new Set(),
4990
5107
  traceIds: new Set(),
4991
5108
  urls: [],
@@ -5035,7 +5152,7 @@ class ReplayContainer {
5035
5152
  * _performanceObserver, Recording, Sentry SDK, etc)
5036
5153
  */
5037
5154
  start() {
5038
- this._setInitialState();
5155
+ this.setInitialState();
5039
5156
 
5040
5157
  if (!this._loadAndCheckSession()) {
5041
5158
  return;
@@ -5087,7 +5204,24 @@ class ReplayContainer {
5087
5204
  // Without this, it would record forever, until an error happens, which we don't want
5088
5205
  // instead, we'll always keep the last 60 seconds of replay before an error happened
5089
5206
  ...(this.recordingMode === 'error' && { checkoutEveryNms: ERROR_CHECKOUT_TIME }),
5090
- emit: this._handleRecordingEmit,
5207
+ emit: getHandleRecordingEmit(this),
5208
+ onMutation: (mutations) => {
5209
+ if (this._options._experiments.captureMutationSize) {
5210
+ const count = mutations.length;
5211
+
5212
+ if (count > 500) {
5213
+ const breadcrumb = createBreadcrumb({
5214
+ category: 'replay.mutations',
5215
+ data: {
5216
+ count,
5217
+ },
5218
+ });
5219
+ this._createCustomBreadcrumb(breadcrumb);
5220
+ }
5221
+ }
5222
+ // `true` means we use the regular mutation handling by rrweb
5223
+ return true;
5224
+ },
5091
5225
  });
5092
5226
  } catch (err) {
5093
5227
  this._handleException(err);
@@ -5251,14 +5385,14 @@ class ReplayContainer {
5251
5385
  * Returns true if session is not expired, false otherwise.
5252
5386
  * @hidden
5253
5387
  */
5254
- checkAndHandleExpiredSession(expiry) {
5388
+ checkAndHandleExpiredSession() {
5255
5389
  const oldSessionId = this.getSessionId();
5256
5390
 
5257
5391
  // Prevent starting a new session if the last user activity is older than
5258
5392
  // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
5259
5393
  // session+recording. This creates noisy replays that do not have much
5260
5394
  // content in them.
5261
- if (this._lastActivity && isExpired(this._lastActivity, MAX_SESSION_LIFE)) {
5395
+ if (this._lastActivity && isExpired(this._lastActivity, this.timeouts.maxSessionLife)) {
5262
5396
  // Pause recording
5263
5397
  this.pause();
5264
5398
  return;
@@ -5266,7 +5400,7 @@ class ReplayContainer {
5266
5400
 
5267
5401
  // --- There is recent user activity --- //
5268
5402
  // This will create a new session if expired, based on expiry length
5269
- if (!this._loadAndCheckSession(expiry)) {
5403
+ if (!this._loadAndCheckSession()) {
5270
5404
  return;
5271
5405
  }
5272
5406
 
@@ -5283,6 +5417,25 @@ class ReplayContainer {
5283
5417
  return false;
5284
5418
  }
5285
5419
 
5420
+ /**
5421
+ * Capture some initial state that can change throughout the lifespan of the
5422
+ * replay. This is required because otherwise they would be captured at the
5423
+ * first flush.
5424
+ */
5425
+ setInitialState() {
5426
+ const urlPath = `${WINDOW.location.pathname}${WINDOW.location.hash}${WINDOW.location.search}`;
5427
+ const url = `${WINDOW.location.origin}${urlPath}`;
5428
+
5429
+ this.performanceEvents = [];
5430
+
5431
+ // Reset _context as well
5432
+ this._clearContext();
5433
+
5434
+ this._context.initialUrl = url;
5435
+ this._context.initialTimestamp = new Date().getTime();
5436
+ this._context.urls.push(url);
5437
+ }
5438
+
5286
5439
  /** A wrapper to conditionally capture exceptions. */
5287
5440
  _handleException(error) {
5288
5441
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', error);
@@ -5296,9 +5449,9 @@ class ReplayContainer {
5296
5449
  * Loads (or refreshes) the current session.
5297
5450
  * Returns false if session is not recorded.
5298
5451
  */
5299
- _loadAndCheckSession(expiry = SESSION_IDLE_DURATION) {
5452
+ _loadAndCheckSession() {
5300
5453
  const { type, session } = getSession({
5301
- expiry,
5454
+ timeouts: this.timeouts,
5302
5455
  stickySession: Boolean(this._options.stickySession),
5303
5456
  currentSession: this.session,
5304
5457
  sessionSampleRate: this._options.sessionSampleRate,
@@ -5308,7 +5461,7 @@ class ReplayContainer {
5308
5461
  // If session was newly created (i.e. was not loaded from storage), then
5309
5462
  // enable flag to create the root replay
5310
5463
  if (type === 'new') {
5311
- this._setInitialState();
5464
+ this.setInitialState();
5312
5465
  }
5313
5466
 
5314
5467
  const currentSessionId = this.getSessionId();
@@ -5326,25 +5479,6 @@ class ReplayContainer {
5326
5479
  return true;
5327
5480
  }
5328
5481
 
5329
- /**
5330
- * Capture some initial state that can change throughout the lifespan of the
5331
- * replay. This is required because otherwise they would be captured at the
5332
- * first flush.
5333
- */
5334
- _setInitialState() {
5335
- const urlPath = `${WINDOW.location.pathname}${WINDOW.location.hash}${WINDOW.location.search}`;
5336
- const url = `${WINDOW.location.origin}${urlPath}`;
5337
-
5338
- this.performanceEvents = [];
5339
-
5340
- // Reset _context as well
5341
- this._clearContext();
5342
-
5343
- this._context.initialUrl = url;
5344
- this._context.initialTimestamp = new Date().getTime();
5345
- this._context.urls.push(url);
5346
- }
5347
-
5348
5482
  /**
5349
5483
  * Adds listeners to record events for the replay
5350
5484
  */
@@ -5396,72 +5530,6 @@ class ReplayContainer {
5396
5530
  }
5397
5531
  }
5398
5532
 
5399
- /**
5400
- * Handler for recording events.
5401
- *
5402
- * Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
5403
- */
5404
- __init12() {this._handleRecordingEmit = (
5405
- event,
5406
- isCheckout,
5407
- ) => {
5408
- // If this is false, it means session is expired, create and a new session and wait for checkout
5409
- if (!this.checkAndHandleExpiredSession()) {
5410
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] Received replay event after session expired.');
5411
-
5412
- return;
5413
- }
5414
-
5415
- this.addUpdate(() => {
5416
- // The session is always started immediately on pageload/init, but for
5417
- // error-only replays, it should reflect the most recent checkout
5418
- // when an error occurs. Clear any state that happens before this current
5419
- // checkout. This needs to happen before `addEvent()` which updates state
5420
- // dependent on this reset.
5421
- if (this.recordingMode === 'error' && event.type === 2) {
5422
- this._setInitialState();
5423
- }
5424
-
5425
- // We need to clear existing events on a checkout, otherwise they are
5426
- // incremental event updates and should be appended
5427
- void addEvent(this, event, isCheckout);
5428
-
5429
- // Different behavior for full snapshots (type=2), ignore other event types
5430
- // See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
5431
- if (event.type !== 2) {
5432
- return false;
5433
- }
5434
-
5435
- // If there is a previousSessionId after a full snapshot occurs, then
5436
- // the replay session was started due to session expiration. The new session
5437
- // is started before triggering a new checkout and contains the id
5438
- // of the previous session. Do not immediately flush in this case
5439
- // to avoid capturing only the checkout and instead the replay will
5440
- // be captured if they perform any follow-up actions.
5441
- if (this.session && this.session.previousSessionId) {
5442
- return true;
5443
- }
5444
-
5445
- // See note above re: session start needs to reflect the most recent
5446
- // checkout.
5447
- if (this.recordingMode === 'error' && this.session && this._context.earliestEvent) {
5448
- this.session.started = this._context.earliestEvent;
5449
- this._maybeSaveSession();
5450
- }
5451
-
5452
- // Flush immediately so that we do not miss the first segment, otherwise
5453
- // it can prevent loading on the UI. This will cause an increase in short
5454
- // replays (e.g. opening and closing a tab quickly), but these can be
5455
- // filtered on the UI.
5456
- if (this.recordingMode === 'session') {
5457
- // We want to ensure the worker is ready, as otherwise we'd always send the first event uncompressed
5458
- void this.flushImmediate();
5459
- }
5460
-
5461
- return true;
5462
- });
5463
- };}
5464
-
5465
5533
  /**
5466
5534
  * Handle when visibility of the page content changes. Opening a new tab will
5467
5535
  * cause the state to change to hidden because of content of current page will
@@ -5510,7 +5578,7 @@ class ReplayContainer {
5510
5578
  return;
5511
5579
  }
5512
5580
 
5513
- const expired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
5581
+ const expired = isSessionExpired(this.session, this.timeouts);
5514
5582
 
5515
5583
  if (breadcrumb && !expired) {
5516
5584
  this._createCustomBreadcrumb(breadcrumb);
@@ -5530,10 +5598,10 @@ class ReplayContainer {
5530
5598
  return;
5531
5599
  }
5532
5600
 
5533
- const isSessionActive = this.checkAndHandleExpiredSession(VISIBILITY_CHANGE_TIMEOUT);
5601
+ const isSessionActive = this.checkAndHandleExpiredSession();
5534
5602
 
5535
5603
  if (!isSessionActive) {
5536
- // If the user has come back to the page within VISIBILITY_CHANGE_TIMEOUT
5604
+ // If the user has come back to the page within SESSION_IDLE_DURATION
5537
5605
  // ms, we will re-use the existing session, otherwise create a new
5538
5606
  // session
5539
5607
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Document has become active, but session has expired');