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