@appsurify-testmap/rrweb 2.0.0-alpha.35 → 2.0.0-alpha.40

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/dist/rrweb.cjs CHANGED
@@ -527,7 +527,7 @@ function getXPath(node2) {
527
527
  return "/html/body";
528
528
  }
529
529
  const parentNode2 = element.parentNode;
530
- if (!parentNode2 || !(parentNode2 instanceof Element)) {
530
+ if (!parentNode2) {
531
531
  return "";
532
532
  }
533
533
  const siblings = Array.from(parentNode2.children).filter(
@@ -589,14 +589,19 @@ function isTextVisible(n2) {
589
589
  return textContent2 !== "";
590
590
  }
591
591
  function isElementVisible(n2) {
592
- return isStyleVisible(n2) && isRectVisible(n2.getBoundingClientRect());
593
- }
594
- function isStyleVisible(n2) {
595
- const style = window.getComputedStyle(n2);
596
- return style.display !== "none" && style.visibility !== "hidden" && parseFloat(style.opacity) !== 0;
592
+ var _a2;
593
+ const win = ((_a2 = n2.ownerDocument) == null ? void 0 : _a2.defaultView) ?? null;
594
+ const style = win ? win.getComputedStyle(n2) : null;
595
+ const isStyleVisible = style != null && style.display !== "none" && style.visibility !== "hidden" && parseFloat(style.opacity) !== 0;
596
+ const rect = n2.getBoundingClientRect();
597
+ const result2 = isStyleVisible && isRectVisible(rect, win);
598
+ return result2;
597
599
  }
598
- function isRectVisible(rect) {
599
- return rect.width > 0 && rect.height > 0 && rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
600
+ function isRectVisible(rect, win) {
601
+ var _a2, _b, _c, _d;
602
+ const height = (win == null ? void 0 : win.innerHeight) ?? ((_b = (_a2 = win == null ? void 0 : win.document) == null ? void 0 : _a2.documentElement) == null ? void 0 : _b.clientHeight) ?? 0;
603
+ const width = (win == null ? void 0 : win.innerWidth) ?? ((_d = (_c = win == null ? void 0 : win.document) == null ? void 0 : _c.documentElement) == null ? void 0 : _d.clientWidth) ?? 0;
604
+ return rect.width > 0 && rect.height > 0 && rect.top >= 0 && rect.left >= 0 && rect.bottom <= height && rect.right <= width;
600
605
  }
601
606
  const interactiveEvents$1 = [
602
607
  "change",
@@ -636,7 +641,7 @@ const interactiveTags = [
636
641
  "video",
637
642
  "audio"
638
643
  ];
639
- const inlineEventAttributes$1 = [
644
+ const inlineEventAttributes = [
640
645
  "onclick",
641
646
  "ondblclick",
642
647
  "onmousedown",
@@ -679,7 +684,6 @@ function hasEventListeners(n2) {
679
684
  return n2 instanceof Element && interactiveElementsRegistry$1.has(n2);
680
685
  }
681
686
  function isElementInteractive(n2) {
682
- var _a2;
683
687
  if (n2.nodeType === Node.ELEMENT_NODE) {
684
688
  const element = n2;
685
689
  const tagName = element.tagName.toLowerCase();
@@ -693,30 +697,35 @@ function isElementInteractive(n2) {
693
697
  const result2 = hasEventListeners(element) || hasTabIndex || hasRoleInteractive || element instanceof HTMLAnchorElement && element.hasAttribute("href") || element instanceof HTMLButtonElement && !element.disabled;
694
698
  return result2;
695
699
  }
696
- if (n2.nodeType === Node.TEXT_NODE) {
697
- const textNode = n2;
698
- const parentElement2 = textNode.parentElement;
699
- if (parentElement2 !== null && interactiveTags.includes(parentElement2.tagName.toLowerCase())) {
700
- return true;
701
- }
702
- return parentElement2 !== null && isElementVisible(parentElement2) && ((_a2 = textNode.textContent) == null ? void 0 : _a2.trim().length) !== 0 && isElementInteractive(parentElement2);
703
- }
704
700
  return false;
705
701
  }
706
- function inspectInlineEventHandlers$1() {
707
- const allElements = document.querySelectorAll("*");
702
+ function inspectInlineEventHandlers(doc) {
703
+ if (!doc || typeof doc.querySelectorAll !== "function") return;
704
+ const allElements = doc.querySelectorAll("*");
708
705
  allElements.forEach((el) => {
709
- inlineEventAttributes$1.forEach((attr) => {
706
+ inlineEventAttributes.forEach((attr) => {
710
707
  if (el.hasAttribute(attr)) {
711
708
  interactiveElementsRegistry$1.add(el);
712
709
  }
713
710
  });
714
711
  });
715
712
  }
716
- if (document.readyState === "complete" || document.readyState === "interactive") {
717
- inspectInlineEventHandlers$1();
718
- } else {
719
- document.addEventListener("DOMContentLoaded", inspectInlineEventHandlers$1);
713
+ function scheduleInlineEventInspection(doc) {
714
+ if (!doc || typeof doc.addEventListener !== "function" || typeof doc.querySelectorAll !== "function") {
715
+ return;
716
+ }
717
+ try {
718
+ if (doc.readyState === "complete" || doc.readyState === "interactive") {
719
+ inspectInlineEventHandlers(doc);
720
+ } else {
721
+ doc.addEventListener("DOMContentLoaded", () => inspectInlineEventHandlers(doc), {
722
+ once: true,
723
+ capture: false
724
+ });
725
+ }
726
+ } catch (e2) {
727
+ console.warn("[inlineEventInspection] Failed to inspect document:", e2);
728
+ }
720
729
  }
721
730
  let _id = 1;
722
731
  const tagNameRegex = new RegExp("[^a-z0-9-_:]");
@@ -835,9 +844,29 @@ function transformAttribute(doc, tagName, name, value) {
835
844
  }
836
845
  return value;
837
846
  }
838
- function ignoreAttribute(tagName, name, _value) {
847
+ function isIgnoreAttribute(tagName, name, _value) {
839
848
  return (tagName === "video" || tagName === "audio") && name === "autoplay";
840
849
  }
850
+ function cleanAttributes(doc, element, ignoreAttribute) {
851
+ const tagName = getValidTagName$1(element);
852
+ const attributes = {};
853
+ const len = element.attributes.length;
854
+ for (let i2 = 0; i2 < len; i2++) {
855
+ const attr = element.attributes[i2];
856
+ const name = attr.name;
857
+ const value = attr.value;
858
+ const shouldIgnoreByName = typeof ignoreAttribute === "string" ? name === ignoreAttribute : ignoreAttribute.test(name);
859
+ if (!shouldIgnoreByName && !isIgnoreAttribute(tagName, name)) {
860
+ attributes[name] = transformAttribute(
861
+ doc,
862
+ tagName,
863
+ toLowerCase(name),
864
+ value
865
+ );
866
+ }
867
+ }
868
+ return attributes;
869
+ }
841
870
  function _isBlockedElement(element, blockClass, blockSelector) {
842
871
  try {
843
872
  if (typeof blockClass === "string") {
@@ -967,6 +996,7 @@ function serializeNode(n2, options) {
967
996
  mirror: mirror2,
968
997
  blockClass,
969
998
  blockSelector,
999
+ ignoreAttribute,
970
1000
  needsMask,
971
1001
  inlineStylesheet,
972
1002
  maskInputOptions = {},
@@ -1011,6 +1041,7 @@ function serializeNode(n2, options) {
1011
1041
  doc,
1012
1042
  blockClass,
1013
1043
  blockSelector,
1044
+ ignoreAttribute,
1014
1045
  inlineStylesheet,
1015
1046
  maskInputOptions,
1016
1047
  maskInputFn,
@@ -1088,6 +1119,7 @@ function serializeElementNode(n2, options) {
1088
1119
  doc,
1089
1120
  blockClass,
1090
1121
  blockSelector,
1122
+ ignoreAttribute,
1091
1123
  inlineStylesheet,
1092
1124
  maskInputOptions = {},
1093
1125
  maskInputFn,
@@ -1101,19 +1133,7 @@ function serializeElementNode(n2, options) {
1101
1133
  } = options;
1102
1134
  const needBlock = _isBlockedElement(n2, blockClass, blockSelector);
1103
1135
  const tagName = getValidTagName$1(n2);
1104
- let attributes = {};
1105
- const len = n2.attributes.length;
1106
- for (let i2 = 0; i2 < len; i2++) {
1107
- const attr = n2.attributes[i2];
1108
- if (!ignoreAttribute(tagName, attr.name, attr.value)) {
1109
- attributes[attr.name] = transformAttribute(
1110
- doc,
1111
- tagName,
1112
- toLowerCase(attr.name),
1113
- attr.value
1114
- );
1115
- }
1116
- }
1136
+ let attributes = cleanAttributes(doc, n2, ignoreAttribute);
1117
1137
  if (tagName === "link" && inlineStylesheet) {
1118
1138
  const stylesheet = Array.from(doc.styleSheets).find((s2) => {
1119
1139
  return s2.href === n2.href;
@@ -1327,6 +1347,7 @@ function serializeNodeWithId(n2, options) {
1327
1347
  blockSelector,
1328
1348
  maskTextClass,
1329
1349
  maskTextSelector,
1350
+ ignoreAttribute,
1330
1351
  skipChild = false,
1331
1352
  inlineStylesheet = true,
1332
1353
  maskInputOptions = {},
@@ -1361,6 +1382,7 @@ function serializeNodeWithId(n2, options) {
1361
1382
  mirror: mirror2,
1362
1383
  blockClass,
1363
1384
  blockSelector,
1385
+ ignoreAttribute,
1364
1386
  needsMask,
1365
1387
  inlineStylesheet,
1366
1388
  maskInputOptions,
@@ -1413,6 +1435,7 @@ function serializeNodeWithId(n2, options) {
1413
1435
  needsMask,
1414
1436
  maskTextClass,
1415
1437
  maskTextSelector,
1438
+ ignoreAttribute,
1416
1439
  skipChild,
1417
1440
  inlineStylesheet,
1418
1441
  maskInputOptions,
@@ -1472,6 +1495,7 @@ function serializeNodeWithId(n2, options) {
1472
1495
  needsMask,
1473
1496
  maskTextClass,
1474
1497
  maskTextSelector,
1498
+ ignoreAttribute,
1475
1499
  skipChild: false,
1476
1500
  inlineStylesheet,
1477
1501
  maskInputOptions,
@@ -1513,6 +1537,7 @@ function serializeNodeWithId(n2, options) {
1513
1537
  needsMask,
1514
1538
  maskTextClass,
1515
1539
  maskTextSelector,
1540
+ ignoreAttribute,
1516
1541
  skipChild: false,
1517
1542
  inlineStylesheet,
1518
1543
  maskInputOptions,
@@ -1550,6 +1575,7 @@ function snapshot(n2, options) {
1550
1575
  blockSelector = null,
1551
1576
  maskTextClass = "rr-mask",
1552
1577
  maskTextSelector = null,
1578
+ ignoreAttribute = "rr-ignore-attr",
1553
1579
  inlineStylesheet = true,
1554
1580
  inlineImages = false,
1555
1581
  recordCanvas = false,
@@ -1566,6 +1592,7 @@ function snapshot(n2, options) {
1566
1592
  stylesheetLoadTimeout,
1567
1593
  keepIframeSrcFn = () => false
1568
1594
  } = options || {};
1595
+ scheduleInlineEventInspection(n2);
1569
1596
  const maskInputOptions = maskAllInputs === true ? {
1570
1597
  color: true,
1571
1598
  date: true,
@@ -1609,6 +1636,7 @@ function snapshot(n2, options) {
1609
1636
  blockSelector,
1610
1637
  maskTextClass,
1611
1638
  maskTextSelector,
1639
+ ignoreAttribute,
1612
1640
  skipChild: false,
1613
1641
  inlineStylesheet,
1614
1642
  maskInputOptions,
@@ -5684,30 +5712,6 @@ const interactiveEvents = [
5684
5712
  "touchend",
5685
5713
  "touchcancel"
5686
5714
  ];
5687
- const inlineEventAttributes = [
5688
- "onclick",
5689
- "ondblclick",
5690
- "onmousedown",
5691
- "onmouseup",
5692
- "onmouseover",
5693
- "onmouseout",
5694
- "onmousemove",
5695
- "onfocus",
5696
- "onblur",
5697
- "onkeydown",
5698
- "onkeypress",
5699
- "onkeyup",
5700
- "onchange",
5701
- "oninput",
5702
- "onsubmit",
5703
- "onreset",
5704
- "onselect",
5705
- "oncontextmenu",
5706
- "ontouchstart",
5707
- "ontouchmove",
5708
- "ontouchend",
5709
- "ontouchcancel"
5710
- ];
5711
5715
  const interactiveElementsRegistry = /* @__PURE__ */ new WeakSet();
5712
5716
  const originalAddEventListener = EventTarget.prototype.addEventListener;
5713
5717
  EventTarget.prototype.addEventListener = function(type, listener, options) {
@@ -5723,21 +5727,6 @@ const originalRemoveEventListener = EventTarget.prototype.removeEventListener;
5723
5727
  EventTarget.prototype.removeEventListener = function(type, listener, options) {
5724
5728
  originalRemoveEventListener.call(this, type, listener, options);
5725
5729
  };
5726
- function inspectInlineEventHandlers() {
5727
- const allElements = document.querySelectorAll("*");
5728
- allElements.forEach((el) => {
5729
- inlineEventAttributes.forEach((attr) => {
5730
- if (el.hasAttribute(attr)) {
5731
- interactiveElementsRegistry.add(el);
5732
- }
5733
- });
5734
- });
5735
- }
5736
- if (document.readyState === "complete" || document.readyState === "interactive") {
5737
- inspectInlineEventHandlers();
5738
- } else {
5739
- document.addEventListener("DOMContentLoaded", inspectInlineEventHandlers);
5740
- }
5741
5730
  function getDefaultExportFromCjs(x2) {
5742
5731
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
5743
5732
  }
@@ -10813,7 +10802,7 @@ let nowTimestamp = Date.now;
10813
10802
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
10814
10803
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
10815
10804
  }
10816
- function getWindowScroll(win) {
10805
+ function getWindowScroll(win = window) {
10817
10806
  var _a2, _b, _c, _d;
10818
10807
  const doc = win.document;
10819
10808
  return {
@@ -10821,11 +10810,13 @@ function getWindowScroll(win) {
10821
10810
  top: doc.scrollingElement ? doc.scrollingElement.scrollTop : win.pageYOffset !== void 0 ? win.pageYOffset : (doc == null ? void 0 : doc.documentElement.scrollTop) || (doc == null ? void 0 : doc.body) && ((_c = index.parentElement(doc.body)) == null ? void 0 : _c.scrollTop) || ((_d = doc == null ? void 0 : doc.body) == null ? void 0 : _d.scrollTop) || 0
10822
10811
  };
10823
10812
  }
10824
- function getWindowHeight() {
10825
- return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body && document.body.clientHeight;
10813
+ function getWindowHeight(win = window) {
10814
+ const doc = win.document;
10815
+ return win.innerHeight || doc.documentElement && doc.documentElement.clientHeight || doc.body && doc.body.clientHeight || 0;
10826
10816
  }
10827
- function getWindowWidth() {
10828
- return window.innerWidth || document.documentElement && document.documentElement.clientWidth || document.body && document.body.clientWidth;
10817
+ function getWindowWidth(win = window) {
10818
+ const doc = win.document;
10819
+ return win.innerWidth || doc.documentElement && doc.documentElement.clientWidth || doc.body && doc.body.clientWidth || 0;
10829
10820
  }
10830
10821
  function closestElementOfNode(node2) {
10831
10822
  if (!node2) {
@@ -11311,6 +11302,7 @@ class MutationBuffer {
11311
11302
  __publicField(this, "blockSelector");
11312
11303
  __publicField(this, "maskTextClass");
11313
11304
  __publicField(this, "maskTextSelector");
11305
+ __publicField(this, "ignoreAttribute");
11314
11306
  __publicField(this, "inlineStylesheet");
11315
11307
  __publicField(this, "maskInputOptions");
11316
11308
  __publicField(this, "maskTextFn");
@@ -11374,6 +11366,7 @@ class MutationBuffer {
11374
11366
  blockSelector: this.blockSelector,
11375
11367
  maskTextClass: this.maskTextClass,
11376
11368
  maskTextSelector: this.maskTextSelector,
11369
+ ignoreAttribute: this.ignoreAttribute || "",
11377
11370
  skipChild: true,
11378
11371
  newlyAddedElement: true,
11379
11372
  inlineStylesheet: this.inlineStylesheet,
@@ -11602,7 +11595,7 @@ class MutationBuffer {
11602
11595
  if (attributeName === "type" && target.tagName === "INPUT" && (m.oldValue || "").toLowerCase() === "password") {
11603
11596
  target.setAttribute("data-rr-is-password", "true");
11604
11597
  }
11605
- if (!ignoreAttribute(target.tagName, attributeName)) {
11598
+ if (!isIgnoreAttribute(target.tagName, attributeName)) {
11606
11599
  item.attributes[attributeName] = transformAttribute(
11607
11600
  this.doc,
11608
11601
  toLowerCase(target.tagName),
@@ -11724,6 +11717,7 @@ class MutationBuffer {
11724
11717
  "blockSelector",
11725
11718
  "maskTextClass",
11726
11719
  "maskTextSelector",
11720
+ "ignoreAttribute",
11727
11721
  "inlineStylesheet",
11728
11722
  "maskInputOptions",
11729
11723
  "maskTextFn",
@@ -13973,6 +13967,7 @@ function record(options = {}) {
13973
13967
  blockSelector = null,
13974
13968
  ignoreClass = "rr-ignore",
13975
13969
  ignoreSelector = null,
13970
+ ignoreAttribute = "rr-ignore-attribute",
13976
13971
  maskTextClass = "rr-mask",
13977
13972
  maskTextSelector = null,
13978
13973
  inlineStylesheet = true,
@@ -14168,7 +14163,7 @@ function record(options = {}) {
14168
14163
  canvasManager = new CanvasManager({
14169
14164
  recordCanvas,
14170
14165
  mutationCb: wrappedCanvasMutationEmit,
14171
- win: window,
14166
+ win,
14172
14167
  blockClass,
14173
14168
  blockSelector,
14174
14169
  mirror,
@@ -14183,6 +14178,7 @@ function record(options = {}) {
14183
14178
  blockSelector,
14184
14179
  maskTextClass,
14185
14180
  maskTextSelector,
14181
+ ignoreAttribute,
14186
14182
  inlineStylesheet,
14187
14183
  maskInputOptions,
14188
14184
  dataURLOptions,
@@ -14209,8 +14205,8 @@ function record(options = {}) {
14209
14205
  type: EventType.Meta,
14210
14206
  data: {
14211
14207
  href: win.location.href,
14212
- width: getWindowWidth(),
14213
- height: getWindowHeight()
14208
+ width: getWindowWidth(win),
14209
+ height: getWindowHeight(win)
14214
14210
  }
14215
14211
  },
14216
14212
  isCheckout
@@ -14218,7 +14214,7 @@ function record(options = {}) {
14218
14214
  stylesheetManager.reset();
14219
14215
  shadowDomManager.init();
14220
14216
  mutationBuffers.forEach((buf) => buf.lock());
14221
- const node2 = snapshot(document, {
14217
+ const node2 = snapshot(doc, {
14222
14218
  mirror,
14223
14219
  blockClass,
14224
14220
  blockSelector,
@@ -14240,7 +14236,7 @@ function record(options = {}) {
14240
14236
  stylesheetManager.trackLinkElement(n2);
14241
14237
  }
14242
14238
  if (hasShadowRoot(n2)) {
14243
- shadowDomManager.addShadowRoot(index.shadowRoot(n2), document);
14239
+ shadowDomManager.addShadowRoot(index.shadowRoot(n2), doc);
14244
14240
  }
14245
14241
  },
14246
14242
  onIframeLoad: (iframe, childSn) => {
@@ -14260,7 +14256,7 @@ function record(options = {}) {
14260
14256
  type: EventType.FullSnapshot,
14261
14257
  data: {
14262
14258
  node: node2,
14263
- initialOffset: getWindowScroll(window)
14259
+ initialOffset: getWindowScroll(win)
14264
14260
  }
14265
14261
  },
14266
14262
  isCheckout
@@ -14369,6 +14365,7 @@ function record(options = {}) {
14369
14365
  ignoreSelector,
14370
14366
  maskTextClass,
14371
14367
  maskTextSelector,
14368
+ ignoreAttribute,
14372
14369
  maskInputOptions,
14373
14370
  inlineStylesheet,
14374
14371
  sampling,
@@ -14415,7 +14412,7 @@ function record(options = {}) {
14415
14412
  });
14416
14413
  const init = () => {
14417
14414
  takeFullSnapshot$1();
14418
- handlers.push(observe(document));
14415
+ handlers.push(observe(doc));
14419
14416
  recording = true;
14420
14417
  };
14421
14418
  if (doc.readyState === "interactive" || doc.readyState === "complete") {
@@ -14440,7 +14437,7 @@ function record(options = {}) {
14440
14437
  });
14441
14438
  if (recordAfter === "load") init();
14442
14439
  },
14443
- window
14440
+ win
14444
14441
  )
14445
14442
  );
14446
14443
  }