@sentry/replay 7.112.2 → 7.113.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
@@ -712,7 +712,7 @@ function serializeTextNode(n, options) {
712
712
  const forceMask = needMaskingText(n, maskTextClass, maskTextSelector, unmaskTextClass, unmaskTextSelector, maskAllText);
713
713
  if (!isStyle && !isScript && !isTextarea && textContent && forceMask) {
714
714
  textContent = maskTextFn
715
- ? maskTextFn(textContent)
715
+ ? maskTextFn(textContent, n.parentElement)
716
716
  : textContent.replace(/[\S]/g, '*');
717
717
  }
718
718
  if (isTextarea && textContent && (maskInputOptions.textarea || forceMask)) {
@@ -1304,14 +1304,14 @@ function throttle$1(func, wait, options = {}) {
1304
1304
  const context = this;
1305
1305
  if (remaining <= 0 || remaining > wait) {
1306
1306
  if (timeout) {
1307
- clearTimeout(timeout);
1307
+ clearTimeout$1(timeout);
1308
1308
  timeout = null;
1309
1309
  }
1310
1310
  previous = now;
1311
1311
  func.apply(context, args);
1312
1312
  }
1313
1313
  else if (!timeout && options.trailing !== false) {
1314
- timeout = setTimeout(() => {
1314
+ timeout = setTimeout$1(() => {
1315
1315
  previous = options.leading === false ? 0 : Date.now();
1316
1316
  timeout = null;
1317
1317
  func.apply(context, args);
@@ -1325,7 +1325,7 @@ function hookSetter(target, key, d, isRevoked, win = window) {
1325
1325
  ? d
1326
1326
  : {
1327
1327
  set(value) {
1328
- setTimeout(() => {
1328
+ setTimeout$1(() => {
1329
1329
  d.set.call(this, value);
1330
1330
  }, 0);
1331
1331
  if (original && original.set) {
@@ -1397,15 +1397,23 @@ function getWindowWidth() {
1397
1397
  (document.documentElement && document.documentElement.clientWidth) ||
1398
1398
  (document.body && document.body.clientWidth));
1399
1399
  }
1400
- function isBlocked(node, blockClass, blockSelector, unblockSelector, checkAncestors) {
1400
+ function closestElementOfNode(node) {
1401
1401
  if (!node) {
1402
- return false;
1402
+ return null;
1403
1403
  }
1404
1404
  const el = node.nodeType === node.ELEMENT_NODE
1405
1405
  ? node
1406
1406
  : node.parentElement;
1407
- if (!el)
1407
+ return el;
1408
+ }
1409
+ function isBlocked(node, blockClass, blockSelector, unblockSelector, checkAncestors) {
1410
+ if (!node) {
1411
+ return false;
1412
+ }
1413
+ const el = closestElementOfNode(node);
1414
+ if (!el) {
1408
1415
  return false;
1416
+ }
1409
1417
  const blockedPredicate = createMatchPredicate(blockClass, blockSelector);
1410
1418
  if (!checkAncestors) {
1411
1419
  const isUnblocked = unblockSelector && el.matches(unblockSelector);
@@ -1551,33 +1559,39 @@ function inDom(n) {
1551
1559
  return false;
1552
1560
  return doc.contains(n) || shadowHostInDom(n);
1553
1561
  }
1554
- let cachedRequestAnimationFrameImplementation;
1555
- function getRequestAnimationFrameImplementation() {
1556
- if (cachedRequestAnimationFrameImplementation) {
1557
- return cachedRequestAnimationFrameImplementation;
1562
+ const cachedImplementations = {};
1563
+ function getImplementation(name) {
1564
+ const cached = cachedImplementations[name];
1565
+ if (cached) {
1566
+ return cached;
1558
1567
  }
1559
1568
  const document = window.document;
1560
- let requestAnimationFrameImplementation = window.requestAnimationFrame;
1569
+ let impl = window[name];
1561
1570
  if (document && typeof document.createElement === 'function') {
1562
1571
  try {
1563
1572
  const sandbox = document.createElement('iframe');
1564
1573
  sandbox.hidden = true;
1565
1574
  document.head.appendChild(sandbox);
1566
1575
  const contentWindow = sandbox.contentWindow;
1567
- if (contentWindow && contentWindow.requestAnimationFrame) {
1568
- requestAnimationFrameImplementation =
1569
- contentWindow.requestAnimationFrame;
1576
+ if (contentWindow && contentWindow[name]) {
1577
+ impl =
1578
+ contentWindow[name];
1570
1579
  }
1571
1580
  document.head.removeChild(sandbox);
1572
1581
  }
1573
1582
  catch (e) {
1574
1583
  }
1575
1584
  }
1576
- return (cachedRequestAnimationFrameImplementation =
1577
- requestAnimationFrameImplementation.bind(window));
1585
+ return (cachedImplementations[name] = impl.bind(window));
1578
1586
  }
1579
1587
  function onRequestAnimationFrame(...rest) {
1580
- return getRequestAnimationFrameImplementation()(...rest);
1588
+ return getImplementation('requestAnimationFrame')(...rest);
1589
+ }
1590
+ function setTimeout$1(...rest) {
1591
+ return getImplementation('setTimeout')(...rest);
1592
+ }
1593
+ function clearTimeout$1(...rest) {
1594
+ return getImplementation('clearTimeout')(...rest);
1581
1595
  }
1582
1596
 
1583
1597
  var EventType = /* @__PURE__ */ ((EventType2) => {
@@ -1726,6 +1740,7 @@ class MutationBuffer {
1726
1740
  this.locked = false;
1727
1741
  this.texts = [];
1728
1742
  this.attributes = [];
1743
+ this.attributeMap = new WeakMap();
1729
1744
  this.removes = [];
1730
1745
  this.mapRemoves = [];
1731
1746
  this.movedMap = {};
@@ -1925,6 +1940,7 @@ class MutationBuffer {
1925
1940
  }
1926
1941
  this.texts = [];
1927
1942
  this.attributes = [];
1943
+ this.attributeMap = new WeakMap();
1928
1944
  this.removes = [];
1929
1945
  this.addedSet = new Set();
1930
1946
  this.movedSet = new Set();
@@ -1936,13 +1952,6 @@ class MutationBuffer {
1936
1952
  if (isIgnored(m.target, this.mirror)) {
1937
1953
  return;
1938
1954
  }
1939
- let unattachedDoc;
1940
- try {
1941
- unattachedDoc = document.implementation.createHTMLDocument();
1942
- }
1943
- catch (e) {
1944
- unattachedDoc = this.doc;
1945
- }
1946
1955
  switch (m.type) {
1947
1956
  case 'characterData': {
1948
1957
  const value = m.target.textContent;
@@ -1951,7 +1960,7 @@ class MutationBuffer {
1951
1960
  this.texts.push({
1952
1961
  value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector, this.unmaskTextClass, this.unmaskTextSelector, this.maskAllText) && value
1953
1962
  ? this.maskTextFn
1954
- ? this.maskTextFn(value)
1963
+ ? this.maskTextFn(value, closestElementOfNode(m.target))
1955
1964
  : value.replace(/[\S]/g, '*')
1956
1965
  : value,
1957
1966
  node: m.target,
@@ -1984,7 +1993,7 @@ class MutationBuffer {
1984
1993
  value === m.oldValue) {
1985
1994
  return;
1986
1995
  }
1987
- let item = this.attributes.find((a) => a.node === m.target);
1996
+ let item = this.attributeMap.get(m.target);
1988
1997
  if (target.tagName === 'IFRAME' &&
1989
1998
  attributeName === 'src' &&
1990
1999
  !this.keepIframeSrcFn(value)) {
@@ -2003,6 +2012,7 @@ class MutationBuffer {
2003
2012
  _unchangedStyles: {},
2004
2013
  };
2005
2014
  this.attributes.push(item);
2015
+ this.attributeMap.set(m.target, item);
2006
2016
  }
2007
2017
  if (attributeName === 'type' &&
2008
2018
  target.tagName === 'INPUT' &&
@@ -2012,7 +2022,16 @@ class MutationBuffer {
2012
2022
  if (!ignoreAttribute(target.tagName, attributeName)) {
2013
2023
  item.attributes[attributeName] = transformAttribute(this.doc, toLowerCase(target.tagName), toLowerCase(attributeName), value, target, this.maskAttributeFn);
2014
2024
  if (attributeName === 'style') {
2015
- const old = unattachedDoc.createElement('span');
2025
+ if (!this.unattachedDoc) {
2026
+ try {
2027
+ this.unattachedDoc =
2028
+ document.implementation.createHTMLDocument();
2029
+ }
2030
+ catch (e) {
2031
+ this.unattachedDoc = this.doc;
2032
+ }
2033
+ }
2034
+ const old = this.unattachedDoc.createElement('span');
2016
2035
  if (m.oldValue) {
2017
2036
  old.setAttribute('style', m.oldValue);
2018
2037
  }
@@ -2898,7 +2917,7 @@ function initFontObserver({ fontCb, doc }) {
2898
2917
  };
2899
2918
  const restoreHandler = patch(doc.fonts, 'add', function (original) {
2900
2919
  return function (fontFace) {
2901
- setTimeout(callbackWrapper(() => {
2920
+ setTimeout$1(callbackWrapper(() => {
2902
2921
  const p = fontMap.get(fontFace);
2903
2922
  if (p) {
2904
2923
  fontCb(p);
@@ -3350,7 +3369,7 @@ class ShadowDomManager {
3350
3369
  doc: shadowRoot,
3351
3370
  mirror: this.mirror,
3352
3371
  }));
3353
- setTimeout(() => {
3372
+ setTimeout$1(() => {
3354
3373
  if (shadowRoot.adoptedStyleSheets &&
3355
3374
  shadowRoot.adoptedStyleSheets.length > 0)
3356
3375
  this.bypassOptions.stylesheetManager.adoptStyleSheets(shadowRoot.adoptedStyleSheets, this.mirror.getId(shadowRoot.host));
@@ -3497,11 +3516,7 @@ class ProcessedNodeManager {
3497
3516
  }
3498
3517
  }
3499
3518
 
3500
- function wrapEvent(e) {
3501
- const eWithTime = e;
3502
- eWithTime.timestamp = nowTimestamp();
3503
- return eWithTime;
3504
- }
3519
+ let wrappedEmit;
3505
3520
  let _takeFullSnapshot;
3506
3521
  const mirror = createMirror();
3507
3522
  function record(options = {}) {
@@ -3584,7 +3599,9 @@ function record(options = {}) {
3584
3599
  }
3585
3600
  return e;
3586
3601
  };
3587
- const wrappedEmit = (e, isCheckout) => {
3602
+ wrappedEmit = (r, isCheckout) => {
3603
+ const e = r;
3604
+ e.timestamp = nowTimestamp();
3588
3605
  if (_optionalChain([mutationBuffers, 'access', _ => _[0], 'optionalAccess', _2 => _2.isFrozen, 'call', _3 => _3()]) &&
3589
3606
  e.type !== EventType.FullSnapshot &&
3590
3607
  !(e.type === EventType.IncrementalSnapshot &&
@@ -3623,35 +3640,35 @@ function record(options = {}) {
3623
3640
  }
3624
3641
  };
3625
3642
  const wrappedMutationEmit = (m) => {
3626
- wrappedEmit(wrapEvent({
3643
+ wrappedEmit({
3627
3644
  type: EventType.IncrementalSnapshot,
3628
3645
  data: {
3629
3646
  source: IncrementalSource.Mutation,
3630
3647
  ...m,
3631
3648
  },
3632
- }));
3649
+ });
3633
3650
  };
3634
- const wrappedScrollEmit = (p) => wrappedEmit(wrapEvent({
3651
+ const wrappedScrollEmit = (p) => wrappedEmit({
3635
3652
  type: EventType.IncrementalSnapshot,
3636
3653
  data: {
3637
3654
  source: IncrementalSource.Scroll,
3638
3655
  ...p,
3639
3656
  },
3640
- }));
3641
- const wrappedCanvasMutationEmit = (p) => wrappedEmit(wrapEvent({
3657
+ });
3658
+ const wrappedCanvasMutationEmit = (p) => wrappedEmit({
3642
3659
  type: EventType.IncrementalSnapshot,
3643
3660
  data: {
3644
3661
  source: IncrementalSource.CanvasMutation,
3645
3662
  ...p,
3646
3663
  },
3647
- }));
3648
- const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit(wrapEvent({
3664
+ });
3665
+ const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit({
3649
3666
  type: EventType.IncrementalSnapshot,
3650
3667
  data: {
3651
3668
  source: IncrementalSource.AdoptedStyleSheet,
3652
3669
  ...a,
3653
3670
  },
3654
- }));
3671
+ });
3655
3672
  const stylesheetManager = new StylesheetManager({
3656
3673
  mutationCb: wrappedMutationEmit,
3657
3674
  adoptedStyleSheetCb: wrappedAdoptedStyleSheetEmit,
@@ -3677,13 +3694,13 @@ function record(options = {}) {
3677
3694
  const canvasManager = _getCanvasManager(getCanvasManager, {
3678
3695
  mirror,
3679
3696
  win: window,
3680
- mutationCb: (p) => wrappedEmit(wrapEvent({
3697
+ mutationCb: (p) => wrappedEmit({
3681
3698
  type: EventType.IncrementalSnapshot,
3682
3699
  data: {
3683
3700
  source: IncrementalSource.CanvasMutation,
3684
3701
  ...p,
3685
3702
  },
3686
- })),
3703
+ }),
3687
3704
  recordCanvas,
3688
3705
  blockClass,
3689
3706
  blockSelector,
@@ -3728,14 +3745,14 @@ function record(options = {}) {
3728
3745
  mirror,
3729
3746
  });
3730
3747
  const takeFullSnapshot = (isCheckout = false) => {
3731
- wrappedEmit(wrapEvent({
3748
+ wrappedEmit({
3732
3749
  type: EventType.Meta,
3733
3750
  data: {
3734
3751
  href: window.location.href,
3735
3752
  width: getWindowWidth(),
3736
3753
  height: getWindowHeight(),
3737
3754
  },
3738
- }), isCheckout);
3755
+ }, isCheckout);
3739
3756
  stylesheetManager.reset();
3740
3757
  shadowDomManager.init();
3741
3758
  mutationBuffers.forEach((buf) => buf.lock());
@@ -3781,13 +3798,13 @@ function record(options = {}) {
3781
3798
  if (!node) {
3782
3799
  return console.warn('Failed to snapshot the document');
3783
3800
  }
3784
- wrappedEmit(wrapEvent({
3801
+ wrappedEmit({
3785
3802
  type: EventType.FullSnapshot,
3786
3803
  data: {
3787
3804
  node,
3788
3805
  initialOffset: getWindowScroll(window),
3789
3806
  },
3790
- }));
3807
+ });
3791
3808
  mutationBuffers.forEach((buf) => buf.unlock());
3792
3809
  if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
3793
3810
  stylesheetManager.adoptStyleSheets(document.adoptedStyleSheets, mirror.getId(document));
@@ -3799,81 +3816,81 @@ function record(options = {}) {
3799
3816
  return callbackWrapper(initObservers)({
3800
3817
  onMutation,
3801
3818
  mutationCb: wrappedMutationEmit,
3802
- mousemoveCb: (positions, source) => wrappedEmit(wrapEvent({
3819
+ mousemoveCb: (positions, source) => wrappedEmit({
3803
3820
  type: EventType.IncrementalSnapshot,
3804
3821
  data: {
3805
3822
  source,
3806
3823
  positions,
3807
3824
  },
3808
- })),
3809
- mouseInteractionCb: (d) => wrappedEmit(wrapEvent({
3825
+ }),
3826
+ mouseInteractionCb: (d) => wrappedEmit({
3810
3827
  type: EventType.IncrementalSnapshot,
3811
3828
  data: {
3812
3829
  source: IncrementalSource.MouseInteraction,
3813
3830
  ...d,
3814
3831
  },
3815
- })),
3832
+ }),
3816
3833
  scrollCb: wrappedScrollEmit,
3817
- viewportResizeCb: (d) => wrappedEmit(wrapEvent({
3834
+ viewportResizeCb: (d) => wrappedEmit({
3818
3835
  type: EventType.IncrementalSnapshot,
3819
3836
  data: {
3820
3837
  source: IncrementalSource.ViewportResize,
3821
3838
  ...d,
3822
3839
  },
3823
- })),
3824
- inputCb: (v) => wrappedEmit(wrapEvent({
3840
+ }),
3841
+ inputCb: (v) => wrappedEmit({
3825
3842
  type: EventType.IncrementalSnapshot,
3826
3843
  data: {
3827
3844
  source: IncrementalSource.Input,
3828
3845
  ...v,
3829
3846
  },
3830
- })),
3831
- mediaInteractionCb: (p) => wrappedEmit(wrapEvent({
3847
+ }),
3848
+ mediaInteractionCb: (p) => wrappedEmit({
3832
3849
  type: EventType.IncrementalSnapshot,
3833
3850
  data: {
3834
3851
  source: IncrementalSource.MediaInteraction,
3835
3852
  ...p,
3836
3853
  },
3837
- })),
3838
- styleSheetRuleCb: (r) => wrappedEmit(wrapEvent({
3854
+ }),
3855
+ styleSheetRuleCb: (r) => wrappedEmit({
3839
3856
  type: EventType.IncrementalSnapshot,
3840
3857
  data: {
3841
3858
  source: IncrementalSource.StyleSheetRule,
3842
3859
  ...r,
3843
3860
  },
3844
- })),
3845
- styleDeclarationCb: (r) => wrappedEmit(wrapEvent({
3861
+ }),
3862
+ styleDeclarationCb: (r) => wrappedEmit({
3846
3863
  type: EventType.IncrementalSnapshot,
3847
3864
  data: {
3848
3865
  source: IncrementalSource.StyleDeclaration,
3849
3866
  ...r,
3850
3867
  },
3851
- })),
3868
+ }),
3852
3869
  canvasMutationCb: wrappedCanvasMutationEmit,
3853
- fontCb: (p) => wrappedEmit(wrapEvent({
3870
+ fontCb: (p) => wrappedEmit({
3854
3871
  type: EventType.IncrementalSnapshot,
3855
3872
  data: {
3856
3873
  source: IncrementalSource.Font,
3857
3874
  ...p,
3858
3875
  },
3859
- })),
3876
+ }),
3860
3877
  selectionCb: (p) => {
3861
- wrappedEmit(wrapEvent({
3878
+ wrappedEmit({
3862
3879
  type: EventType.IncrementalSnapshot,
3863
3880
  data: {
3864
3881
  source: IncrementalSource.Selection,
3865
3882
  ...p,
3866
3883
  },
3867
- }));
3884
+ });
3868
3885
  },
3869
3886
  customElementCb: (c) => {
3870
- wrappedEmit(wrapEvent({
3887
+ wrappedEmit({
3871
3888
  type: EventType.IncrementalSnapshot,
3872
3889
  data: {
3873
3890
  source: IncrementalSource.CustomElement,
3874
3891
  ...c,
3875
3892
  },
3876
- }));
3893
+ });
3877
3894
  },
3878
3895
  blockClass,
3879
3896
  ignoreClass,
@@ -3911,13 +3928,13 @@ function record(options = {}) {
3911
3928
  , 'optionalAccess', _7 => _7.map, 'call', _8 => _8((p) => ({
3912
3929
  observer: p.observer,
3913
3930
  options: p.options,
3914
- callback: (payload) => wrappedEmit(wrapEvent({
3931
+ callback: (payload) => wrappedEmit({
3915
3932
  type: EventType.Plugin,
3916
3933
  data: {
3917
3934
  plugin: p.name,
3918
3935
  payload,
3919
3936
  },
3920
- })),
3937
+ }),
3921
3938
  }))]) || [],
3922
3939
  }, {});
3923
3940
  };
@@ -3939,18 +3956,18 @@ function record(options = {}) {
3939
3956
  }
3940
3957
  else {
3941
3958
  handlers.push(on('DOMContentLoaded', () => {
3942
- wrappedEmit(wrapEvent({
3959
+ wrappedEmit({
3943
3960
  type: EventType.DomContentLoaded,
3944
3961
  data: {},
3945
- }));
3962
+ });
3946
3963
  if (recordAfter === 'DOMContentLoaded')
3947
3964
  init();
3948
3965
  }));
3949
3966
  handlers.push(on('load', () => {
3950
- wrappedEmit(wrapEvent({
3967
+ wrappedEmit({
3951
3968
  type: EventType.Load,
3952
3969
  data: {},
3953
- }));
3970
+ });
3954
3971
  if (recordAfter === 'load')
3955
3972
  init();
3956
3973
  }, window));