@sentry/replay 7.112.1 → 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/cjs/index.js CHANGED
@@ -718,7 +718,7 @@ function serializeTextNode(n, options) {
718
718
  const forceMask = needMaskingText(n, maskTextClass, maskTextSelector, unmaskTextClass, unmaskTextSelector, maskAllText);
719
719
  if (!isStyle && !isScript && !isTextarea && textContent && forceMask) {
720
720
  textContent = maskTextFn
721
- ? maskTextFn(textContent)
721
+ ? maskTextFn(textContent, n.parentElement)
722
722
  : textContent.replace(/[\S]/g, '*');
723
723
  }
724
724
  if (isTextarea && textContent && (maskInputOptions.textarea || forceMask)) {
@@ -1310,14 +1310,14 @@ function throttle$1(func, wait, options = {}) {
1310
1310
  const context = this;
1311
1311
  if (remaining <= 0 || remaining > wait) {
1312
1312
  if (timeout) {
1313
- clearTimeout(timeout);
1313
+ clearTimeout$1(timeout);
1314
1314
  timeout = null;
1315
1315
  }
1316
1316
  previous = now;
1317
1317
  func.apply(context, args);
1318
1318
  }
1319
1319
  else if (!timeout && options.trailing !== false) {
1320
- timeout = setTimeout(() => {
1320
+ timeout = setTimeout$1(() => {
1321
1321
  previous = options.leading === false ? 0 : Date.now();
1322
1322
  timeout = null;
1323
1323
  func.apply(context, args);
@@ -1331,7 +1331,7 @@ function hookSetter(target, key, d, isRevoked, win = window) {
1331
1331
  ? d
1332
1332
  : {
1333
1333
  set(value) {
1334
- setTimeout(() => {
1334
+ setTimeout$1(() => {
1335
1335
  d.set.call(this, value);
1336
1336
  }, 0);
1337
1337
  if (original && original.set) {
@@ -1403,15 +1403,23 @@ function getWindowWidth() {
1403
1403
  (document.documentElement && document.documentElement.clientWidth) ||
1404
1404
  (document.body && document.body.clientWidth));
1405
1405
  }
1406
- function isBlocked(node, blockClass, blockSelector, unblockSelector, checkAncestors) {
1406
+ function closestElementOfNode(node) {
1407
1407
  if (!node) {
1408
- return false;
1408
+ return null;
1409
1409
  }
1410
1410
  const el = node.nodeType === node.ELEMENT_NODE
1411
1411
  ? node
1412
1412
  : node.parentElement;
1413
- if (!el)
1413
+ return el;
1414
+ }
1415
+ function isBlocked(node, blockClass, blockSelector, unblockSelector, checkAncestors) {
1416
+ if (!node) {
1417
+ return false;
1418
+ }
1419
+ const el = closestElementOfNode(node);
1420
+ if (!el) {
1414
1421
  return false;
1422
+ }
1415
1423
  const blockedPredicate = createMatchPredicate(blockClass, blockSelector);
1416
1424
  if (!checkAncestors) {
1417
1425
  const isUnblocked = unblockSelector && el.matches(unblockSelector);
@@ -1557,33 +1565,39 @@ function inDom(n) {
1557
1565
  return false;
1558
1566
  return doc.contains(n) || shadowHostInDom(n);
1559
1567
  }
1560
- let cachedRequestAnimationFrameImplementation;
1561
- function getRequestAnimationFrameImplementation() {
1562
- if (cachedRequestAnimationFrameImplementation) {
1563
- return cachedRequestAnimationFrameImplementation;
1568
+ const cachedImplementations = {};
1569
+ function getImplementation(name) {
1570
+ const cached = cachedImplementations[name];
1571
+ if (cached) {
1572
+ return cached;
1564
1573
  }
1565
1574
  const document = window.document;
1566
- let requestAnimationFrameImplementation = window.requestAnimationFrame;
1575
+ let impl = window[name];
1567
1576
  if (document && typeof document.createElement === 'function') {
1568
1577
  try {
1569
1578
  const sandbox = document.createElement('iframe');
1570
1579
  sandbox.hidden = true;
1571
1580
  document.head.appendChild(sandbox);
1572
1581
  const contentWindow = sandbox.contentWindow;
1573
- if (contentWindow && contentWindow.requestAnimationFrame) {
1574
- requestAnimationFrameImplementation =
1575
- contentWindow.requestAnimationFrame;
1582
+ if (contentWindow && contentWindow[name]) {
1583
+ impl =
1584
+ contentWindow[name];
1576
1585
  }
1577
1586
  document.head.removeChild(sandbox);
1578
1587
  }
1579
1588
  catch (e) {
1580
1589
  }
1581
1590
  }
1582
- return (cachedRequestAnimationFrameImplementation =
1583
- requestAnimationFrameImplementation.bind(window));
1591
+ return (cachedImplementations[name] = impl.bind(window));
1584
1592
  }
1585
1593
  function onRequestAnimationFrame(...rest) {
1586
- return getRequestAnimationFrameImplementation()(...rest);
1594
+ return getImplementation('requestAnimationFrame')(...rest);
1595
+ }
1596
+ function setTimeout$1(...rest) {
1597
+ return getImplementation('setTimeout')(...rest);
1598
+ }
1599
+ function clearTimeout$1(...rest) {
1600
+ return getImplementation('clearTimeout')(...rest);
1587
1601
  }
1588
1602
 
1589
1603
  var EventType = /* @__PURE__ */ ((EventType2) => {
@@ -1732,6 +1746,7 @@ class MutationBuffer {
1732
1746
  this.locked = false;
1733
1747
  this.texts = [];
1734
1748
  this.attributes = [];
1749
+ this.attributeMap = new WeakMap();
1735
1750
  this.removes = [];
1736
1751
  this.mapRemoves = [];
1737
1752
  this.movedMap = {};
@@ -1931,6 +1946,7 @@ class MutationBuffer {
1931
1946
  }
1932
1947
  this.texts = [];
1933
1948
  this.attributes = [];
1949
+ this.attributeMap = new WeakMap();
1934
1950
  this.removes = [];
1935
1951
  this.addedSet = new Set();
1936
1952
  this.movedSet = new Set();
@@ -1942,13 +1958,6 @@ class MutationBuffer {
1942
1958
  if (isIgnored(m.target, this.mirror)) {
1943
1959
  return;
1944
1960
  }
1945
- let unattachedDoc;
1946
- try {
1947
- unattachedDoc = document.implementation.createHTMLDocument();
1948
- }
1949
- catch (e) {
1950
- unattachedDoc = this.doc;
1951
- }
1952
1961
  switch (m.type) {
1953
1962
  case 'characterData': {
1954
1963
  const value = m.target.textContent;
@@ -1957,7 +1966,7 @@ class MutationBuffer {
1957
1966
  this.texts.push({
1958
1967
  value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector, this.unmaskTextClass, this.unmaskTextSelector, this.maskAllText) && value
1959
1968
  ? this.maskTextFn
1960
- ? this.maskTextFn(value)
1969
+ ? this.maskTextFn(value, closestElementOfNode(m.target))
1961
1970
  : value.replace(/[\S]/g, '*')
1962
1971
  : value,
1963
1972
  node: m.target,
@@ -1990,7 +1999,7 @@ class MutationBuffer {
1990
1999
  value === m.oldValue) {
1991
2000
  return;
1992
2001
  }
1993
- let item = this.attributes.find((a) => a.node === m.target);
2002
+ let item = this.attributeMap.get(m.target);
1994
2003
  if (target.tagName === 'IFRAME' &&
1995
2004
  attributeName === 'src' &&
1996
2005
  !this.keepIframeSrcFn(value)) {
@@ -2009,6 +2018,7 @@ class MutationBuffer {
2009
2018
  _unchangedStyles: {},
2010
2019
  };
2011
2020
  this.attributes.push(item);
2021
+ this.attributeMap.set(m.target, item);
2012
2022
  }
2013
2023
  if (attributeName === 'type' &&
2014
2024
  target.tagName === 'INPUT' &&
@@ -2018,7 +2028,16 @@ class MutationBuffer {
2018
2028
  if (!ignoreAttribute(target.tagName, attributeName)) {
2019
2029
  item.attributes[attributeName] = transformAttribute(this.doc, toLowerCase(target.tagName), toLowerCase(attributeName), value, target, this.maskAttributeFn);
2020
2030
  if (attributeName === 'style') {
2021
- const old = unattachedDoc.createElement('span');
2031
+ if (!this.unattachedDoc) {
2032
+ try {
2033
+ this.unattachedDoc =
2034
+ document.implementation.createHTMLDocument();
2035
+ }
2036
+ catch (e) {
2037
+ this.unattachedDoc = this.doc;
2038
+ }
2039
+ }
2040
+ const old = this.unattachedDoc.createElement('span');
2022
2041
  if (m.oldValue) {
2023
2042
  old.setAttribute('style', m.oldValue);
2024
2043
  }
@@ -2904,7 +2923,7 @@ function initFontObserver({ fontCb, doc }) {
2904
2923
  };
2905
2924
  const restoreHandler = patch(doc.fonts, 'add', function (original) {
2906
2925
  return function (fontFace) {
2907
- setTimeout(callbackWrapper(() => {
2926
+ setTimeout$1(callbackWrapper(() => {
2908
2927
  const p = fontMap.get(fontFace);
2909
2928
  if (p) {
2910
2929
  fontCb(p);
@@ -3356,7 +3375,7 @@ class ShadowDomManager {
3356
3375
  doc: shadowRoot,
3357
3376
  mirror: this.mirror,
3358
3377
  }));
3359
- setTimeout(() => {
3378
+ setTimeout$1(() => {
3360
3379
  if (shadowRoot.adoptedStyleSheets &&
3361
3380
  shadowRoot.adoptedStyleSheets.length > 0)
3362
3381
  this.bypassOptions.stylesheetManager.adoptStyleSheets(shadowRoot.adoptedStyleSheets, this.mirror.getId(shadowRoot.host));
@@ -3503,11 +3522,7 @@ class ProcessedNodeManager {
3503
3522
  }
3504
3523
  }
3505
3524
 
3506
- function wrapEvent(e) {
3507
- const eWithTime = e;
3508
- eWithTime.timestamp = nowTimestamp();
3509
- return eWithTime;
3510
- }
3525
+ let wrappedEmit;
3511
3526
  let _takeFullSnapshot;
3512
3527
  const mirror = createMirror();
3513
3528
  function record(options = {}) {
@@ -3590,7 +3605,9 @@ function record(options = {}) {
3590
3605
  }
3591
3606
  return e;
3592
3607
  };
3593
- const wrappedEmit = (e, isCheckout) => {
3608
+ wrappedEmit = (r, isCheckout) => {
3609
+ const e = r;
3610
+ e.timestamp = nowTimestamp();
3594
3611
  if (_optionalChain([mutationBuffers, 'access', _ => _[0], 'optionalAccess', _2 => _2.isFrozen, 'call', _3 => _3()]) &&
3595
3612
  e.type !== EventType.FullSnapshot &&
3596
3613
  !(e.type === EventType.IncrementalSnapshot &&
@@ -3629,35 +3646,35 @@ function record(options = {}) {
3629
3646
  }
3630
3647
  };
3631
3648
  const wrappedMutationEmit = (m) => {
3632
- wrappedEmit(wrapEvent({
3649
+ wrappedEmit({
3633
3650
  type: EventType.IncrementalSnapshot,
3634
3651
  data: {
3635
3652
  source: IncrementalSource.Mutation,
3636
3653
  ...m,
3637
3654
  },
3638
- }));
3655
+ });
3639
3656
  };
3640
- const wrappedScrollEmit = (p) => wrappedEmit(wrapEvent({
3657
+ const wrappedScrollEmit = (p) => wrappedEmit({
3641
3658
  type: EventType.IncrementalSnapshot,
3642
3659
  data: {
3643
3660
  source: IncrementalSource.Scroll,
3644
3661
  ...p,
3645
3662
  },
3646
- }));
3647
- const wrappedCanvasMutationEmit = (p) => wrappedEmit(wrapEvent({
3663
+ });
3664
+ const wrappedCanvasMutationEmit = (p) => wrappedEmit({
3648
3665
  type: EventType.IncrementalSnapshot,
3649
3666
  data: {
3650
3667
  source: IncrementalSource.CanvasMutation,
3651
3668
  ...p,
3652
3669
  },
3653
- }));
3654
- const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit(wrapEvent({
3670
+ });
3671
+ const wrappedAdoptedStyleSheetEmit = (a) => wrappedEmit({
3655
3672
  type: EventType.IncrementalSnapshot,
3656
3673
  data: {
3657
3674
  source: IncrementalSource.AdoptedStyleSheet,
3658
3675
  ...a,
3659
3676
  },
3660
- }));
3677
+ });
3661
3678
  const stylesheetManager = new StylesheetManager({
3662
3679
  mutationCb: wrappedMutationEmit,
3663
3680
  adoptedStyleSheetCb: wrappedAdoptedStyleSheetEmit,
@@ -3683,13 +3700,13 @@ function record(options = {}) {
3683
3700
  const canvasManager = _getCanvasManager(getCanvasManager, {
3684
3701
  mirror,
3685
3702
  win: window,
3686
- mutationCb: (p) => wrappedEmit(wrapEvent({
3703
+ mutationCb: (p) => wrappedEmit({
3687
3704
  type: EventType.IncrementalSnapshot,
3688
3705
  data: {
3689
3706
  source: IncrementalSource.CanvasMutation,
3690
3707
  ...p,
3691
3708
  },
3692
- })),
3709
+ }),
3693
3710
  recordCanvas,
3694
3711
  blockClass,
3695
3712
  blockSelector,
@@ -3734,14 +3751,14 @@ function record(options = {}) {
3734
3751
  mirror,
3735
3752
  });
3736
3753
  const takeFullSnapshot = (isCheckout = false) => {
3737
- wrappedEmit(wrapEvent({
3754
+ wrappedEmit({
3738
3755
  type: EventType.Meta,
3739
3756
  data: {
3740
3757
  href: window.location.href,
3741
3758
  width: getWindowWidth(),
3742
3759
  height: getWindowHeight(),
3743
3760
  },
3744
- }), isCheckout);
3761
+ }, isCheckout);
3745
3762
  stylesheetManager.reset();
3746
3763
  shadowDomManager.init();
3747
3764
  mutationBuffers.forEach((buf) => buf.lock());
@@ -3787,13 +3804,13 @@ function record(options = {}) {
3787
3804
  if (!node) {
3788
3805
  return console.warn('Failed to snapshot the document');
3789
3806
  }
3790
- wrappedEmit(wrapEvent({
3807
+ wrappedEmit({
3791
3808
  type: EventType.FullSnapshot,
3792
3809
  data: {
3793
3810
  node,
3794
3811
  initialOffset: getWindowScroll(window),
3795
3812
  },
3796
- }));
3813
+ });
3797
3814
  mutationBuffers.forEach((buf) => buf.unlock());
3798
3815
  if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
3799
3816
  stylesheetManager.adoptStyleSheets(document.adoptedStyleSheets, mirror.getId(document));
@@ -3805,81 +3822,81 @@ function record(options = {}) {
3805
3822
  return callbackWrapper(initObservers)({
3806
3823
  onMutation,
3807
3824
  mutationCb: wrappedMutationEmit,
3808
- mousemoveCb: (positions, source) => wrappedEmit(wrapEvent({
3825
+ mousemoveCb: (positions, source) => wrappedEmit({
3809
3826
  type: EventType.IncrementalSnapshot,
3810
3827
  data: {
3811
3828
  source,
3812
3829
  positions,
3813
3830
  },
3814
- })),
3815
- mouseInteractionCb: (d) => wrappedEmit(wrapEvent({
3831
+ }),
3832
+ mouseInteractionCb: (d) => wrappedEmit({
3816
3833
  type: EventType.IncrementalSnapshot,
3817
3834
  data: {
3818
3835
  source: IncrementalSource.MouseInteraction,
3819
3836
  ...d,
3820
3837
  },
3821
- })),
3838
+ }),
3822
3839
  scrollCb: wrappedScrollEmit,
3823
- viewportResizeCb: (d) => wrappedEmit(wrapEvent({
3840
+ viewportResizeCb: (d) => wrappedEmit({
3824
3841
  type: EventType.IncrementalSnapshot,
3825
3842
  data: {
3826
3843
  source: IncrementalSource.ViewportResize,
3827
3844
  ...d,
3828
3845
  },
3829
- })),
3830
- inputCb: (v) => wrappedEmit(wrapEvent({
3846
+ }),
3847
+ inputCb: (v) => wrappedEmit({
3831
3848
  type: EventType.IncrementalSnapshot,
3832
3849
  data: {
3833
3850
  source: IncrementalSource.Input,
3834
3851
  ...v,
3835
3852
  },
3836
- })),
3837
- mediaInteractionCb: (p) => wrappedEmit(wrapEvent({
3853
+ }),
3854
+ mediaInteractionCb: (p) => wrappedEmit({
3838
3855
  type: EventType.IncrementalSnapshot,
3839
3856
  data: {
3840
3857
  source: IncrementalSource.MediaInteraction,
3841
3858
  ...p,
3842
3859
  },
3843
- })),
3844
- styleSheetRuleCb: (r) => wrappedEmit(wrapEvent({
3860
+ }),
3861
+ styleSheetRuleCb: (r) => wrappedEmit({
3845
3862
  type: EventType.IncrementalSnapshot,
3846
3863
  data: {
3847
3864
  source: IncrementalSource.StyleSheetRule,
3848
3865
  ...r,
3849
3866
  },
3850
- })),
3851
- styleDeclarationCb: (r) => wrappedEmit(wrapEvent({
3867
+ }),
3868
+ styleDeclarationCb: (r) => wrappedEmit({
3852
3869
  type: EventType.IncrementalSnapshot,
3853
3870
  data: {
3854
3871
  source: IncrementalSource.StyleDeclaration,
3855
3872
  ...r,
3856
3873
  },
3857
- })),
3874
+ }),
3858
3875
  canvasMutationCb: wrappedCanvasMutationEmit,
3859
- fontCb: (p) => wrappedEmit(wrapEvent({
3876
+ fontCb: (p) => wrappedEmit({
3860
3877
  type: EventType.IncrementalSnapshot,
3861
3878
  data: {
3862
3879
  source: IncrementalSource.Font,
3863
3880
  ...p,
3864
3881
  },
3865
- })),
3882
+ }),
3866
3883
  selectionCb: (p) => {
3867
- wrappedEmit(wrapEvent({
3884
+ wrappedEmit({
3868
3885
  type: EventType.IncrementalSnapshot,
3869
3886
  data: {
3870
3887
  source: IncrementalSource.Selection,
3871
3888
  ...p,
3872
3889
  },
3873
- }));
3890
+ });
3874
3891
  },
3875
3892
  customElementCb: (c) => {
3876
- wrappedEmit(wrapEvent({
3893
+ wrappedEmit({
3877
3894
  type: EventType.IncrementalSnapshot,
3878
3895
  data: {
3879
3896
  source: IncrementalSource.CustomElement,
3880
3897
  ...c,
3881
3898
  },
3882
- }));
3899
+ });
3883
3900
  },
3884
3901
  blockClass,
3885
3902
  ignoreClass,
@@ -3917,13 +3934,13 @@ function record(options = {}) {
3917
3934
  , 'optionalAccess', _7 => _7.map, 'call', _8 => _8((p) => ({
3918
3935
  observer: p.observer,
3919
3936
  options: p.options,
3920
- callback: (payload) => wrappedEmit(wrapEvent({
3937
+ callback: (payload) => wrappedEmit({
3921
3938
  type: EventType.Plugin,
3922
3939
  data: {
3923
3940
  plugin: p.name,
3924
3941
  payload,
3925
3942
  },
3926
- })),
3943
+ }),
3927
3944
  }))]) || [],
3928
3945
  }, {});
3929
3946
  };
@@ -3945,18 +3962,18 @@ function record(options = {}) {
3945
3962
  }
3946
3963
  else {
3947
3964
  handlers.push(on('DOMContentLoaded', () => {
3948
- wrappedEmit(wrapEvent({
3965
+ wrappedEmit({
3949
3966
  type: EventType.DomContentLoaded,
3950
3967
  data: {},
3951
- }));
3968
+ });
3952
3969
  if (recordAfter === 'DOMContentLoaded')
3953
3970
  init();
3954
3971
  }));
3955
3972
  handlers.push(on('load', () => {
3956
- wrappedEmit(wrapEvent({
3973
+ wrappedEmit({
3957
3974
  type: EventType.Load,
3958
3975
  data: {},
3959
- }));
3976
+ });
3960
3977
  if (recordAfter === 'load')
3961
3978
  init();
3962
3979
  }, window));