@sentry/replay 7.52.1 → 7.53.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
@@ -195,17 +195,17 @@ The following options can be configured as options to the integration, in `new R
195
195
 
196
196
  The following options can be configured as options to the integration, in `new Replay({})`:
197
197
 
198
- | key | type | default | description |
199
- | ---------------- | ------------------------ | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200
- | maskAllText | boolean | `true` | Mask _all_ text content. Will pass text content through `maskTextFn` before sending to server. |
201
- | maskAllInputs | boolean | `true` | Mask values of `<input>` elements. Passes input values through `maskInputFn` before sending to server. |
202
- | blockAllMedia | boolean | `true` | Block _all_ media elements (`img, svg, video, object, picture, embed, map, audio`)
203
- | maskTextFn | (text: string) => string | `(text) => '*'.repeat(text.length)` | Function to customize how text content is masked before sending to server. By default, masks text with `*`. |
204
- | block | Array<string> | `.sentry-block, [data-sentry-block]` | Redact any elements that match the DOM selectors. See [privacy](#blocking) section for an example. |
205
- | unblock | Array<string> | `.sentry-unblock, [data-sentry-unblock]`| Do not redact any elements that match the DOM selectors. Useful when using `blockAllMedia`. See [privacy](#blocking) section for an example. |
206
- | mask | Array<string> | `.sentry-mask, [data-sentry-mask]` | Mask all elements that match the given DOM selectors. See [privacy](#masking) section for an example. |
207
- | unmask | Array<string> | `.sentry-unmask, [data-sentry-unmask]` | Unmask all elements that match the given DOM selectors. Useful when using `maskAllText`. See [privacy](#masking) section for an example. |
208
- | ignore | Array<string> | `.sentry-ignore, [data-sentry-ignore]` | Ignores all events on the matching input fields. See [privacy](#ignoring) section for an example. |
198
+ | key | type | default | description |
199
+ | ---------------- | ------------------------ | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
200
+ | maskAllText | boolean | `true` | Mask _all_ text content. Will pass text content through `maskFn` before sending to server. |
201
+ | maskAllInputs | boolean | `true` | Mask values of `<input>` elements. Passes input values through `maskInputFn` before sending to server. |
202
+ | blockAllMedia | boolean | `true` | Block _all_ media elements (`img, svg, video, object, picture, embed, map, audio`) |
203
+ | maskFn | (text: string) => string | `(text) => '*'.repeat(text.length)` | Function to customize how text content is masked before sending to server. By default, masks text with `*`. |
204
+ | block | Array<string> | `.sentry-block, [data-sentry-block]` | Redact any elements that match the DOM selectors. See [privacy](#blocking) section for an example. |
205
+ | unblock | Array<string> | `.sentry-unblock, [data-sentry-unblock]`| Do not redact any elements that match the DOM selectors. Useful when using `blockAllMedia`. See [privacy](#blocking) section for an example. |
206
+ | mask | Array<string> | `.sentry-mask, [data-sentry-mask]` | Mask all elements that match the given DOM selectors. See [privacy](#masking) section for an example. |
207
+ | unmask | Array<string> | `.sentry-unmask, [data-sentry-unmask]` | Unmask all elements that match the given DOM selectors. Useful when using `maskAllText`. See [privacy](#masking) section for an example. |
208
+ | ignore | Array<string> | `.sentry-ignore, [data-sentry-ignore]` | Ignores all events on the matching input fields. See [privacy](#ignoring) section for an example. |
209
209
 
210
210
  #### Deprecated options
211
211
  In order to streamline our privacy options, the following have been deprecated in favor for the respective options above.
package/cjs/index.js CHANGED
@@ -3287,6 +3287,23 @@ var NodeType;
3287
3287
  NodeType[NodeType["Comment"] = 5] = "Comment";
3288
3288
  })(NodeType || (NodeType = {}));
3289
3289
 
3290
+ /* eslint-disable @typescript-eslint/naming-convention */
3291
+
3292
+ var EventType; (function (EventType) {
3293
+ const DomContentLoaded = 0; EventType[EventType["DomContentLoaded"] = DomContentLoaded] = "DomContentLoaded";
3294
+ const Load = 1; EventType[EventType["Load"] = Load] = "Load";
3295
+ const FullSnapshot = 2; EventType[EventType["FullSnapshot"] = FullSnapshot] = "FullSnapshot";
3296
+ const IncrementalSnapshot = 3; EventType[EventType["IncrementalSnapshot"] = IncrementalSnapshot] = "IncrementalSnapshot";
3297
+ const Meta = 4; EventType[EventType["Meta"] = Meta] = "Meta";
3298
+ const Custom = 5; EventType[EventType["Custom"] = Custom] = "Custom";
3299
+ const Plugin = 6; EventType[EventType["Plugin"] = Plugin] = "Plugin";
3300
+ })(EventType || (EventType = {}));
3301
+
3302
+ /**
3303
+ * This is a partial copy of rrweb's eventWithTime type which only contains the properties
3304
+ * we specifcally need in the SDK.
3305
+ */
3306
+
3290
3307
  /**
3291
3308
  * Converts a timestamp to ms, if it was in s, or keeps it as ms.
3292
3309
  */
@@ -3329,7 +3346,18 @@ async function addEvent(
3329
3346
  replay.eventBuffer.clear();
3330
3347
  }
3331
3348
 
3332
- return await replay.eventBuffer.addEvent(event);
3349
+ const replayOptions = replay.getOptions();
3350
+
3351
+ const eventAfterPossibleCallback =
3352
+ typeof replayOptions.beforeAddRecordingEvent === 'function' && event.type === EventType.Custom
3353
+ ? replayOptions.beforeAddRecordingEvent(event)
3354
+ : event;
3355
+
3356
+ if (!eventAfterPossibleCallback) {
3357
+ return;
3358
+ }
3359
+
3360
+ return await replay.eventBuffer.addEvent(eventAfterPossibleCallback);
3333
3361
  } catch (error) {
3334
3362
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error(error);
3335
3363
  await replay.stop('addEvent');
@@ -6305,23 +6333,6 @@ function debounce(func, wait, options) {
6305
6333
  return debounced;
6306
6334
  }
6307
6335
 
6308
- /* eslint-disable @typescript-eslint/naming-convention */
6309
-
6310
- var EventType; (function (EventType) {
6311
- const DomContentLoaded = 0; EventType[EventType["DomContentLoaded"] = DomContentLoaded] = "DomContentLoaded";
6312
- const Load = 1; EventType[EventType["Load"] = Load] = "Load";
6313
- const FullSnapshot = 2; EventType[EventType["FullSnapshot"] = FullSnapshot] = "FullSnapshot";
6314
- const IncrementalSnapshot = 3; EventType[EventType["IncrementalSnapshot"] = IncrementalSnapshot] = "IncrementalSnapshot";
6315
- const Meta = 4; EventType[EventType["Meta"] = Meta] = "Meta";
6316
- const Custom = 5; EventType[EventType["Custom"] = Custom] = "Custom";
6317
- const Plugin = 6; EventType[EventType["Plugin"] = Plugin] = "Plugin";
6318
- })(EventType || (EventType = {}));
6319
-
6320
- /**
6321
- * This is a partial copy of rrweb's eventWithTime type which only contains the properties
6322
- * we specifcally need in the SDK.
6323
- */
6324
-
6325
6336
  /**
6326
6337
  * Handler for recording events.
6327
6338
  *
@@ -6395,6 +6406,30 @@ function getHandleRecordingEmit(replay) {
6395
6406
  }
6396
6407
  }
6397
6408
 
6409
+ const options = replay.getOptions();
6410
+
6411
+ // TODO: We want this as an experiment so that we can test
6412
+ // internally and create metrics before making this the default
6413
+ if (options._experiments.delayFlushOnCheckout) {
6414
+ // If the full snapshot is due to an initial load, we will not have
6415
+ // a previous session ID. In this case, we want to buffer events
6416
+ // for a set amount of time before flushing. This can help avoid
6417
+ // capturing replays of users that immediately close the window.
6418
+ setTimeout(() => replay.conditionalFlush(), options._experiments.delayFlushOnCheckout);
6419
+
6420
+ // Cancel any previously debounced flushes to ensure there are no [near]
6421
+ // simultaneous flushes happening. The latter request should be
6422
+ // insignificant in this case, so wait for additional user interaction to
6423
+ // trigger a new flush.
6424
+ //
6425
+ // This can happen because there's no guarantee that a recording event
6426
+ // happens first. e.g. a mouse click can happen and trigger a debounced
6427
+ // flush before the checkout.
6428
+ replay.cancelFlush();
6429
+
6430
+ return true;
6431
+ }
6432
+
6398
6433
  // Flush immediately so that we do not miss the first segment, otherwise
6399
6434
  // it can prevent loading on the UI. This will cause an increase in short
6400
6435
  // replays (e.g. opening and closing a tab quickly), but these can be
@@ -7160,7 +7195,17 @@ class ReplayContainer {
7160
7195
  }
7161
7196
 
7162
7197
  /**
7163
- *
7198
+ * Only flush if `this.recordingMode === 'session'`
7199
+ */
7200
+ conditionalFlush() {
7201
+ if (this.recordingMode === 'buffer') {
7202
+ return Promise.resolve();
7203
+ }
7204
+
7205
+ return this.flushImmediate();
7206
+ }
7207
+
7208
+ /**
7164
7209
  * Always flush via `_debouncedFlush` so that we do not have flushes triggered
7165
7210
  * from calling both `flush` and `_debouncedFlush`. Otherwise, there could be
7166
7211
  * cases of mulitple flushes happening closely together.
@@ -7171,6 +7216,13 @@ class ReplayContainer {
7171
7216
  return this._debouncedFlush.flush() ;
7172
7217
  }
7173
7218
 
7219
+ /**
7220
+ * Cancels queued up flushes.
7221
+ */
7222
+ cancelFlush() {
7223
+ this._debouncedFlush.cancel();
7224
+ }
7225
+
7174
7226
  /** Get the current sesion (=replay) ID */
7175
7227
  getSessionId() {
7176
7228
  return this.session && this.session.id;
@@ -7420,7 +7472,7 @@ class ReplayContainer {
7420
7472
  // Send replay when the page/tab becomes hidden. There is no reason to send
7421
7473
  // replay if it becomes visible, since no actions we care about were done
7422
7474
  // while it was hidden
7423
- this._conditionalFlush();
7475
+ void this.conditionalFlush();
7424
7476
  }
7425
7477
 
7426
7478
  /**
@@ -7504,17 +7556,6 @@ class ReplayContainer {
7504
7556
  return Promise.all(createPerformanceSpans(this, createPerformanceEntries(entries)));
7505
7557
  }
7506
7558
 
7507
- /**
7508
- * Only flush if `this.recordingMode === 'session'`
7509
- */
7510
- _conditionalFlush() {
7511
- if (this.recordingMode === 'buffer') {
7512
- return;
7513
- }
7514
-
7515
- void this.flushImmediate();
7516
- }
7517
-
7518
7559
  /**
7519
7560
  * Clear _context
7520
7561
  */
@@ -7876,6 +7917,8 @@ class Replay {
7876
7917
  ignore = [],
7877
7918
  maskFn,
7878
7919
 
7920
+ beforeAddRecordingEvent,
7921
+
7879
7922
  // eslint-disable-next-line deprecation/deprecation
7880
7923
  blockClass,
7881
7924
  // eslint-disable-next-line deprecation/deprecation
@@ -7933,6 +7976,7 @@ class Replay {
7933
7976
  networkCaptureBodies,
7934
7977
  networkRequestHeaders: _getMergedNetworkHeaders(networkRequestHeaders),
7935
7978
  networkResponseHeaders: _getMergedNetworkHeaders(networkResponseHeaders),
7979
+ beforeAddRecordingEvent,
7936
7980
 
7937
7981
  _experiments,
7938
7982
  };