@sentry/replay 7.59.3 → 7.60.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/cjs/index.js CHANGED
@@ -48,6 +48,11 @@ const SLOW_CLICK_SCROLL_TIMEOUT = 300;
48
48
  /** When encountering a total segment size exceeding this size, stop the replay (as we cannot properly ingest it). */
49
49
  const REPLAY_MAX_EVENT_BUFFER_SIZE = 20000000; // ~20MB
50
50
 
51
+ /** Replays must be min. 5s long before we send them. */
52
+ const MIN_REPLAY_DURATION = 4999;
53
+ /* The max. allowed value that the minReplayDuration can be set to. */
54
+ const MIN_REPLAY_DURATION_LIMIT = 15000;
55
+
51
56
  var NodeType$1;
52
57
  (function (NodeType) {
53
58
  NodeType[NodeType["Document"] = 0] = "Document";
@@ -3272,6 +3277,22 @@ record.takeFullSnapshot = (isCheckout) => {
3272
3277
  };
3273
3278
  record.mirror = mirror;
3274
3279
 
3280
+ /**
3281
+ * Converts a timestamp to ms, if it was in s, or keeps it as ms.
3282
+ */
3283
+ function timestampToMs(timestamp) {
3284
+ const isMs = timestamp > 9999999999;
3285
+ return isMs ? timestamp : timestamp * 1000;
3286
+ }
3287
+
3288
+ /**
3289
+ * Converts a timestamp to s, if it was in ms, or keeps it as s.
3290
+ */
3291
+ function timestampToS(timestamp) {
3292
+ const isMs = timestamp > 9999999999;
3293
+ return isMs ? timestamp / 1000 : timestamp;
3294
+ }
3295
+
3275
3296
  /**
3276
3297
  * Add a breadcrumb event to replay.
3277
3298
  */
@@ -3471,7 +3492,7 @@ class ClickDetector {
3471
3492
  }
3472
3493
 
3473
3494
  const newClick = {
3474
- timestamp: breadcrumb.timestamp,
3495
+ timestamp: timestampToS(breadcrumb.timestamp),
3475
3496
  clickBreadcrumb: breadcrumb,
3476
3497
  // Set this to 0 so we know it originates from the click breadcrumb
3477
3498
  clickCount: 0,
@@ -3511,6 +3532,7 @@ class ClickDetector {
3511
3532
  click.scrollAfter = click.timestamp <= this._lastScroll ? this._lastScroll - click.timestamp : undefined;
3512
3533
  }
3513
3534
 
3535
+ // All of these are in seconds!
3514
3536
  if (click.timestamp + this._timeout <= now) {
3515
3537
  timedOutClicks.push(click);
3516
3538
  }
@@ -3518,10 +3540,10 @@ class ClickDetector {
3518
3540
 
3519
3541
  // Remove "old" clicks
3520
3542
  for (const click of timedOutClicks) {
3521
- this._generateBreadcrumbs(click);
3522
-
3523
3543
  const pos = this._clicks.indexOf(click);
3524
- if (pos !== -1) {
3544
+
3545
+ if (pos > -1) {
3546
+ this._generateBreadcrumbs(click);
3525
3547
  this._clicks.splice(pos, 1);
3526
3548
  }
3527
3549
  }
@@ -3713,8 +3735,16 @@ const handleDomListener = (
3713
3735
 
3714
3736
  const isClick = handlerData.name === 'click';
3715
3737
  const event = isClick && (handlerData.event );
3716
- // Ignore clicks if ctrl/alt/meta keys are held down as they alter behavior of clicks (e.g. open in new tab)
3717
- if (isClick && replay.clickDetector && event && !event.altKey && !event.metaKey && !event.ctrlKey) {
3738
+ // Ignore clicks if ctrl/alt/meta/shift keys are held down as they alter behavior of clicks (e.g. open in new tab)
3739
+ if (
3740
+ isClick &&
3741
+ replay.clickDetector &&
3742
+ event &&
3743
+ !event.altKey &&
3744
+ !event.metaKey &&
3745
+ !event.ctrlKey &&
3746
+ !event.shiftKey
3747
+ ) {
3718
3748
  handleClick(
3719
3749
  replay.clickDetector,
3720
3750
  result ,
@@ -3986,14 +4016,6 @@ function t(t){let e=t.length;for(;--e>=0;)t[e]=0}const e=new Uint8Array([0,0,0,0
3986
4016
 
3987
4017
  function e(){const e=new Blob([r]);return URL.createObjectURL(e)}
3988
4018
 
3989
- /**
3990
- * Converts a timestamp to ms, if it was in s, or keeps it as ms.
3991
- */
3992
- function timestampToMs(timestamp) {
3993
- const isMs = timestamp > 9999999999;
3994
- return isMs ? timestamp : timestamp * 1000;
3995
- }
3996
-
3997
4019
  /** This error indicates that the event buffer size exceeded the limit.. */
3998
4020
  class EventBufferSizeExceededError extends Error {
3999
4021
  constructor() {
@@ -6606,6 +6628,11 @@ function getHandleRecordingEmit(replay) {
6606
6628
  if (replay.recordingMode === 'buffer' && replay.session && replay.eventBuffer) {
6607
6629
  const earliestEvent = replay.eventBuffer.getEarliestTimestamp();
6608
6630
  if (earliestEvent) {
6631
+ // eslint-disable-next-line no-console
6632
+ const log = replay.getOptions()._experiments.traceInternals ? console.info : utils.logger.info;
6633
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&
6634
+ log(`[Replay] Updating session start time to earliest event in buffer at ${earliestEvent}`);
6635
+
6609
6636
  replay.session.started = earliestEvent;
6610
6637
 
6611
6638
  if (replay.getOptions().stickySession) {
@@ -7387,6 +7414,10 @@ class ReplayContainer {
7387
7414
 
7388
7415
  const activityTime = Date.now();
7389
7416
 
7417
+ // eslint-disable-next-line no-console
7418
+ const log = this.getOptions()._experiments.traceInternals ? console.info : utils.logger.info;
7419
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && log(`[Replay] Converting buffer to session, starting at ${activityTime}`);
7420
+
7390
7421
  // Allow flush to complete before resuming as a session recording, otherwise
7391
7422
  // the checkout from `startRecording` may be included in the payload.
7392
7423
  // Prefer to keep the error replay as a separate (and smaller) segment
@@ -8056,6 +8087,23 @@ class ReplayContainer {
8056
8087
  return;
8057
8088
  }
8058
8089
 
8090
+ const start = this.session.started;
8091
+ const now = Date.now();
8092
+ const duration = now - start;
8093
+
8094
+ // If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
8095
+ // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
8096
+ if (duration < this._options.minReplayDuration || duration > this.timeouts.maxSessionLife + 5000) {
8097
+ // eslint-disable-next-line no-console
8098
+ const log = this.getOptions()._experiments.traceInternals ? console.warn : utils.logger.warn;
8099
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&
8100
+ log(
8101
+ `[Replay] Session duration (${Math.floor(duration / 1000)}s) is too short or too long, not sending replay.`,
8102
+ );
8103
+
8104
+ return;
8105
+ }
8106
+
8059
8107
  // A flush is about to happen, cancel any queued flushes
8060
8108
  this._debouncedFlush.cancel();
8061
8109
 
@@ -8258,6 +8306,7 @@ class Replay {
8258
8306
  constructor({
8259
8307
  flushMinDelay = DEFAULT_FLUSH_MIN_DELAY,
8260
8308
  flushMaxDelay = DEFAULT_FLUSH_MAX_DELAY,
8309
+ minReplayDuration = MIN_REPLAY_DURATION,
8261
8310
  stickySession = true,
8262
8311
  useCompression = true,
8263
8312
  _experiments = {},
@@ -8334,6 +8383,7 @@ class Replay {
8334
8383
  this._initialOptions = {
8335
8384
  flushMinDelay,
8336
8385
  flushMaxDelay,
8386
+ minReplayDuration: Math.min(minReplayDuration, MIN_REPLAY_DURATION_LIMIT),
8337
8387
  stickySession,
8338
8388
  sessionSampleRate,
8339
8389
  errorSampleRate,