@appsurify-testmap/rrweb-replay 2.0.0-alpha.41 → 2.1.0-alpha.2

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.
@@ -16,6 +16,9 @@ var NodeType$3 = /* @__PURE__ */ ((NodeType2) => {
16
16
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
17
17
  return NodeType2;
18
18
  })(NodeType$3 || {});
19
+ function isElement(n2) {
20
+ return n2.nodeType === n2.ELEMENT_NODE;
21
+ }
19
22
  class Mirror {
20
23
  constructor() {
21
24
  __publicField$1(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -89,8 +92,16 @@ function isNodeMetaEqual(a2, b) {
89
92
  return a2.tagName === b.tagName && JSON.stringify(a2.attributes) === JSON.stringify(b.attributes) && a2.isSVG === b.isSVG && a2.needBlock === b.needBlock;
90
93
  return false;
91
94
  }
92
- function isElement(n2) {
93
- return n2.nodeType === n2.ELEMENT_NODE;
95
+ function extractFileExtension(path, baseURL) {
96
+ let url;
97
+ try {
98
+ url = new URL(path, baseURL ?? window.location.href);
99
+ } catch (err) {
100
+ return null;
101
+ }
102
+ const regex = /\.([0-9a-z]+)(?:$)/i;
103
+ const match = url.pathname.match(regex);
104
+ return (match == null ? void 0 : match[1]) ?? null;
94
105
  }
95
106
  const interactiveEvents$1 = [
96
107
  "change",
@@ -117,27 +128,59 @@ const interactiveEvents$1 = [
117
128
  "touchend",
118
129
  "touchcancel"
119
130
  ];
131
+ const inlineEventAttributes$1 = [
132
+ "onclick",
133
+ "ondblclick",
134
+ "onmousedown",
135
+ "onmouseup",
136
+ "onmouseover",
137
+ "onmouseout",
138
+ "onmousemove",
139
+ "onfocus",
140
+ "onblur",
141
+ "onkeydown",
142
+ "onkeypress",
143
+ "onkeyup",
144
+ "onchange",
145
+ "oninput",
146
+ "onsubmit",
147
+ "onreset",
148
+ "onselect",
149
+ "oncontextmenu",
150
+ "ontouchstart",
151
+ "ontouchmove",
152
+ "ontouchend",
153
+ "ontouchcancel"
154
+ ];
120
155
  const interactiveElementsRegistry$1 = /* @__PURE__ */ new WeakSet();
121
- if (typeof Element !== "undefined" && typeof EventTarget !== "undefined") {
122
- const originalAddEventListener = EventTarget.prototype.addEventListener;
123
- EventTarget.prototype.addEventListener = function(type, listener, options) {
124
- originalAddEventListener.call(this, type, listener, options);
125
- if (this instanceof Element) {
126
- const eventType = type.toLowerCase();
127
- if (interactiveEvents$1.includes(eventType)) {
128
- interactiveElementsRegistry$1.add(this);
129
- }
156
+ const originalAddEventListener$1 = EventTarget.prototype.addEventListener;
157
+ EventTarget.prototype.addEventListener = function(type, listener, options) {
158
+ originalAddEventListener$1.call(this, type, listener, options);
159
+ if (this instanceof Element) {
160
+ const eventType = type.toLowerCase();
161
+ if (interactiveEvents$1.includes(eventType)) {
162
+ interactiveElementsRegistry$1.add(this);
130
163
  }
131
- };
164
+ }
165
+ };
166
+ const originalRemoveEventListener$1 = EventTarget.prototype.removeEventListener;
167
+ EventTarget.prototype.removeEventListener = function(type, listener, options) {
168
+ originalRemoveEventListener$1.call(this, type, listener, options);
169
+ };
170
+ function inspectInlineEventHandlers$1() {
171
+ const allElements = document.querySelectorAll("*");
172
+ allElements.forEach((el) => {
173
+ inlineEventAttributes$1.forEach((attr) => {
174
+ if (el.hasAttribute(attr)) {
175
+ interactiveElementsRegistry$1.add(el);
176
+ }
177
+ });
178
+ });
132
179
  }
133
- if (typeof Element !== "undefined" && typeof EventTarget !== "undefined") {
134
- const originalRemoveEventListener = EventTarget.prototype.removeEventListener;
135
- EventTarget.prototype.removeEventListener = function(type, listener, options) {
136
- originalRemoveEventListener.call(this, type, listener, options);
137
- if (this instanceof Element) {
138
- type.toLowerCase();
139
- }
140
- };
180
+ if (document.readyState === "complete" || document.readyState === "interactive") {
181
+ inspectInlineEventHandlers$1();
182
+ } else {
183
+ document.addEventListener("DOMContentLoaded", inspectInlineEventHandlers$1);
141
184
  }
142
185
  const MEDIA_SELECTOR = /(max|min)-device-(width|height)/;
143
186
  const MEDIA_SELECTOR_GLOBAL = new RegExp(MEDIA_SELECTOR.source, "g");
@@ -3772,11 +3815,16 @@ function getTagName(n2) {
3772
3815
  function adaptCssForReplay(cssText, cache) {
3773
3816
  const cachedStyle = cache == null ? void 0 : cache.stylesWithHoverClass.get(cssText);
3774
3817
  if (cachedStyle) return cachedStyle;
3775
- const ast = postcss$1$1([
3776
- mediaSelectorPlugin,
3777
- pseudoClassPlugin
3778
- ]).process(cssText);
3779
- const result2 = ast.css;
3818
+ let result2 = cssText;
3819
+ try {
3820
+ const ast = postcss$1$1([
3821
+ mediaSelectorPlugin,
3822
+ pseudoClassPlugin
3823
+ ]).process(cssText);
3824
+ result2 = ast.css;
3825
+ } catch (error) {
3826
+ console.warn("Failed to adapt css for replay", error);
3827
+ }
3780
3828
  cache == null ? void 0 : cache.stylesWithHoverClass.set(cssText, result2);
3781
3829
  return result2;
3782
3830
  }
@@ -3797,11 +3845,39 @@ function applyCssSplits(n2, cssText, hackCss, cache) {
3797
3845
  while (cssTextSplits.length > 1 && cssTextSplits.length > childTextNodes.length) {
3798
3846
  cssTextSplits.splice(-2, 2, cssTextSplits.slice(-2).join(""));
3799
3847
  }
3848
+ let adaptedCss = "";
3849
+ if (hackCss) {
3850
+ adaptedCss = adaptCssForReplay(cssTextSplits.join(""), cache);
3851
+ }
3852
+ let startIndex = 0;
3800
3853
  for (let i2 = 0; i2 < childTextNodes.length; i2++) {
3854
+ if (i2 === cssTextSplits.length) {
3855
+ break;
3856
+ }
3801
3857
  const childTextNode = childTextNodes[i2];
3802
- const cssTextSection = cssTextSplits[i2];
3803
- if (childTextNode && cssTextSection) {
3804
- childTextNode.textContent = hackCss ? adaptCssForReplay(cssTextSection, cache) : cssTextSection;
3858
+ if (!hackCss) {
3859
+ childTextNode.textContent = cssTextSplits[i2];
3860
+ } else if (i2 < cssTextSplits.length - 1) {
3861
+ let endIndex = startIndex;
3862
+ let endSearch = cssTextSplits[i2 + 1].length;
3863
+ endSearch = Math.min(endSearch, 30);
3864
+ let found = false;
3865
+ for (; endSearch > 2; endSearch--) {
3866
+ const searchBit = cssTextSplits[i2 + 1].substring(0, endSearch);
3867
+ const searchIndex = adaptedCss.substring(startIndex).indexOf(searchBit);
3868
+ found = searchIndex !== -1;
3869
+ if (found) {
3870
+ endIndex += searchIndex;
3871
+ break;
3872
+ }
3873
+ }
3874
+ if (!found) {
3875
+ endIndex += cssTextSplits[i2].length;
3876
+ }
3877
+ childTextNode.textContent = adaptedCss.substring(startIndex, endIndex);
3878
+ startIndex = endIndex;
3879
+ } else {
3880
+ childTextNode.textContent = adaptedCss.substring(startIndex);
3805
3881
  }
3806
3882
  }
3807
3883
  }
@@ -3885,8 +3961,8 @@ function buildNode(n2, options) {
3885
3961
  } else if (tagName === "meta" && n2.attributes["http-equiv"] === "Content-Security-Policy" && name === "content") {
3886
3962
  node2.setAttribute("csp-content", value.toString());
3887
3963
  continue;
3888
- } else if (tagName === "link" && (n2.attributes.rel === "preload" || n2.attributes.rel === "modulepreload") && n2.attributes.as === "script") {
3889
- } else if (tagName === "link" && n2.attributes.rel === "prefetch" && typeof n2.attributes.href === "string" && n2.attributes.href.endsWith(".js")) {
3964
+ } else if (tagName === "link" && (n2.attributes.rel === "preload" && n2.attributes.as === "script" || n2.attributes.rel === "modulepreload")) {
3965
+ } else if (tagName === "link" && n2.attributes.rel === "prefetch" && typeof n2.attributes.href === "string" && extractFileExtension(n2.attributes.href) === "js") {
3890
3966
  } else if (tagName === "img" && n2.attributes.srcset && n2.attributes.rr_dataURL) {
3891
3967
  node2.setAttribute(
3892
3968
  "rrweb-original-srcset",
@@ -4195,27 +4271,59 @@ const interactiveEvents = [
4195
4271
  "touchend",
4196
4272
  "touchcancel"
4197
4273
  ];
4274
+ const inlineEventAttributes = [
4275
+ "onclick",
4276
+ "ondblclick",
4277
+ "onmousedown",
4278
+ "onmouseup",
4279
+ "onmouseover",
4280
+ "onmouseout",
4281
+ "onmousemove",
4282
+ "onfocus",
4283
+ "onblur",
4284
+ "onkeydown",
4285
+ "onkeypress",
4286
+ "onkeyup",
4287
+ "onchange",
4288
+ "oninput",
4289
+ "onsubmit",
4290
+ "onreset",
4291
+ "onselect",
4292
+ "oncontextmenu",
4293
+ "ontouchstart",
4294
+ "ontouchmove",
4295
+ "ontouchend",
4296
+ "ontouchcancel"
4297
+ ];
4198
4298
  const interactiveElementsRegistry = /* @__PURE__ */ new WeakSet();
4199
- if (typeof Element !== "undefined" && typeof EventTarget !== "undefined") {
4200
- const originalAddEventListener = EventTarget.prototype.addEventListener;
4201
- EventTarget.prototype.addEventListener = function(type, listener, options) {
4202
- originalAddEventListener.call(this, type, listener, options);
4203
- if (this instanceof Element) {
4204
- const eventType = type.toLowerCase();
4205
- if (interactiveEvents.includes(eventType)) {
4206
- interactiveElementsRegistry.add(this);
4207
- }
4299
+ const originalAddEventListener = EventTarget.prototype.addEventListener;
4300
+ EventTarget.prototype.addEventListener = function(type, listener, options) {
4301
+ originalAddEventListener.call(this, type, listener, options);
4302
+ if (this instanceof Element) {
4303
+ const eventType = type.toLowerCase();
4304
+ if (interactiveEvents.includes(eventType)) {
4305
+ interactiveElementsRegistry.add(this);
4208
4306
  }
4209
- };
4307
+ }
4308
+ };
4309
+ const originalRemoveEventListener = EventTarget.prototype.removeEventListener;
4310
+ EventTarget.prototype.removeEventListener = function(type, listener, options) {
4311
+ originalRemoveEventListener.call(this, type, listener, options);
4312
+ };
4313
+ function inspectInlineEventHandlers() {
4314
+ const allElements = document.querySelectorAll("*");
4315
+ allElements.forEach((el) => {
4316
+ inlineEventAttributes.forEach((attr) => {
4317
+ if (el.hasAttribute(attr)) {
4318
+ interactiveElementsRegistry.add(el);
4319
+ }
4320
+ });
4321
+ });
4210
4322
  }
4211
- if (typeof Element !== "undefined" && typeof EventTarget !== "undefined") {
4212
- const originalRemoveEventListener = EventTarget.prototype.removeEventListener;
4213
- EventTarget.prototype.removeEventListener = function(type, listener, options) {
4214
- originalRemoveEventListener.call(this, type, listener, options);
4215
- if (this instanceof Element) {
4216
- type.toLowerCase();
4217
- }
4218
- };
4323
+ if (document.readyState === "complete" || document.readyState === "interactive") {
4324
+ inspectInlineEventHandlers();
4325
+ } else {
4326
+ document.addEventListener("DOMContentLoaded", inspectInlineEventHandlers);
4219
4327
  }
4220
4328
  function getDefaultExportFromCjs(x2) {
4221
4329
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
@@ -9167,6 +9275,32 @@ function querySelectorAll(n2, selectors) {
9167
9275
  function mutationObserverCtor() {
9168
9276
  return getUntaintedPrototype("MutationObserver").constructor;
9169
9277
  }
9278
+ function patch(source, name, replacement) {
9279
+ try {
9280
+ if (!(name in source)) {
9281
+ return () => {
9282
+ };
9283
+ }
9284
+ const original = source[name];
9285
+ const wrapped = replacement(original);
9286
+ if (typeof wrapped === "function") {
9287
+ wrapped.prototype = wrapped.prototype || {};
9288
+ Object.defineProperties(wrapped, {
9289
+ __rrweb_original__: {
9290
+ enumerable: false,
9291
+ value: original
9292
+ }
9293
+ });
9294
+ }
9295
+ source[name] = wrapped;
9296
+ return () => {
9297
+ source[name] = original;
9298
+ };
9299
+ } catch {
9300
+ return () => {
9301
+ };
9302
+ }
9303
+ }
9170
9304
  const index = {
9171
9305
  childNodes,
9172
9306
  parentNode,
@@ -9179,7 +9313,8 @@ const index = {
9179
9313
  shadowRoot,
9180
9314
  querySelector,
9181
9315
  querySelectorAll,
9182
- mutationObserver: mutationObserverCtor
9316
+ mutationObserver: mutationObserverCtor,
9317
+ patch
9183
9318
  };
9184
9319
  const DEPARTED_MIRROR_ACCESS_WARNING = "Please stop import mirror directly. Instead of that,\r\nnow you can use replayer.getMirror() to access the mirror instance of a replayer,\r\nor you can use record.mirror to access the mirror instance during recording.";
9185
9320
  let _mirror = {
@@ -9397,13 +9532,14 @@ var MouseInteractions = /* @__PURE__ */ ((MouseInteractions2) => {
9397
9532
  MouseInteractions2[MouseInteractions2["MouseUp"] = 0] = "MouseUp";
9398
9533
  MouseInteractions2[MouseInteractions2["MouseDown"] = 1] = "MouseDown";
9399
9534
  MouseInteractions2[MouseInteractions2["Click"] = 2] = "Click";
9400
- MouseInteractions2[MouseInteractions2["DblClick"] = 3] = "DblClick";
9401
- MouseInteractions2[MouseInteractions2["Focus"] = 4] = "Focus";
9402
- MouseInteractions2[MouseInteractions2["Blur"] = 5] = "Blur";
9403
- MouseInteractions2[MouseInteractions2["TouchStart"] = 6] = "TouchStart";
9404
- MouseInteractions2[MouseInteractions2["TouchMove_Departed"] = 7] = "TouchMove_Departed";
9405
- MouseInteractions2[MouseInteractions2["TouchEnd"] = 8] = "TouchEnd";
9406
- MouseInteractions2[MouseInteractions2["TouchCancel"] = 9] = "TouchCancel";
9535
+ MouseInteractions2[MouseInteractions2["ContextMenu"] = 3] = "ContextMenu";
9536
+ MouseInteractions2[MouseInteractions2["DblClick"] = 4] = "DblClick";
9537
+ MouseInteractions2[MouseInteractions2["Focus"] = 5] = "Focus";
9538
+ MouseInteractions2[MouseInteractions2["Blur"] = 6] = "Blur";
9539
+ MouseInteractions2[MouseInteractions2["TouchStart"] = 7] = "TouchStart";
9540
+ MouseInteractions2[MouseInteractions2["TouchMove_Departed"] = 8] = "TouchMove_Departed";
9541
+ MouseInteractions2[MouseInteractions2["TouchEnd"] = 9] = "TouchEnd";
9542
+ MouseInteractions2[MouseInteractions2["TouchCancel"] = 10] = "TouchCancel";
9407
9543
  return MouseInteractions2;
9408
9544
  })(MouseInteractions || {});
9409
9545
  var CanvasContext = /* @__PURE__ */ ((CanvasContext2) => {