@kalayanasundaram123/rrweb 2.0.3 → 2.0.5

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.
@@ -69,14 +69,18 @@ const testableAccessors$1 = {
69
69
  "ownerDocument"
70
70
  ],
71
71
  ShadowRoot: ["host", "styleSheets"],
72
- Element: ["shadowRoot", "querySelector", "querySelectorAll"],
73
- MutationObserver: []
72
+ Element: ["shadowRoot"],
73
+ MutationObserver: [],
74
+ EventTarget: []
74
75
  };
75
76
  const testableMethods$1 = {
76
77
  Node: ["contains", "getRootNode"],
77
78
  ShadowRoot: ["getSelection"],
78
- Element: [],
79
- MutationObserver: ["constructor"]
79
+ // PR #1802: moved from testableAccessors
80
+ Element: ["querySelector", "querySelectorAll"],
81
+ MutationObserver: ["constructor"],
82
+ // PR #1814
83
+ EventTarget: ["addEventListener", "removeEventListener"]
80
84
  };
81
85
  const untaintedBasePrototype$1 = {};
82
86
  const untaintedBaseIframeCleanup$1 = {};
@@ -201,10 +205,10 @@ function shadowRoot$1(n2) {
201
205
  return getUntaintedAccessor$1("Element", n2, "shadowRoot");
202
206
  }
203
207
  function querySelector$1(n2, selectors) {
204
- return getUntaintedAccessor$1("Element", n2, "querySelector")(selectors);
208
+ return getUntaintedMethod$1("Element", n2, "querySelector")(selectors);
205
209
  }
206
210
  function querySelectorAll$1(n2, selectors) {
207
- return getUntaintedAccessor$1("Element", n2, "querySelectorAll")(selectors);
211
+ return getUntaintedMethod$1("Element", n2, "querySelectorAll")(selectors);
208
212
  }
209
213
  function mutationObserverCtor$1() {
210
214
  var _a2;
@@ -214,10 +218,69 @@ function mutationObserverCtor$1() {
214
218
  }
215
219
  ];
216
220
  }
221
+ function getUntaintedProxy$1() {
222
+ var _a3;
223
+ var _a2;
224
+ let UntaintedProxy = globalThis.Proxy;
225
+ try {
226
+ if (typeof UntaintedProxy !== "function" || !Function.prototype.toString.call(UntaintedProxy).includes("[native code]")) {
227
+ const frame = document.createElement("iframe");
228
+ frame.style.display = "none";
229
+ document.documentElement.appendChild(frame);
230
+ UntaintedProxy = (_a3 = (_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) != null ? _a3 : UntaintedProxy;
231
+ document.documentElement.removeChild(frame);
232
+ }
233
+ } catch (e2) {
234
+ }
235
+ return UntaintedProxy;
236
+ }
217
237
  let nowTimestamp$1 = Date.now;
218
238
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
219
239
  nowTimestamp$1 = () => (/* @__PURE__ */ new Date()).getTime();
220
240
  }
241
+ const _rrwebNativeMap$2 = /* @__PURE__ */ new WeakMap();
242
+ let _nativeToStringStr$2 = "";
243
+ (function _installToStringProxy() {
244
+ var _a3;
245
+ var _a2;
246
+ const _nativeToString = Function.prototype.toString;
247
+ _nativeToStringStr$2 = _nativeToString.call(_nativeToString);
248
+ let _Proxy = globalThis.Proxy;
249
+ try {
250
+ if (typeof _Proxy !== "function" || !_nativeToString.call(_Proxy).includes("[native code]")) {
251
+ const frame = document.createElement("iframe");
252
+ frame.style.display = "none";
253
+ document.documentElement.appendChild(frame);
254
+ _Proxy = (_a3 = (_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) != null ? _a3 : _Proxy;
255
+ document.documentElement.removeChild(frame);
256
+ }
257
+ } catch (e2) {
258
+ }
259
+ const _fnProto = Object.getPrototypeOf(_nativeToString);
260
+ const _proxy = new _Proxy(_nativeToString, {
261
+ apply(target, thisArg, args) {
262
+ const str = _rrwebNativeMap$2.get(thisArg);
263
+ if (str !== void 0) return str;
264
+ if (thisArg != null && typeof thisArg === "function" && !_fnProto.isPrototypeOf(
265
+ thisArg.toString
266
+ )) {
267
+ return thisArg.toString();
268
+ }
269
+ return target.apply(thisArg, args);
270
+ }
271
+ });
272
+ _rrwebNativeMap$2.set(_proxy, _nativeToStringStr$2);
273
+ Object.defineProperty(Function.prototype, "toString", {
274
+ value: _proxy,
275
+ configurable: true,
276
+ writable: true
277
+ });
278
+ })();
279
+ function makeNativeFn$1(fn, nativeFn) {
280
+ const name = fn.name || nativeFn.name || "";
281
+ _rrwebNativeMap$2.set(fn, _nativeToStringStr$2.replace("toString", name));
282
+ return fn;
283
+ }
221
284
  function patch$1(source, name, replacement) {
222
285
  try {
223
286
  if (!(name in source)) {
@@ -234,6 +297,10 @@ function patch$1(source, name, replacement) {
234
297
  value: original
235
298
  }
236
299
  });
300
+ _rrwebNativeMap$2.set(
301
+ wrapped,
302
+ _nativeToStringStr$2.replace("toString", name)
303
+ );
237
304
  }
238
305
  source[name] = wrapped;
239
306
  return () => {
@@ -259,7 +326,9 @@ const index$1 = {
259
326
  querySelectorAll: querySelectorAll$1,
260
327
  nowTimestamp: nowTimestamp$1,
261
328
  mutationObserverCtor: mutationObserverCtor$1,
262
- patch: patch$1
329
+ patch: patch$1,
330
+ makeNativeFn: makeNativeFn$1,
331
+ getUntaintedProxy: getUntaintedProxy$1
263
332
  };
264
333
  function isElement(n2) {
265
334
  return n2.nodeType === n2.ELEMENT_NODE;
@@ -5803,6 +5872,44 @@ var __defProp222 = Object.defineProperty;
5803
5872
  var __defNormalProp222 = (obj, key, value) => key in obj ? __defProp222(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5804
5873
  var __publicField22 = (obj, key, value) => __defNormalProp222(obj, typeof key !== "symbol" ? key + "" : key, value);
5805
5874
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) ;
5875
+ const _rrwebNativeMap$1 = /* @__PURE__ */ new WeakMap();
5876
+ let _nativeToStringStr$1 = "";
5877
+ (function _installToStringProxy2() {
5878
+ var _a3;
5879
+ var _a2;
5880
+ const _nativeToString = Function.prototype.toString;
5881
+ _nativeToStringStr$1 = _nativeToString.call(_nativeToString);
5882
+ let _Proxy = globalThis.Proxy;
5883
+ try {
5884
+ if (typeof _Proxy !== "function" || !_nativeToString.call(_Proxy).includes("[native code]")) {
5885
+ const frame = document.createElement("iframe");
5886
+ frame.style.display = "none";
5887
+ document.documentElement.appendChild(frame);
5888
+ _Proxy = (_a3 = (_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) != null ? _a3 : _Proxy;
5889
+ document.documentElement.removeChild(frame);
5890
+ }
5891
+ } catch (e2) {
5892
+ }
5893
+ const _fnProto = Object.getPrototypeOf(_nativeToString);
5894
+ const _proxy = new _Proxy(_nativeToString, {
5895
+ apply(target, thisArg, args) {
5896
+ const str = _rrwebNativeMap$1.get(thisArg);
5897
+ if (str !== void 0) return str;
5898
+ if (thisArg != null && typeof thisArg === "function" && !_fnProto.isPrototypeOf(
5899
+ thisArg.toString
5900
+ )) {
5901
+ return thisArg.toString();
5902
+ }
5903
+ return target.apply(thisArg, args);
5904
+ }
5905
+ });
5906
+ _rrwebNativeMap$1.set(_proxy, _nativeToStringStr$1);
5907
+ Object.defineProperty(Function.prototype, "toString", {
5908
+ value: _proxy,
5909
+ configurable: true,
5910
+ writable: true
5911
+ });
5912
+ })();
5806
5913
  let Mirror$1 = class Mirror2 {
5807
5914
  constructor() {
5808
5915
  __publicField22(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -10894,14 +11001,18 @@ const testableAccessors = {
10894
11001
  "ownerDocument"
10895
11002
  ],
10896
11003
  ShadowRoot: ["host", "styleSheets"],
10897
- Element: ["shadowRoot", "querySelector", "querySelectorAll"],
10898
- MutationObserver: []
11004
+ Element: ["shadowRoot"],
11005
+ MutationObserver: [],
11006
+ EventTarget: []
10899
11007
  };
10900
11008
  const testableMethods = {
10901
11009
  Node: ["contains", "getRootNode"],
10902
11010
  ShadowRoot: ["getSelection"],
10903
- Element: [],
10904
- MutationObserver: ["constructor"]
11011
+ // PR #1802: moved from testableAccessors
11012
+ Element: ["querySelector", "querySelectorAll"],
11013
+ MutationObserver: ["constructor"],
11014
+ // PR #1814
11015
+ EventTarget: ["addEventListener", "removeEventListener"]
10905
11016
  };
10906
11017
  const untaintedBasePrototype = {};
10907
11018
  const untaintedBaseIframeCleanup = {};
@@ -11026,10 +11137,10 @@ function shadowRoot(n2) {
11026
11137
  return getUntaintedAccessor("Element", n2, "shadowRoot");
11027
11138
  }
11028
11139
  function querySelector(n2, selectors) {
11029
- return getUntaintedAccessor("Element", n2, "querySelector")(selectors);
11140
+ return getUntaintedMethod("Element", n2, "querySelector")(selectors);
11030
11141
  }
11031
11142
  function querySelectorAll(n2, selectors) {
11032
- return getUntaintedAccessor("Element", n2, "querySelectorAll")(selectors);
11143
+ return getUntaintedMethod("Element", n2, "querySelectorAll")(selectors);
11033
11144
  }
11034
11145
  function mutationObserverCtor() {
11035
11146
  var _a2;
@@ -11039,10 +11150,69 @@ function mutationObserverCtor() {
11039
11150
  }
11040
11151
  ];
11041
11152
  }
11153
+ function getUntaintedProxy() {
11154
+ var _a3;
11155
+ var _a2;
11156
+ let UntaintedProxy = globalThis.Proxy;
11157
+ try {
11158
+ if (typeof UntaintedProxy !== "function" || !Function.prototype.toString.call(UntaintedProxy).includes("[native code]")) {
11159
+ const frame = document.createElement("iframe");
11160
+ frame.style.display = "none";
11161
+ document.documentElement.appendChild(frame);
11162
+ UntaintedProxy = (_a3 = (_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) != null ? _a3 : UntaintedProxy;
11163
+ document.documentElement.removeChild(frame);
11164
+ }
11165
+ } catch (e2) {
11166
+ }
11167
+ return UntaintedProxy;
11168
+ }
11042
11169
  let nowTimestamp = Date.now;
11043
11170
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
11044
11171
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
11045
11172
  }
11173
+ const _rrwebNativeMap = /* @__PURE__ */ new WeakMap();
11174
+ let _nativeToStringStr = "";
11175
+ (function _installToStringProxy3() {
11176
+ var _a3;
11177
+ var _a2;
11178
+ const _nativeToString = Function.prototype.toString;
11179
+ _nativeToStringStr = _nativeToString.call(_nativeToString);
11180
+ let _Proxy = globalThis.Proxy;
11181
+ try {
11182
+ if (typeof _Proxy !== "function" || !_nativeToString.call(_Proxy).includes("[native code]")) {
11183
+ const frame = document.createElement("iframe");
11184
+ frame.style.display = "none";
11185
+ document.documentElement.appendChild(frame);
11186
+ _Proxy = (_a3 = (_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) != null ? _a3 : _Proxy;
11187
+ document.documentElement.removeChild(frame);
11188
+ }
11189
+ } catch (e2) {
11190
+ }
11191
+ const _fnProto = Object.getPrototypeOf(_nativeToString);
11192
+ const _proxy = new _Proxy(_nativeToString, {
11193
+ apply(target, thisArg, args) {
11194
+ const str = _rrwebNativeMap.get(thisArg);
11195
+ if (str !== void 0) return str;
11196
+ if (thisArg != null && typeof thisArg === "function" && !_fnProto.isPrototypeOf(
11197
+ thisArg.toString
11198
+ )) {
11199
+ return thisArg.toString();
11200
+ }
11201
+ return target.apply(thisArg, args);
11202
+ }
11203
+ });
11204
+ _rrwebNativeMap.set(_proxy, _nativeToStringStr);
11205
+ Object.defineProperty(Function.prototype, "toString", {
11206
+ value: _proxy,
11207
+ configurable: true,
11208
+ writable: true
11209
+ });
11210
+ })();
11211
+ function makeNativeFn(fn, nativeFn) {
11212
+ const name = fn.name || nativeFn.name || "";
11213
+ _rrwebNativeMap.set(fn, _nativeToStringStr.replace("toString", name));
11214
+ return fn;
11215
+ }
11046
11216
  function patch(source, name, replacement) {
11047
11217
  try {
11048
11218
  if (!(name in source)) {
@@ -11059,6 +11229,10 @@ function patch(source, name, replacement) {
11059
11229
  value: original
11060
11230
  }
11061
11231
  });
11232
+ _rrwebNativeMap.set(
11233
+ wrapped,
11234
+ _nativeToStringStr.replace("toString", name)
11235
+ );
11062
11236
  }
11063
11237
  source[name] = wrapped;
11064
11238
  return () => {
@@ -11084,12 +11258,23 @@ const index = {
11084
11258
  querySelectorAll,
11085
11259
  nowTimestamp,
11086
11260
  mutationObserverCtor,
11087
- patch
11261
+ patch,
11262
+ makeNativeFn,
11263
+ getUntaintedProxy
11088
11264
  };
11089
11265
  function on(type, fn, target = document) {
11090
11266
  const options = { capture: true, passive: true };
11091
- target.addEventListener(type, fn, options);
11092
- return () => target.removeEventListener(type, fn, options);
11267
+ const eventTarget = target;
11268
+ getUntaintedMethod("EventTarget", eventTarget, "addEventListener")(
11269
+ type,
11270
+ fn,
11271
+ options
11272
+ );
11273
+ return () => getUntaintedMethod("EventTarget", eventTarget, "removeEventListener")(
11274
+ type,
11275
+ fn,
11276
+ options
11277
+ );
11093
11278
  }
11094
11279
  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.";
11095
11280
  exports.mirror = {
@@ -11151,20 +11336,27 @@ function throttle(func, wait, options = {}) {
11151
11336
  }
11152
11337
  function hookSetter(target, key, d, isRevoked, win = window) {
11153
11338
  const original = win.Object.getOwnPropertyDescriptor(target, key);
11154
- win.Object.defineProperty(
11155
- target,
11156
- key,
11157
- isRevoked ? d : {
11158
- set(value) {
11339
+ if (!isRevoked && (original == null ? void 0 : original.set)) {
11340
+ const hookedSetter = function(value) {
11341
+ setTimeout(() => {
11342
+ d.set.call(this, value);
11343
+ }, 0);
11344
+ original.set.call(this, value);
11345
+ };
11346
+ makeNativeFn(hookedSetter, original.set);
11347
+ win.Object.defineProperty(target, key, { set: hookedSetter });
11348
+ } else {
11349
+ win.Object.defineProperty(
11350
+ target,
11351
+ key,
11352
+ isRevoked ? d : { set(value) {
11159
11353
  setTimeout(() => {
11160
11354
  d.set.call(this, value);
11161
11355
  }, 0);
11162
- if (original && original.set) {
11163
- original.set.call(this, value);
11164
- }
11165
- }
11166
- }
11167
- );
11356
+ if (original && original.set) original.set.call(this, value);
11357
+ } }
11358
+ );
11359
+ }
11168
11360
  return () => hookSetter(target, key, original || {}, true);
11169
11361
  }
11170
11362
  function getWindowScroll(win) {
@@ -12173,6 +12365,7 @@ const callbackWrapper = (cb) => {
12173
12365
  };
12174
12366
  return rrwebWrapped;
12175
12367
  };
12368
+ const Proxy$1 = getUntaintedProxy();
12176
12369
  const mutationBuffers = [];
12177
12370
  function getEventTarget(event) {
12178
12371
  try {
@@ -12574,61 +12767,11 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12574
12767
  };
12575
12768
  }
12576
12769
  const insertRule = win.CSSStyleSheet.prototype.insertRule;
12577
- win.CSSStyleSheet.prototype.insertRule = new Proxy(insertRule, {
12578
- apply: callbackWrapper(
12579
- (target, thisArg, argumentsList) => {
12580
- const [rule2, index2] = argumentsList;
12581
- const { id, styleId } = getIdAndStyleId(
12582
- thisArg,
12583
- mirror2,
12584
- stylesheetManager.styleMirror
12585
- );
12586
- if (id && id !== -1 || styleId && styleId !== -1) {
12587
- styleSheetRuleCb({
12588
- id,
12589
- styleId,
12590
- adds: [{ rule: rule2, index: index2 }]
12591
- });
12592
- }
12593
- return target.apply(thisArg, argumentsList);
12594
- }
12595
- )
12596
- });
12597
- win.CSSStyleSheet.prototype.addRule = function(selector, styleBlock, index2 = this.cssRules.length) {
12598
- const rule2 = `${selector} { ${styleBlock} }`;
12599
- return win.CSSStyleSheet.prototype.insertRule.apply(this, [rule2, index2]);
12600
- };
12601
- const deleteRule = win.CSSStyleSheet.prototype.deleteRule;
12602
- win.CSSStyleSheet.prototype.deleteRule = new Proxy(deleteRule, {
12603
- apply: callbackWrapper(
12604
- (target, thisArg, argumentsList) => {
12605
- const [index2] = argumentsList;
12606
- const { id, styleId } = getIdAndStyleId(
12607
- thisArg,
12608
- mirror2,
12609
- stylesheetManager.styleMirror
12610
- );
12611
- if (id && id !== -1 || styleId && styleId !== -1) {
12612
- styleSheetRuleCb({
12613
- id,
12614
- styleId,
12615
- removes: [{ index: index2 }]
12616
- });
12617
- }
12618
- return target.apply(thisArg, argumentsList);
12619
- }
12620
- )
12621
- });
12622
- win.CSSStyleSheet.prototype.removeRule = function(index2) {
12623
- return win.CSSStyleSheet.prototype.deleteRule.apply(this, [index2]);
12624
- };
12625
- let replace;
12626
- if (win.CSSStyleSheet.prototype.replace) {
12627
- replace = win.CSSStyleSheet.prototype.replace;
12628
- win.CSSStyleSheet.prototype.replace = new Proxy(replace, {
12770
+ win.CSSStyleSheet.prototype.insertRule = makeNativeFn(
12771
+ new Proxy$1(insertRule, {
12629
12772
  apply: callbackWrapper(
12630
12773
  (target, thisArg, argumentsList) => {
12631
- const [text] = argumentsList;
12774
+ const [rule2, index2] = argumentsList;
12632
12775
  const { id, styleId } = getIdAndStyleId(
12633
12776
  thisArg,
12634
12777
  mirror2,
@@ -12638,21 +12781,28 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12638
12781
  styleSheetRuleCb({
12639
12782
  id,
12640
12783
  styleId,
12641
- replace: text
12784
+ adds: [{ rule: rule2, index: index2 }]
12642
12785
  });
12643
12786
  }
12644
12787
  return target.apply(thisArg, argumentsList);
12645
12788
  }
12646
12789
  )
12647
- });
12648
- }
12649
- let replaceSync;
12650
- if (win.CSSStyleSheet.prototype.replaceSync) {
12651
- replaceSync = win.CSSStyleSheet.prototype.replaceSync;
12652
- win.CSSStyleSheet.prototype.replaceSync = new Proxy(replaceSync, {
12790
+ }),
12791
+ insertRule
12792
+ );
12793
+ win.CSSStyleSheet.prototype.addRule = makeNativeFn(
12794
+ function(selector, styleBlock, index2 = this.cssRules.length) {
12795
+ const rule2 = `${selector} { ${styleBlock} }`;
12796
+ return win.CSSStyleSheet.prototype.insertRule.apply(this, [rule2, index2]);
12797
+ },
12798
+ insertRule
12799
+ );
12800
+ const deleteRule = win.CSSStyleSheet.prototype.deleteRule;
12801
+ win.CSSStyleSheet.prototype.deleteRule = makeNativeFn(
12802
+ new Proxy$1(deleteRule, {
12653
12803
  apply: callbackWrapper(
12654
12804
  (target, thisArg, argumentsList) => {
12655
- const [text] = argumentsList;
12805
+ const [index2] = argumentsList;
12656
12806
  const { id, styleId } = getIdAndStyleId(
12657
12807
  thisArg,
12658
12808
  mirror2,
@@ -12662,13 +12812,74 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12662
12812
  styleSheetRuleCb({
12663
12813
  id,
12664
12814
  styleId,
12665
- replaceSync: text
12815
+ removes: [{ index: index2 }]
12666
12816
  });
12667
12817
  }
12668
12818
  return target.apply(thisArg, argumentsList);
12669
12819
  }
12670
12820
  )
12671
- });
12821
+ }),
12822
+ deleteRule
12823
+ );
12824
+ win.CSSStyleSheet.prototype.removeRule = makeNativeFn(
12825
+ function(index2) {
12826
+ return win.CSSStyleSheet.prototype.deleteRule.apply(this, [index2]);
12827
+ },
12828
+ deleteRule
12829
+ );
12830
+ let replace;
12831
+ if (win.CSSStyleSheet.prototype.replace) {
12832
+ replace = win.CSSStyleSheet.prototype.replace;
12833
+ win.CSSStyleSheet.prototype.replace = makeNativeFn(
12834
+ new Proxy$1(replace, {
12835
+ apply: callbackWrapper(
12836
+ (target, thisArg, argumentsList) => {
12837
+ const [text] = argumentsList;
12838
+ const { id, styleId } = getIdAndStyleId(
12839
+ thisArg,
12840
+ mirror2,
12841
+ stylesheetManager.styleMirror
12842
+ );
12843
+ if (id && id !== -1 || styleId && styleId !== -1) {
12844
+ styleSheetRuleCb({
12845
+ id,
12846
+ styleId,
12847
+ replace: text
12848
+ });
12849
+ }
12850
+ return target.apply(thisArg, argumentsList);
12851
+ }
12852
+ )
12853
+ }),
12854
+ replace
12855
+ );
12856
+ }
12857
+ let replaceSync;
12858
+ if (win.CSSStyleSheet.prototype.replaceSync) {
12859
+ replaceSync = win.CSSStyleSheet.prototype.replaceSync;
12860
+ win.CSSStyleSheet.prototype.replaceSync = makeNativeFn(
12861
+ new Proxy$1(replaceSync, {
12862
+ apply: callbackWrapper(
12863
+ (target, thisArg, argumentsList) => {
12864
+ const [text] = argumentsList;
12865
+ const { id, styleId } = getIdAndStyleId(
12866
+ thisArg,
12867
+ mirror2,
12868
+ stylesheetManager.styleMirror
12869
+ );
12870
+ if (id && id !== -1 || styleId && styleId !== -1) {
12871
+ styleSheetRuleCb({
12872
+ id,
12873
+ styleId,
12874
+ replaceSync: text
12875
+ });
12876
+ }
12877
+ return target.apply(thisArg, argumentsList);
12878
+ }
12879
+ )
12880
+ }),
12881
+ replaceSync
12882
+ );
12672
12883
  }
12673
12884
  const supportedNestedCSSRuleTypes = {};
12674
12885
  if (canMonkeyPatchNestedCSSRule("CSSGroupingRule")) {
@@ -12692,9 +12903,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12692
12903
  // eslint-disable-next-line @typescript-eslint/unbound-method
12693
12904
  deleteRule: type.prototype.deleteRule
12694
12905
  };
12695
- type.prototype.insertRule = new Proxy(
12696
- unmodifiedFunctions[typeKey].insertRule,
12697
- {
12906
+ type.prototype.insertRule = makeNativeFn(
12907
+ new Proxy$1(unmodifiedFunctions[typeKey].insertRule, {
12698
12908
  apply: callbackWrapper(
12699
12909
  (target, thisArg, argumentsList) => {
12700
12910
  const [rule2, index2] = argumentsList;
@@ -12722,11 +12932,11 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12722
12932
  return target.apply(thisArg, argumentsList);
12723
12933
  }
12724
12934
  )
12725
- }
12935
+ }),
12936
+ unmodifiedFunctions[typeKey].insertRule
12726
12937
  );
12727
- type.prototype.deleteRule = new Proxy(
12728
- unmodifiedFunctions[typeKey].deleteRule,
12729
- {
12938
+ type.prototype.deleteRule = makeNativeFn(
12939
+ new Proxy$1(unmodifiedFunctions[typeKey].deleteRule, {
12730
12940
  apply: callbackWrapper(
12731
12941
  (target, thisArg, argumentsList) => {
12732
12942
  const [index2] = argumentsList;
@@ -12747,7 +12957,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12747
12957
  return target.apply(thisArg, argumentsList);
12748
12958
  }
12749
12959
  )
12750
- }
12960
+ }),
12961
+ unmodifiedFunctions[typeKey].deleteRule
12751
12962
  );
12752
12963
  });
12753
12964
  return callbackWrapper(() => {
@@ -12814,7 +13025,7 @@ function initStyleDeclarationObserver({
12814
13025
  stylesheetManager
12815
13026
  }, { win }) {
12816
13027
  const setProperty = win.CSSStyleDeclaration.prototype.setProperty;
12817
- win.CSSStyleDeclaration.prototype.setProperty = new Proxy(setProperty, {
13028
+ win.CSSStyleDeclaration.prototype.setProperty = new Proxy$1(setProperty, {
12818
13029
  apply: callbackWrapper(
12819
13030
  (target, thisArg, argumentsList) => {
12820
13031
  var _a2;
@@ -12845,7 +13056,7 @@ function initStyleDeclarationObserver({
12845
13056
  )
12846
13057
  });
12847
13058
  const removeProperty = win.CSSStyleDeclaration.prototype.removeProperty;
12848
- win.CSSStyleDeclaration.prototype.removeProperty = new Proxy(removeProperty, {
13059
+ win.CSSStyleDeclaration.prototype.removeProperty = new Proxy$1(removeProperty, {
12849
13060
  apply: callbackWrapper(
12850
13061
  (target, thisArg, argumentsList) => {
12851
13062
  var _a2;
@@ -12927,16 +13138,19 @@ function initFontObserver({ fontCb, doc }) {
12927
13138
  const handlers = [];
12928
13139
  const fontMap = /* @__PURE__ */ new WeakMap();
12929
13140
  const originalFontFace = win.FontFace;
12930
- win.FontFace = function FontFace2(family, source, descriptors) {
12931
- const fontFace = new originalFontFace(family, source, descriptors);
12932
- fontMap.set(fontFace, {
12933
- family,
12934
- buffer: typeof source !== "string",
12935
- descriptors,
12936
- fontSource: typeof source === "string" ? source : JSON.stringify(Array.from(new Uint8Array(source)))
12937
- });
12938
- return fontFace;
12939
- };
13141
+ win.FontFace = makeNativeFn(
13142
+ function FontFace2(family, source, descriptors) {
13143
+ const fontFace = new originalFontFace(family, source, descriptors);
13144
+ fontMap.set(fontFace, {
13145
+ family,
13146
+ buffer: typeof source !== "string",
13147
+ descriptors,
13148
+ fontSource: typeof source === "string" ? source : JSON.stringify(Array.from(new Uint8Array(source)))
13149
+ });
13150
+ return fontFace;
13151
+ },
13152
+ originalFontFace
13153
+ );
12940
13154
  const restoreHandler = patch(
12941
13155
  doc.fonts,
12942
13156
  "add",
@@ -13249,7 +13463,7 @@ class CrossOriginIframeMirror {
13249
13463
  return remoteIdToIdMap;
13250
13464
  }
13251
13465
  }
13252
- class IframeManager {
13466
+ const _IframeManager = class _IframeManager2 {
13253
13467
  constructor(options) {
13254
13468
  __publicField(this, "iframes", /* @__PURE__ */ new WeakMap());
13255
13469
  __publicField(this, "crossOriginIframeMap", /* @__PURE__ */ new WeakMap());
@@ -13262,6 +13476,7 @@ class IframeManager {
13262
13476
  __publicField(this, "loadListener");
13263
13477
  __publicField(this, "stylesheetManager");
13264
13478
  __publicField(this, "recordCrossOriginIframes");
13479
+ __publicField(this, "iframeNavStats", /* @__PURE__ */ new WeakMap());
13265
13480
  this.mutationCb = options.mutationCb;
13266
13481
  this.wrappedEmit = options.wrappedEmit;
13267
13482
  this.stylesheetManager = options.stylesheetManager;
@@ -13284,6 +13499,21 @@ class IframeManager {
13284
13499
  addLoadListener(cb) {
13285
13500
  this.loadListener = cb;
13286
13501
  }
13502
+ isIframeLooping(iframeEl) {
13503
+ const now = Date.now();
13504
+ const stats = this.iframeNavStats.get(iframeEl);
13505
+ if (!stats || now - stats.windowStart > _IframeManager2.LOOP_NAV_WINDOW_MS) {
13506
+ this.iframeNavStats.set(iframeEl, { count: 1, windowStart: now });
13507
+ return false;
13508
+ }
13509
+ stats.count++;
13510
+ if (stats.count > _IframeManager2.LOOP_NAV_LIMIT) {
13511
+ stats.windowStart = now;
13512
+ stats.count = 0;
13513
+ return true;
13514
+ }
13515
+ return false;
13516
+ }
13287
13517
  attachIframe(iframeEl, childSn) {
13288
13518
  var _a2, _b;
13289
13519
  this.mutationCb({
@@ -13304,7 +13534,9 @@ class IframeManager {
13304
13534
  "message",
13305
13535
  this.handleMessage.bind(this)
13306
13536
  );
13307
- (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
13537
+ if (!this.isIframeLooping(iframeEl)) {
13538
+ (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
13539
+ }
13308
13540
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
13309
13541
  this.stylesheetManager.adoptStyleSheets(
13310
13542
  iframeEl.contentDocument.adoptedStyleSheets,
@@ -13482,7 +13714,10 @@ class IframeManager {
13482
13714
  });
13483
13715
  }
13484
13716
  }
13485
- }
13717
+ };
13718
+ __publicField(_IframeManager, "LOOP_NAV_LIMIT", 5);
13719
+ __publicField(_IframeManager, "LOOP_NAV_WINDOW_MS", 3e3);
13720
+ let IframeManager = _IframeManager;
13486
13721
  class ShadowDomManager {
13487
13722
  constructor(options) {
13488
13723
  __publicField(this, "shadowDoms", /* @__PURE__ */ new WeakSet());
@@ -13972,6 +14207,26 @@ function fnv1aHash(buffer) {
13972
14207
  function canSnapshotCanvas() {
13973
14208
  return typeof OffscreenCanvas !== "undefined";
13974
14209
  }
14210
+ const FPS_WORKER_SOURCE = `
14211
+ var _C='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
14212
+ function _enc(ab){var b=new Uint8Array(ab),i,n=b.length,o='';for(i=0;i<n;i+=3){o+=_C[b[i]>>2];o+=_C[(b[i]&3)<<4|b[i+1]>>4];o+=_C[(b[i+1]&15)<<2|b[i+2]>>6];o+=_C[b[i+2]&63];}if(n%3===2){o=o.substring(0,o.length-1)+'=';}else if(n%3===1){o=o.substring(0,o.length-2)+'==';}return o;}
14213
+ function _fp(ab){var v=new Uint8Array(ab),h=0x811c9dc5;for(var i=0;i<v.length;i++){h^=v[i];h=(h*0x01000193)|0;}return (h>>>0).toString(16);}
14214
+ var _last=new Map(),_cv=null,_ctx=null;
14215
+ self.onmessage=async function(e){
14216
+ var d=e.data,id=d.id,bm=d.bitmap,w=d.width,h=d.height,opt=d.dataURLOptions;
14217
+ try{
14218
+ if(!('OffscreenCanvas' in self)){bm.close();return self.postMessage({id:id});}
14219
+ if(!_cv||_cv.width!==w||_cv.height!==h){_cv=new OffscreenCanvas(w,h);_ctx=_cv.getContext('2d');}
14220
+ _ctx.clearRect(0,0,w,h);_ctx.drawImage(bm,0,0);bm.close();
14221
+ var blob=await _cv.convertToBlob(opt);
14222
+ var buf=await blob.arrayBuffer();
14223
+ var fp=_fp(buf);
14224
+ if(_last.get(id)===fp)return self.postMessage({id:id});
14225
+ _last.set(id,fp);
14226
+ self.postMessage({id:id,type:blob.type,base64:_enc(buf),width:w,height:h});
14227
+ }catch(err){try{bm.close();}catch(_){}self.postMessage({id:id});}
14228
+ };
14229
+ `;
13975
14230
  class CanvasManager {
13976
14231
  constructor(options) {
13977
14232
  __publicField(this, "pendingCanvasMutations", /* @__PURE__ */ new Map());
@@ -13989,6 +14244,7 @@ class CanvasManager {
13989
14244
  __publicField(this, "lastFingerprintMap", /* @__PURE__ */ new Map());
13990
14245
  __publicField(this, "snapshotCanvas", null);
13991
14246
  __publicField(this, "snapshotCtx", null);
14247
+ __publicField(this, "worker", null);
13992
14248
  __publicField(this, "lastSnapshotTime", 0);
13993
14249
  __publicField(this, "processMutation", (target, mutation) => {
13994
14250
  const newFrame = this.rafStamps.invokeId && this.rafStamps.latestId !== this.rafStamps.invokeId;
@@ -14010,10 +14266,12 @@ class CanvasManager {
14010
14266
  this.startPendingCanvasMutationFlusher();
14011
14267
  }
14012
14268
  if (recordCanvas && typeof sampling === "number" && canSnapshotCanvas()) {
14269
+ this.worker = this.initFPSWorker();
14013
14270
  this.initCanvasFPSObserver();
14014
14271
  }
14015
14272
  }
14016
14273
  reset() {
14274
+ var _a2;
14017
14275
  this.pendingCanvasMutations.clear();
14018
14276
  this.restoreHandlers.forEach((handler) => {
14019
14277
  try {
@@ -14029,6 +14287,8 @@ class CanvasManager {
14029
14287
  this.lastFingerprintMap = /* @__PURE__ */ new Map();
14030
14288
  this.snapshotCanvas = null;
14031
14289
  this.snapshotCtx = null;
14290
+ (_a2 = this.worker) == null ? void 0 : _a2.terminate();
14291
+ this.worker = null;
14032
14292
  }
14033
14293
  freeze() {
14034
14294
  this.frozen = true;
@@ -14042,6 +14302,29 @@ class CanvasManager {
14042
14302
  unlock() {
14043
14303
  this.locked = false;
14044
14304
  }
14305
+ initFPSWorker() {
14306
+ try {
14307
+ const worker = new Worker(
14308
+ "data:application/javascript;charset=utf-8," + encodeURIComponent(FPS_WORKER_SOURCE)
14309
+ );
14310
+ worker.onmessage = (e2) => {
14311
+ const data = e2.data;
14312
+ const { id } = data;
14313
+ this.snapshotInProgressMap.set(id, false);
14314
+ if (data.base64 === void 0) return;
14315
+ this.emitCanvasSnapshot(
14316
+ id,
14317
+ data.base64,
14318
+ data.type || "image/png",
14319
+ data.width || 0,
14320
+ data.height || 0
14321
+ );
14322
+ };
14323
+ return worker;
14324
+ } catch (e2) {
14325
+ return null;
14326
+ }
14327
+ }
14045
14328
  /**
14046
14329
  * Begin observing canvas activity inside `win` — the top window, or the
14047
14330
  * `contentWindow` of a same-origin iframe. De-duplicated, so it is safe to
@@ -14248,9 +14531,22 @@ class CanvasManager {
14248
14531
  }
14249
14532
  const width = canvas.width;
14250
14533
  const height = canvas.height;
14251
- createImageBitmap(canvas).then(
14252
- (bitmap) => this.snapshotImageBitmap(id, bitmap, width, height, dataURLOptions)
14253
- ).catch(() => {
14534
+ createImageBitmap(canvas).then((bitmap) => {
14535
+ if (this.worker) {
14536
+ this.worker.postMessage(
14537
+ { id, bitmap, width, height, dataURLOptions },
14538
+ [bitmap]
14539
+ );
14540
+ } else {
14541
+ void this.snapshotImageBitmap(
14542
+ id,
14543
+ bitmap,
14544
+ width,
14545
+ height,
14546
+ dataURLOptions
14547
+ );
14548
+ }
14549
+ }).catch(() => {
14254
14550
  this.snapshotInProgressMap.set(id, false);
14255
14551
  });
14256
14552
  });
@@ -14783,9 +15079,20 @@ function record(options = {}) {
14783
15079
  hooks
14784
15080
  );
14785
15081
  };
15082
+ const iframeObservers = /* @__PURE__ */ new Map();
14786
15083
  iframeManager.addLoadListener((iframeEl) => {
14787
15084
  try {
14788
- handlers.push(observe(iframeEl.contentDocument));
15085
+ const prevCleanup = iframeObservers.get(iframeEl);
15086
+ if (prevCleanup) {
15087
+ try {
15088
+ prevCleanup();
15089
+ } catch (e2) {
15090
+ }
15091
+ iframeObservers.delete(iframeEl);
15092
+ }
15093
+ const cleanup = observe(iframeEl.contentDocument);
15094
+ handlers.push(cleanup);
15095
+ iframeObservers.set(iframeEl, cleanup);
14789
15096
  } catch (error) {
14790
15097
  console.warn(error);
14791
15098
  }