@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.d.cts CHANGED
@@ -79,14 +79,14 @@ declare function getRootShadowHost(n: Node): Node;
79
79
 
80
80
  declare function getShadowHost(n: Node): Element | null;
81
81
 
82
- declare function getWindowHeight(): number;
82
+ declare function getWindowHeight(win?: Window): number;
83
83
 
84
- declare function getWindowScroll(win: Window): {
84
+ declare function getWindowScroll(win?: Window): {
85
85
  left: number;
86
86
  top: number;
87
87
  };
88
88
 
89
- declare function getWindowWidth(): number;
89
+ declare function getWindowWidth(win?: Window): number;
90
90
 
91
91
  declare function hasShadowRoot<T extends Node | RRNode>(n: T): n is T & {
92
92
  shadowRoot: ShadowRoot;
@@ -233,6 +233,7 @@ export declare type recordOptions<T> = {
233
233
  ignoreSelector?: string;
234
234
  maskTextClass?: maskTextClass;
235
235
  maskTextSelector?: string;
236
+ ignoreAttribute?: string;
236
237
  maskAllInputs?: boolean;
237
238
  maskInputOptions?: MaskInputOptions;
238
239
  maskInputFn?: MaskInputFn;
package/dist/rrweb.d.ts CHANGED
@@ -79,14 +79,14 @@ declare function getRootShadowHost(n: Node): Node;
79
79
 
80
80
  declare function getShadowHost(n: Node): Element | null;
81
81
 
82
- declare function getWindowHeight(): number;
82
+ declare function getWindowHeight(win?: Window): number;
83
83
 
84
- declare function getWindowScroll(win: Window): {
84
+ declare function getWindowScroll(win?: Window): {
85
85
  left: number;
86
86
  top: number;
87
87
  };
88
88
 
89
- declare function getWindowWidth(): number;
89
+ declare function getWindowWidth(win?: Window): number;
90
90
 
91
91
  declare function hasShadowRoot<T extends Node | RRNode>(n: T): n is T & {
92
92
  shadowRoot: ShadowRoot;
@@ -233,6 +233,7 @@ export declare type recordOptions<T> = {
233
233
  ignoreSelector?: string;
234
234
  maskTextClass?: maskTextClass;
235
235
  maskTextSelector?: string;
236
+ ignoreAttribute?: string;
236
237
  maskAllInputs?: boolean;
237
238
  maskInputOptions?: MaskInputOptions;
238
239
  maskInputFn?: MaskInputFn;
package/dist/rrweb.js CHANGED
@@ -525,7 +525,7 @@ function getXPath(node2) {
525
525
  return "/html/body";
526
526
  }
527
527
  const parentNode2 = element.parentNode;
528
- if (!parentNode2 || !(parentNode2 instanceof Element)) {
528
+ if (!parentNode2) {
529
529
  return "";
530
530
  }
531
531
  const siblings = Array.from(parentNode2.children).filter(
@@ -587,14 +587,19 @@ function isTextVisible(n2) {
587
587
  return textContent2 !== "";
588
588
  }
589
589
  function isElementVisible(n2) {
590
- return isStyleVisible(n2) && isRectVisible(n2.getBoundingClientRect());
591
- }
592
- function isStyleVisible(n2) {
593
- const style = window.getComputedStyle(n2);
594
- return style.display !== "none" && style.visibility !== "hidden" && parseFloat(style.opacity) !== 0;
590
+ var _a2;
591
+ const win = ((_a2 = n2.ownerDocument) == null ? void 0 : _a2.defaultView) ?? null;
592
+ const style = win ? win.getComputedStyle(n2) : null;
593
+ const isStyleVisible = style != null && style.display !== "none" && style.visibility !== "hidden" && parseFloat(style.opacity) !== 0;
594
+ const rect = n2.getBoundingClientRect();
595
+ const result2 = isStyleVisible && isRectVisible(rect, win);
596
+ return result2;
595
597
  }
596
- function isRectVisible(rect) {
597
- 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);
598
+ function isRectVisible(rect, win) {
599
+ var _a2, _b, _c, _d;
600
+ 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;
601
+ 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;
602
+ return rect.width > 0 && rect.height > 0 && rect.top >= 0 && rect.left >= 0 && rect.bottom <= height && rect.right <= width;
598
603
  }
599
604
  const interactiveEvents$1 = [
600
605
  "change",
@@ -634,7 +639,7 @@ const interactiveTags = [
634
639
  "video",
635
640
  "audio"
636
641
  ];
637
- const inlineEventAttributes$1 = [
642
+ const inlineEventAttributes = [
638
643
  "onclick",
639
644
  "ondblclick",
640
645
  "onmousedown",
@@ -677,7 +682,6 @@ function hasEventListeners(n2) {
677
682
  return n2 instanceof Element && interactiveElementsRegistry$1.has(n2);
678
683
  }
679
684
  function isElementInteractive(n2) {
680
- var _a2;
681
685
  if (n2.nodeType === Node.ELEMENT_NODE) {
682
686
  const element = n2;
683
687
  const tagName = element.tagName.toLowerCase();
@@ -691,30 +695,35 @@ function isElementInteractive(n2) {
691
695
  const result2 = hasEventListeners(element) || hasTabIndex || hasRoleInteractive || element instanceof HTMLAnchorElement && element.hasAttribute("href") || element instanceof HTMLButtonElement && !element.disabled;
692
696
  return result2;
693
697
  }
694
- if (n2.nodeType === Node.TEXT_NODE) {
695
- const textNode = n2;
696
- const parentElement2 = textNode.parentElement;
697
- if (parentElement2 !== null && interactiveTags.includes(parentElement2.tagName.toLowerCase())) {
698
- return true;
699
- }
700
- return parentElement2 !== null && isElementVisible(parentElement2) && ((_a2 = textNode.textContent) == null ? void 0 : _a2.trim().length) !== 0 && isElementInteractive(parentElement2);
701
- }
702
698
  return false;
703
699
  }
704
- function inspectInlineEventHandlers$1() {
705
- const allElements = document.querySelectorAll("*");
700
+ function inspectInlineEventHandlers(doc) {
701
+ if (!doc || typeof doc.querySelectorAll !== "function") return;
702
+ const allElements = doc.querySelectorAll("*");
706
703
  allElements.forEach((el) => {
707
- inlineEventAttributes$1.forEach((attr) => {
704
+ inlineEventAttributes.forEach((attr) => {
708
705
  if (el.hasAttribute(attr)) {
709
706
  interactiveElementsRegistry$1.add(el);
710
707
  }
711
708
  });
712
709
  });
713
710
  }
714
- if (document.readyState === "complete" || document.readyState === "interactive") {
715
- inspectInlineEventHandlers$1();
716
- } else {
717
- document.addEventListener("DOMContentLoaded", inspectInlineEventHandlers$1);
711
+ function scheduleInlineEventInspection(doc) {
712
+ if (!doc || typeof doc.addEventListener !== "function" || typeof doc.querySelectorAll !== "function") {
713
+ return;
714
+ }
715
+ try {
716
+ if (doc.readyState === "complete" || doc.readyState === "interactive") {
717
+ inspectInlineEventHandlers(doc);
718
+ } else {
719
+ doc.addEventListener("DOMContentLoaded", () => inspectInlineEventHandlers(doc), {
720
+ once: true,
721
+ capture: false
722
+ });
723
+ }
724
+ } catch (e2) {
725
+ console.warn("[inlineEventInspection] Failed to inspect document:", e2);
726
+ }
718
727
  }
719
728
  let _id = 1;
720
729
  const tagNameRegex = new RegExp("[^a-z0-9-_:]");
@@ -833,9 +842,29 @@ function transformAttribute(doc, tagName, name, value) {
833
842
  }
834
843
  return value;
835
844
  }
836
- function ignoreAttribute(tagName, name, _value) {
845
+ function isIgnoreAttribute(tagName, name, _value) {
837
846
  return (tagName === "video" || tagName === "audio") && name === "autoplay";
838
847
  }
848
+ function cleanAttributes(doc, element, ignoreAttribute) {
849
+ const tagName = getValidTagName$1(element);
850
+ const attributes = {};
851
+ const len = element.attributes.length;
852
+ for (let i2 = 0; i2 < len; i2++) {
853
+ const attr = element.attributes[i2];
854
+ const name = attr.name;
855
+ const value = attr.value;
856
+ const shouldIgnoreByName = typeof ignoreAttribute === "string" ? name === ignoreAttribute : ignoreAttribute.test(name);
857
+ if (!shouldIgnoreByName && !isIgnoreAttribute(tagName, name)) {
858
+ attributes[name] = transformAttribute(
859
+ doc,
860
+ tagName,
861
+ toLowerCase(name),
862
+ value
863
+ );
864
+ }
865
+ }
866
+ return attributes;
867
+ }
839
868
  function _isBlockedElement(element, blockClass, blockSelector) {
840
869
  try {
841
870
  if (typeof blockClass === "string") {
@@ -965,6 +994,7 @@ function serializeNode(n2, options) {
965
994
  mirror: mirror2,
966
995
  blockClass,
967
996
  blockSelector,
997
+ ignoreAttribute,
968
998
  needsMask,
969
999
  inlineStylesheet,
970
1000
  maskInputOptions = {},
@@ -1009,6 +1039,7 @@ function serializeNode(n2, options) {
1009
1039
  doc,
1010
1040
  blockClass,
1011
1041
  blockSelector,
1042
+ ignoreAttribute,
1012
1043
  inlineStylesheet,
1013
1044
  maskInputOptions,
1014
1045
  maskInputFn,
@@ -1086,6 +1117,7 @@ function serializeElementNode(n2, options) {
1086
1117
  doc,
1087
1118
  blockClass,
1088
1119
  blockSelector,
1120
+ ignoreAttribute,
1089
1121
  inlineStylesheet,
1090
1122
  maskInputOptions = {},
1091
1123
  maskInputFn,
@@ -1099,19 +1131,7 @@ function serializeElementNode(n2, options) {
1099
1131
  } = options;
1100
1132
  const needBlock = _isBlockedElement(n2, blockClass, blockSelector);
1101
1133
  const tagName = getValidTagName$1(n2);
1102
- let attributes = {};
1103
- const len = n2.attributes.length;
1104
- for (let i2 = 0; i2 < len; i2++) {
1105
- const attr = n2.attributes[i2];
1106
- if (!ignoreAttribute(tagName, attr.name, attr.value)) {
1107
- attributes[attr.name] = transformAttribute(
1108
- doc,
1109
- tagName,
1110
- toLowerCase(attr.name),
1111
- attr.value
1112
- );
1113
- }
1114
- }
1134
+ let attributes = cleanAttributes(doc, n2, ignoreAttribute);
1115
1135
  if (tagName === "link" && inlineStylesheet) {
1116
1136
  const stylesheet = Array.from(doc.styleSheets).find((s2) => {
1117
1137
  return s2.href === n2.href;
@@ -1325,6 +1345,7 @@ function serializeNodeWithId(n2, options) {
1325
1345
  blockSelector,
1326
1346
  maskTextClass,
1327
1347
  maskTextSelector,
1348
+ ignoreAttribute,
1328
1349
  skipChild = false,
1329
1350
  inlineStylesheet = true,
1330
1351
  maskInputOptions = {},
@@ -1359,6 +1380,7 @@ function serializeNodeWithId(n2, options) {
1359
1380
  mirror: mirror2,
1360
1381
  blockClass,
1361
1382
  blockSelector,
1383
+ ignoreAttribute,
1362
1384
  needsMask,
1363
1385
  inlineStylesheet,
1364
1386
  maskInputOptions,
@@ -1411,6 +1433,7 @@ function serializeNodeWithId(n2, options) {
1411
1433
  needsMask,
1412
1434
  maskTextClass,
1413
1435
  maskTextSelector,
1436
+ ignoreAttribute,
1414
1437
  skipChild,
1415
1438
  inlineStylesheet,
1416
1439
  maskInputOptions,
@@ -1470,6 +1493,7 @@ function serializeNodeWithId(n2, options) {
1470
1493
  needsMask,
1471
1494
  maskTextClass,
1472
1495
  maskTextSelector,
1496
+ ignoreAttribute,
1473
1497
  skipChild: false,
1474
1498
  inlineStylesheet,
1475
1499
  maskInputOptions,
@@ -1511,6 +1535,7 @@ function serializeNodeWithId(n2, options) {
1511
1535
  needsMask,
1512
1536
  maskTextClass,
1513
1537
  maskTextSelector,
1538
+ ignoreAttribute,
1514
1539
  skipChild: false,
1515
1540
  inlineStylesheet,
1516
1541
  maskInputOptions,
@@ -1548,6 +1573,7 @@ function snapshot(n2, options) {
1548
1573
  blockSelector = null,
1549
1574
  maskTextClass = "rr-mask",
1550
1575
  maskTextSelector = null,
1576
+ ignoreAttribute = "rr-ignore-attr",
1551
1577
  inlineStylesheet = true,
1552
1578
  inlineImages = false,
1553
1579
  recordCanvas = false,
@@ -1564,6 +1590,7 @@ function snapshot(n2, options) {
1564
1590
  stylesheetLoadTimeout,
1565
1591
  keepIframeSrcFn = () => false
1566
1592
  } = options || {};
1593
+ scheduleInlineEventInspection(n2);
1567
1594
  const maskInputOptions = maskAllInputs === true ? {
1568
1595
  color: true,
1569
1596
  date: true,
@@ -1607,6 +1634,7 @@ function snapshot(n2, options) {
1607
1634
  blockSelector,
1608
1635
  maskTextClass,
1609
1636
  maskTextSelector,
1637
+ ignoreAttribute,
1610
1638
  skipChild: false,
1611
1639
  inlineStylesheet,
1612
1640
  maskInputOptions,
@@ -5682,30 +5710,6 @@ const interactiveEvents = [
5682
5710
  "touchend",
5683
5711
  "touchcancel"
5684
5712
  ];
5685
- const inlineEventAttributes = [
5686
- "onclick",
5687
- "ondblclick",
5688
- "onmousedown",
5689
- "onmouseup",
5690
- "onmouseover",
5691
- "onmouseout",
5692
- "onmousemove",
5693
- "onfocus",
5694
- "onblur",
5695
- "onkeydown",
5696
- "onkeypress",
5697
- "onkeyup",
5698
- "onchange",
5699
- "oninput",
5700
- "onsubmit",
5701
- "onreset",
5702
- "onselect",
5703
- "oncontextmenu",
5704
- "ontouchstart",
5705
- "ontouchmove",
5706
- "ontouchend",
5707
- "ontouchcancel"
5708
- ];
5709
5713
  const interactiveElementsRegistry = /* @__PURE__ */ new WeakSet();
5710
5714
  const originalAddEventListener = EventTarget.prototype.addEventListener;
5711
5715
  EventTarget.prototype.addEventListener = function(type, listener, options) {
@@ -5721,21 +5725,6 @@ const originalRemoveEventListener = EventTarget.prototype.removeEventListener;
5721
5725
  EventTarget.prototype.removeEventListener = function(type, listener, options) {
5722
5726
  originalRemoveEventListener.call(this, type, listener, options);
5723
5727
  };
5724
- function inspectInlineEventHandlers() {
5725
- const allElements = document.querySelectorAll("*");
5726
- allElements.forEach((el) => {
5727
- inlineEventAttributes.forEach((attr) => {
5728
- if (el.hasAttribute(attr)) {
5729
- interactiveElementsRegistry.add(el);
5730
- }
5731
- });
5732
- });
5733
- }
5734
- if (document.readyState === "complete" || document.readyState === "interactive") {
5735
- inspectInlineEventHandlers();
5736
- } else {
5737
- document.addEventListener("DOMContentLoaded", inspectInlineEventHandlers);
5738
- }
5739
5728
  function getDefaultExportFromCjs(x2) {
5740
5729
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
5741
5730
  }
@@ -10811,7 +10800,7 @@ let nowTimestamp = Date.now;
10811
10800
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
10812
10801
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
10813
10802
  }
10814
- function getWindowScroll(win) {
10803
+ function getWindowScroll(win = window) {
10815
10804
  var _a2, _b, _c, _d;
10816
10805
  const doc = win.document;
10817
10806
  return {
@@ -10819,11 +10808,13 @@ function getWindowScroll(win) {
10819
10808
  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
10820
10809
  };
10821
10810
  }
10822
- function getWindowHeight() {
10823
- return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body && document.body.clientHeight;
10811
+ function getWindowHeight(win = window) {
10812
+ const doc = win.document;
10813
+ return win.innerHeight || doc.documentElement && doc.documentElement.clientHeight || doc.body && doc.body.clientHeight || 0;
10824
10814
  }
10825
- function getWindowWidth() {
10826
- return window.innerWidth || document.documentElement && document.documentElement.clientWidth || document.body && document.body.clientWidth;
10815
+ function getWindowWidth(win = window) {
10816
+ const doc = win.document;
10817
+ return win.innerWidth || doc.documentElement && doc.documentElement.clientWidth || doc.body && doc.body.clientWidth || 0;
10827
10818
  }
10828
10819
  function closestElementOfNode(node2) {
10829
10820
  if (!node2) {
@@ -11309,6 +11300,7 @@ class MutationBuffer {
11309
11300
  __publicField(this, "blockSelector");
11310
11301
  __publicField(this, "maskTextClass");
11311
11302
  __publicField(this, "maskTextSelector");
11303
+ __publicField(this, "ignoreAttribute");
11312
11304
  __publicField(this, "inlineStylesheet");
11313
11305
  __publicField(this, "maskInputOptions");
11314
11306
  __publicField(this, "maskTextFn");
@@ -11372,6 +11364,7 @@ class MutationBuffer {
11372
11364
  blockSelector: this.blockSelector,
11373
11365
  maskTextClass: this.maskTextClass,
11374
11366
  maskTextSelector: this.maskTextSelector,
11367
+ ignoreAttribute: this.ignoreAttribute || "",
11375
11368
  skipChild: true,
11376
11369
  newlyAddedElement: true,
11377
11370
  inlineStylesheet: this.inlineStylesheet,
@@ -11600,7 +11593,7 @@ class MutationBuffer {
11600
11593
  if (attributeName === "type" && target.tagName === "INPUT" && (m.oldValue || "").toLowerCase() === "password") {
11601
11594
  target.setAttribute("data-rr-is-password", "true");
11602
11595
  }
11603
- if (!ignoreAttribute(target.tagName, attributeName)) {
11596
+ if (!isIgnoreAttribute(target.tagName, attributeName)) {
11604
11597
  item.attributes[attributeName] = transformAttribute(
11605
11598
  this.doc,
11606
11599
  toLowerCase(target.tagName),
@@ -11722,6 +11715,7 @@ class MutationBuffer {
11722
11715
  "blockSelector",
11723
11716
  "maskTextClass",
11724
11717
  "maskTextSelector",
11718
+ "ignoreAttribute",
11725
11719
  "inlineStylesheet",
11726
11720
  "maskInputOptions",
11727
11721
  "maskTextFn",
@@ -13971,6 +13965,7 @@ function record(options = {}) {
13971
13965
  blockSelector = null,
13972
13966
  ignoreClass = "rr-ignore",
13973
13967
  ignoreSelector = null,
13968
+ ignoreAttribute = "rr-ignore-attribute",
13974
13969
  maskTextClass = "rr-mask",
13975
13970
  maskTextSelector = null,
13976
13971
  inlineStylesheet = true,
@@ -14166,7 +14161,7 @@ function record(options = {}) {
14166
14161
  canvasManager = new CanvasManager({
14167
14162
  recordCanvas,
14168
14163
  mutationCb: wrappedCanvasMutationEmit,
14169
- win: window,
14164
+ win,
14170
14165
  blockClass,
14171
14166
  blockSelector,
14172
14167
  mirror,
@@ -14181,6 +14176,7 @@ function record(options = {}) {
14181
14176
  blockSelector,
14182
14177
  maskTextClass,
14183
14178
  maskTextSelector,
14179
+ ignoreAttribute,
14184
14180
  inlineStylesheet,
14185
14181
  maskInputOptions,
14186
14182
  dataURLOptions,
@@ -14207,8 +14203,8 @@ function record(options = {}) {
14207
14203
  type: EventType.Meta,
14208
14204
  data: {
14209
14205
  href: win.location.href,
14210
- width: getWindowWidth(),
14211
- height: getWindowHeight()
14206
+ width: getWindowWidth(win),
14207
+ height: getWindowHeight(win)
14212
14208
  }
14213
14209
  },
14214
14210
  isCheckout
@@ -14216,7 +14212,7 @@ function record(options = {}) {
14216
14212
  stylesheetManager.reset();
14217
14213
  shadowDomManager.init();
14218
14214
  mutationBuffers.forEach((buf) => buf.lock());
14219
- const node2 = snapshot(document, {
14215
+ const node2 = snapshot(doc, {
14220
14216
  mirror,
14221
14217
  blockClass,
14222
14218
  blockSelector,
@@ -14238,7 +14234,7 @@ function record(options = {}) {
14238
14234
  stylesheetManager.trackLinkElement(n2);
14239
14235
  }
14240
14236
  if (hasShadowRoot(n2)) {
14241
- shadowDomManager.addShadowRoot(index.shadowRoot(n2), document);
14237
+ shadowDomManager.addShadowRoot(index.shadowRoot(n2), doc);
14242
14238
  }
14243
14239
  },
14244
14240
  onIframeLoad: (iframe, childSn) => {
@@ -14258,7 +14254,7 @@ function record(options = {}) {
14258
14254
  type: EventType.FullSnapshot,
14259
14255
  data: {
14260
14256
  node: node2,
14261
- initialOffset: getWindowScroll(window)
14257
+ initialOffset: getWindowScroll(win)
14262
14258
  }
14263
14259
  },
14264
14260
  isCheckout
@@ -14367,6 +14363,7 @@ function record(options = {}) {
14367
14363
  ignoreSelector,
14368
14364
  maskTextClass,
14369
14365
  maskTextSelector,
14366
+ ignoreAttribute,
14370
14367
  maskInputOptions,
14371
14368
  inlineStylesheet,
14372
14369
  sampling,
@@ -14413,7 +14410,7 @@ function record(options = {}) {
14413
14410
  });
14414
14411
  const init = () => {
14415
14412
  takeFullSnapshot$1();
14416
- handlers.push(observe(document));
14413
+ handlers.push(observe(doc));
14417
14414
  recording = true;
14418
14415
  };
14419
14416
  if (doc.readyState === "interactive" || doc.readyState === "complete") {
@@ -14438,7 +14435,7 @@ function record(options = {}) {
14438
14435
  });
14439
14436
  if (recordAfter === "load") init();
14440
14437
  },
14441
- window
14438
+ win
14442
14439
  )
14443
14440
  );
14444
14441
  }