@kalayanasundaram123/rrweb 2.0.4 → 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.
package/dist/rrweb.cjs CHANGED
@@ -25,14 +25,18 @@ const testableAccessors$1 = {
25
25
  "ownerDocument"
26
26
  ],
27
27
  ShadowRoot: ["host", "styleSheets"],
28
- Element: ["shadowRoot", "querySelector", "querySelectorAll"],
29
- MutationObserver: []
28
+ Element: ["shadowRoot"],
29
+ MutationObserver: [],
30
+ EventTarget: []
30
31
  };
31
32
  const testableMethods$1 = {
32
33
  Node: ["contains", "getRootNode"],
33
34
  ShadowRoot: ["getSelection"],
34
- Element: [],
35
- MutationObserver: ["constructor"]
35
+ // PR #1802: moved from testableAccessors
36
+ Element: ["querySelector", "querySelectorAll"],
37
+ MutationObserver: ["constructor"],
38
+ // PR #1814
39
+ EventTarget: ["addEventListener", "removeEventListener"]
36
40
  };
37
41
  const untaintedBasePrototype$1 = {};
38
42
  const untaintedBaseIframeCleanup$1 = {};
@@ -157,10 +161,10 @@ function shadowRoot$1(n2) {
157
161
  return getUntaintedAccessor$1("Element", n2, "shadowRoot");
158
162
  }
159
163
  function querySelector$1(n2, selectors) {
160
- return getUntaintedAccessor$1("Element", n2, "querySelector")(selectors);
164
+ return getUntaintedMethod$1("Element", n2, "querySelector")(selectors);
161
165
  }
162
166
  function querySelectorAll$1(n2, selectors) {
163
- return getUntaintedAccessor$1("Element", n2, "querySelectorAll")(selectors);
167
+ return getUntaintedMethod$1("Element", n2, "querySelectorAll")(selectors);
164
168
  }
165
169
  function mutationObserverCtor$1() {
166
170
  return [
@@ -169,10 +173,67 @@ function mutationObserverCtor$1() {
169
173
  })
170
174
  ];
171
175
  }
176
+ function getUntaintedProxy$1() {
177
+ var _a2;
178
+ let UntaintedProxy = globalThis.Proxy;
179
+ try {
180
+ if (typeof UntaintedProxy !== "function" || !Function.prototype.toString.call(UntaintedProxy).includes("[native code]")) {
181
+ const frame = document.createElement("iframe");
182
+ frame.style.display = "none";
183
+ document.documentElement.appendChild(frame);
184
+ UntaintedProxy = ((_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) ?? UntaintedProxy;
185
+ document.documentElement.removeChild(frame);
186
+ }
187
+ } catch {
188
+ }
189
+ return UntaintedProxy;
190
+ }
172
191
  let nowTimestamp$1 = Date.now;
173
192
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
174
193
  nowTimestamp$1 = () => (/* @__PURE__ */ new Date()).getTime();
175
194
  }
195
+ const _rrwebNativeMap$2 = /* @__PURE__ */ new WeakMap();
196
+ let _nativeToStringStr$2 = "";
197
+ (function _installToStringProxy() {
198
+ var _a2;
199
+ const _nativeToString = Function.prototype.toString;
200
+ _nativeToStringStr$2 = _nativeToString.call(_nativeToString);
201
+ let _Proxy = globalThis.Proxy;
202
+ try {
203
+ if (typeof _Proxy !== "function" || !_nativeToString.call(_Proxy).includes("[native code]")) {
204
+ const frame = document.createElement("iframe");
205
+ frame.style.display = "none";
206
+ document.documentElement.appendChild(frame);
207
+ _Proxy = ((_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) ?? _Proxy;
208
+ document.documentElement.removeChild(frame);
209
+ }
210
+ } catch {
211
+ }
212
+ const _fnProto = Object.getPrototypeOf(_nativeToString);
213
+ const _proxy = new _Proxy(_nativeToString, {
214
+ apply(target, thisArg, args) {
215
+ const str = _rrwebNativeMap$2.get(thisArg);
216
+ if (str !== void 0) return str;
217
+ if (thisArg != null && typeof thisArg === "function" && !_fnProto.isPrototypeOf(
218
+ thisArg.toString
219
+ )) {
220
+ return thisArg.toString();
221
+ }
222
+ return target.apply(thisArg, args);
223
+ }
224
+ });
225
+ _rrwebNativeMap$2.set(_proxy, _nativeToStringStr$2);
226
+ Object.defineProperty(Function.prototype, "toString", {
227
+ value: _proxy,
228
+ configurable: true,
229
+ writable: true
230
+ });
231
+ })();
232
+ function makeNativeFn$1(fn, nativeFn) {
233
+ const name = fn.name || nativeFn.name || "";
234
+ _rrwebNativeMap$2.set(fn, _nativeToStringStr$2.replace("toString", name));
235
+ return fn;
236
+ }
176
237
  function patch$1(source, name, replacement) {
177
238
  try {
178
239
  if (!(name in source)) {
@@ -189,6 +250,10 @@ function patch$1(source, name, replacement) {
189
250
  value: original
190
251
  }
191
252
  });
253
+ _rrwebNativeMap$2.set(
254
+ wrapped,
255
+ _nativeToStringStr$2.replace("toString", name)
256
+ );
192
257
  }
193
258
  source[name] = wrapped;
194
259
  return () => {
@@ -214,7 +279,9 @@ const index$1 = {
214
279
  querySelectorAll: querySelectorAll$1,
215
280
  nowTimestamp: nowTimestamp$1,
216
281
  mutationObserverCtor: mutationObserverCtor$1,
217
- patch: patch$1
282
+ patch: patch$1,
283
+ makeNativeFn: makeNativeFn$1,
284
+ getUntaintedProxy: getUntaintedProxy$1
218
285
  };
219
286
  function isElement(n2) {
220
287
  return n2.nodeType === n2.ELEMENT_NODE;
@@ -5758,6 +5825,43 @@ var __defProp22 = Object.defineProperty;
5758
5825
  var __defNormalProp22 = (obj, key, value) => key in obj ? __defProp22(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5759
5826
  var __publicField22 = (obj, key, value) => __defNormalProp22(obj, typeof key !== "symbol" ? key + "" : key, value);
5760
5827
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) ;
5828
+ const _rrwebNativeMap$1 = /* @__PURE__ */ new WeakMap();
5829
+ let _nativeToStringStr$1 = "";
5830
+ (function _installToStringProxy2() {
5831
+ var _a2;
5832
+ const _nativeToString = Function.prototype.toString;
5833
+ _nativeToStringStr$1 = _nativeToString.call(_nativeToString);
5834
+ let _Proxy = globalThis.Proxy;
5835
+ try {
5836
+ if (typeof _Proxy !== "function" || !_nativeToString.call(_Proxy).includes("[native code]")) {
5837
+ const frame = document.createElement("iframe");
5838
+ frame.style.display = "none";
5839
+ document.documentElement.appendChild(frame);
5840
+ _Proxy = ((_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) ?? _Proxy;
5841
+ document.documentElement.removeChild(frame);
5842
+ }
5843
+ } catch {
5844
+ }
5845
+ const _fnProto = Object.getPrototypeOf(_nativeToString);
5846
+ const _proxy = new _Proxy(_nativeToString, {
5847
+ apply(target, thisArg, args) {
5848
+ const str = _rrwebNativeMap$1.get(thisArg);
5849
+ if (str !== void 0) return str;
5850
+ if (thisArg != null && typeof thisArg === "function" && !_fnProto.isPrototypeOf(
5851
+ thisArg.toString
5852
+ )) {
5853
+ return thisArg.toString();
5854
+ }
5855
+ return target.apply(thisArg, args);
5856
+ }
5857
+ });
5858
+ _rrwebNativeMap$1.set(_proxy, _nativeToStringStr$1);
5859
+ Object.defineProperty(Function.prototype, "toString", {
5860
+ value: _proxy,
5861
+ configurable: true,
5862
+ writable: true
5863
+ });
5864
+ })();
5761
5865
  let Mirror$1 = class Mirror2 {
5762
5866
  constructor() {
5763
5867
  __publicField22(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -10850,14 +10954,18 @@ const testableAccessors = {
10850
10954
  "ownerDocument"
10851
10955
  ],
10852
10956
  ShadowRoot: ["host", "styleSheets"],
10853
- Element: ["shadowRoot", "querySelector", "querySelectorAll"],
10854
- MutationObserver: []
10957
+ Element: ["shadowRoot"],
10958
+ MutationObserver: [],
10959
+ EventTarget: []
10855
10960
  };
10856
10961
  const testableMethods = {
10857
10962
  Node: ["contains", "getRootNode"],
10858
10963
  ShadowRoot: ["getSelection"],
10859
- Element: [],
10860
- MutationObserver: ["constructor"]
10964
+ // PR #1802: moved from testableAccessors
10965
+ Element: ["querySelector", "querySelectorAll"],
10966
+ MutationObserver: ["constructor"],
10967
+ // PR #1814
10968
+ EventTarget: ["addEventListener", "removeEventListener"]
10861
10969
  };
10862
10970
  const untaintedBasePrototype = {};
10863
10971
  const untaintedBaseIframeCleanup = {};
@@ -10982,10 +11090,10 @@ function shadowRoot(n2) {
10982
11090
  return getUntaintedAccessor("Element", n2, "shadowRoot");
10983
11091
  }
10984
11092
  function querySelector(n2, selectors) {
10985
- return getUntaintedAccessor("Element", n2, "querySelector")(selectors);
11093
+ return getUntaintedMethod("Element", n2, "querySelector")(selectors);
10986
11094
  }
10987
11095
  function querySelectorAll(n2, selectors) {
10988
- return getUntaintedAccessor("Element", n2, "querySelectorAll")(selectors);
11096
+ return getUntaintedMethod("Element", n2, "querySelectorAll")(selectors);
10989
11097
  }
10990
11098
  function mutationObserverCtor() {
10991
11099
  return [
@@ -10994,10 +11102,67 @@ function mutationObserverCtor() {
10994
11102
  })
10995
11103
  ];
10996
11104
  }
11105
+ function getUntaintedProxy() {
11106
+ var _a2;
11107
+ let UntaintedProxy = globalThis.Proxy;
11108
+ try {
11109
+ if (typeof UntaintedProxy !== "function" || !Function.prototype.toString.call(UntaintedProxy).includes("[native code]")) {
11110
+ const frame = document.createElement("iframe");
11111
+ frame.style.display = "none";
11112
+ document.documentElement.appendChild(frame);
11113
+ UntaintedProxy = ((_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) ?? UntaintedProxy;
11114
+ document.documentElement.removeChild(frame);
11115
+ }
11116
+ } catch {
11117
+ }
11118
+ return UntaintedProxy;
11119
+ }
10997
11120
  let nowTimestamp = Date.now;
10998
11121
  if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) {
10999
11122
  nowTimestamp = () => (/* @__PURE__ */ new Date()).getTime();
11000
11123
  }
11124
+ const _rrwebNativeMap = /* @__PURE__ */ new WeakMap();
11125
+ let _nativeToStringStr = "";
11126
+ (function _installToStringProxy3() {
11127
+ var _a2;
11128
+ const _nativeToString = Function.prototype.toString;
11129
+ _nativeToStringStr = _nativeToString.call(_nativeToString);
11130
+ let _Proxy = globalThis.Proxy;
11131
+ try {
11132
+ if (typeof _Proxy !== "function" || !_nativeToString.call(_Proxy).includes("[native code]")) {
11133
+ const frame = document.createElement("iframe");
11134
+ frame.style.display = "none";
11135
+ document.documentElement.appendChild(frame);
11136
+ _Proxy = ((_a2 = frame.contentWindow) == null ? void 0 : _a2.Proxy) ?? _Proxy;
11137
+ document.documentElement.removeChild(frame);
11138
+ }
11139
+ } catch {
11140
+ }
11141
+ const _fnProto = Object.getPrototypeOf(_nativeToString);
11142
+ const _proxy = new _Proxy(_nativeToString, {
11143
+ apply(target, thisArg, args) {
11144
+ const str = _rrwebNativeMap.get(thisArg);
11145
+ if (str !== void 0) return str;
11146
+ if (thisArg != null && typeof thisArg === "function" && !_fnProto.isPrototypeOf(
11147
+ thisArg.toString
11148
+ )) {
11149
+ return thisArg.toString();
11150
+ }
11151
+ return target.apply(thisArg, args);
11152
+ }
11153
+ });
11154
+ _rrwebNativeMap.set(_proxy, _nativeToStringStr);
11155
+ Object.defineProperty(Function.prototype, "toString", {
11156
+ value: _proxy,
11157
+ configurable: true,
11158
+ writable: true
11159
+ });
11160
+ })();
11161
+ function makeNativeFn(fn, nativeFn) {
11162
+ const name = fn.name || nativeFn.name || "";
11163
+ _rrwebNativeMap.set(fn, _nativeToStringStr.replace("toString", name));
11164
+ return fn;
11165
+ }
11001
11166
  function patch(source, name, replacement) {
11002
11167
  try {
11003
11168
  if (!(name in source)) {
@@ -11014,6 +11179,10 @@ function patch(source, name, replacement) {
11014
11179
  value: original
11015
11180
  }
11016
11181
  });
11182
+ _rrwebNativeMap.set(
11183
+ wrapped,
11184
+ _nativeToStringStr.replace("toString", name)
11185
+ );
11017
11186
  }
11018
11187
  source[name] = wrapped;
11019
11188
  return () => {
@@ -11039,12 +11208,23 @@ const index = {
11039
11208
  querySelectorAll,
11040
11209
  nowTimestamp,
11041
11210
  mutationObserverCtor,
11042
- patch
11211
+ patch,
11212
+ makeNativeFn,
11213
+ getUntaintedProxy
11043
11214
  };
11044
11215
  function on(type, fn, target = document) {
11045
11216
  const options = { capture: true, passive: true };
11046
- target.addEventListener(type, fn, options);
11047
- return () => target.removeEventListener(type, fn, options);
11217
+ const eventTarget = target;
11218
+ getUntaintedMethod("EventTarget", eventTarget, "addEventListener")(
11219
+ type,
11220
+ fn,
11221
+ options
11222
+ );
11223
+ return () => getUntaintedMethod("EventTarget", eventTarget, "removeEventListener")(
11224
+ type,
11225
+ fn,
11226
+ options
11227
+ );
11048
11228
  }
11049
11229
  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.";
11050
11230
  exports.mirror = {
@@ -11106,20 +11286,27 @@ function throttle(func, wait, options = {}) {
11106
11286
  }
11107
11287
  function hookSetter(target, key, d, isRevoked, win = window) {
11108
11288
  const original = win.Object.getOwnPropertyDescriptor(target, key);
11109
- win.Object.defineProperty(
11110
- target,
11111
- key,
11112
- isRevoked ? d : {
11113
- set(value) {
11289
+ if (!isRevoked && (original == null ? void 0 : original.set)) {
11290
+ const hookedSetter = function(value) {
11291
+ setTimeout(() => {
11292
+ d.set.call(this, value);
11293
+ }, 0);
11294
+ original.set.call(this, value);
11295
+ };
11296
+ makeNativeFn(hookedSetter, original.set);
11297
+ win.Object.defineProperty(target, key, { set: hookedSetter });
11298
+ } else {
11299
+ win.Object.defineProperty(
11300
+ target,
11301
+ key,
11302
+ isRevoked ? d : { set(value) {
11114
11303
  setTimeout(() => {
11115
11304
  d.set.call(this, value);
11116
11305
  }, 0);
11117
- if (original && original.set) {
11118
- original.set.call(this, value);
11119
- }
11120
- }
11121
- }
11122
- );
11306
+ if (original && original.set) original.set.call(this, value);
11307
+ } }
11308
+ );
11309
+ }
11123
11310
  return () => hookSetter(target, key, original || {}, true);
11124
11311
  }
11125
11312
  function getWindowScroll(win) {
@@ -12147,6 +12334,7 @@ const callbackWrapper = (cb) => {
12147
12334
  };
12148
12335
  return rrwebWrapped;
12149
12336
  };
12337
+ const Proxy$1 = getUntaintedProxy();
12150
12338
  const mutationBuffers = [];
12151
12339
  function getEventTarget(event) {
12152
12340
  try {
@@ -12550,61 +12738,11 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12550
12738
  };
12551
12739
  }
12552
12740
  const insertRule = win.CSSStyleSheet.prototype.insertRule;
12553
- win.CSSStyleSheet.prototype.insertRule = new Proxy(insertRule, {
12554
- apply: callbackWrapper(
12555
- (target, thisArg, argumentsList) => {
12556
- const [rule2, index2] = argumentsList;
12557
- const { id, styleId } = getIdAndStyleId(
12558
- thisArg,
12559
- mirror2,
12560
- stylesheetManager.styleMirror
12561
- );
12562
- if (id && id !== -1 || styleId && styleId !== -1) {
12563
- styleSheetRuleCb({
12564
- id,
12565
- styleId,
12566
- adds: [{ rule: rule2, index: index2 }]
12567
- });
12568
- }
12569
- return target.apply(thisArg, argumentsList);
12570
- }
12571
- )
12572
- });
12573
- win.CSSStyleSheet.prototype.addRule = function(selector, styleBlock, index2 = this.cssRules.length) {
12574
- const rule2 = `${selector} { ${styleBlock} }`;
12575
- return win.CSSStyleSheet.prototype.insertRule.apply(this, [rule2, index2]);
12576
- };
12577
- const deleteRule = win.CSSStyleSheet.prototype.deleteRule;
12578
- win.CSSStyleSheet.prototype.deleteRule = new Proxy(deleteRule, {
12579
- apply: callbackWrapper(
12580
- (target, thisArg, argumentsList) => {
12581
- const [index2] = argumentsList;
12582
- const { id, styleId } = getIdAndStyleId(
12583
- thisArg,
12584
- mirror2,
12585
- stylesheetManager.styleMirror
12586
- );
12587
- if (id && id !== -1 || styleId && styleId !== -1) {
12588
- styleSheetRuleCb({
12589
- id,
12590
- styleId,
12591
- removes: [{ index: index2 }]
12592
- });
12593
- }
12594
- return target.apply(thisArg, argumentsList);
12595
- }
12596
- )
12597
- });
12598
- win.CSSStyleSheet.prototype.removeRule = function(index2) {
12599
- return win.CSSStyleSheet.prototype.deleteRule.apply(this, [index2]);
12600
- };
12601
- let replace;
12602
- if (win.CSSStyleSheet.prototype.replace) {
12603
- replace = win.CSSStyleSheet.prototype.replace;
12604
- win.CSSStyleSheet.prototype.replace = new Proxy(replace, {
12741
+ win.CSSStyleSheet.prototype.insertRule = makeNativeFn(
12742
+ new Proxy$1(insertRule, {
12605
12743
  apply: callbackWrapper(
12606
12744
  (target, thisArg, argumentsList) => {
12607
- const [text] = argumentsList;
12745
+ const [rule2, index2] = argumentsList;
12608
12746
  const { id, styleId } = getIdAndStyleId(
12609
12747
  thisArg,
12610
12748
  mirror2,
@@ -12614,21 +12752,28 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12614
12752
  styleSheetRuleCb({
12615
12753
  id,
12616
12754
  styleId,
12617
- replace: text
12755
+ adds: [{ rule: rule2, index: index2 }]
12618
12756
  });
12619
12757
  }
12620
12758
  return target.apply(thisArg, argumentsList);
12621
12759
  }
12622
12760
  )
12623
- });
12624
- }
12625
- let replaceSync;
12626
- if (win.CSSStyleSheet.prototype.replaceSync) {
12627
- replaceSync = win.CSSStyleSheet.prototype.replaceSync;
12628
- win.CSSStyleSheet.prototype.replaceSync = new Proxy(replaceSync, {
12761
+ }),
12762
+ insertRule
12763
+ );
12764
+ win.CSSStyleSheet.prototype.addRule = makeNativeFn(
12765
+ function(selector, styleBlock, index2 = this.cssRules.length) {
12766
+ const rule2 = `${selector} { ${styleBlock} }`;
12767
+ return win.CSSStyleSheet.prototype.insertRule.apply(this, [rule2, index2]);
12768
+ },
12769
+ insertRule
12770
+ );
12771
+ const deleteRule = win.CSSStyleSheet.prototype.deleteRule;
12772
+ win.CSSStyleSheet.prototype.deleteRule = makeNativeFn(
12773
+ new Proxy$1(deleteRule, {
12629
12774
  apply: callbackWrapper(
12630
12775
  (target, thisArg, argumentsList) => {
12631
- const [text] = argumentsList;
12776
+ const [index2] = argumentsList;
12632
12777
  const { id, styleId } = getIdAndStyleId(
12633
12778
  thisArg,
12634
12779
  mirror2,
@@ -12638,13 +12783,74 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12638
12783
  styleSheetRuleCb({
12639
12784
  id,
12640
12785
  styleId,
12641
- replaceSync: text
12786
+ removes: [{ index: index2 }]
12642
12787
  });
12643
12788
  }
12644
12789
  return target.apply(thisArg, argumentsList);
12645
12790
  }
12646
12791
  )
12647
- });
12792
+ }),
12793
+ deleteRule
12794
+ );
12795
+ win.CSSStyleSheet.prototype.removeRule = makeNativeFn(
12796
+ function(index2) {
12797
+ return win.CSSStyleSheet.prototype.deleteRule.apply(this, [index2]);
12798
+ },
12799
+ deleteRule
12800
+ );
12801
+ let replace;
12802
+ if (win.CSSStyleSheet.prototype.replace) {
12803
+ replace = win.CSSStyleSheet.prototype.replace;
12804
+ win.CSSStyleSheet.prototype.replace = makeNativeFn(
12805
+ new Proxy$1(replace, {
12806
+ apply: callbackWrapper(
12807
+ (target, thisArg, argumentsList) => {
12808
+ const [text] = argumentsList;
12809
+ const { id, styleId } = getIdAndStyleId(
12810
+ thisArg,
12811
+ mirror2,
12812
+ stylesheetManager.styleMirror
12813
+ );
12814
+ if (id && id !== -1 || styleId && styleId !== -1) {
12815
+ styleSheetRuleCb({
12816
+ id,
12817
+ styleId,
12818
+ replace: text
12819
+ });
12820
+ }
12821
+ return target.apply(thisArg, argumentsList);
12822
+ }
12823
+ )
12824
+ }),
12825
+ replace
12826
+ );
12827
+ }
12828
+ let replaceSync;
12829
+ if (win.CSSStyleSheet.prototype.replaceSync) {
12830
+ replaceSync = win.CSSStyleSheet.prototype.replaceSync;
12831
+ win.CSSStyleSheet.prototype.replaceSync = makeNativeFn(
12832
+ new Proxy$1(replaceSync, {
12833
+ apply: callbackWrapper(
12834
+ (target, thisArg, argumentsList) => {
12835
+ const [text] = argumentsList;
12836
+ const { id, styleId } = getIdAndStyleId(
12837
+ thisArg,
12838
+ mirror2,
12839
+ stylesheetManager.styleMirror
12840
+ );
12841
+ if (id && id !== -1 || styleId && styleId !== -1) {
12842
+ styleSheetRuleCb({
12843
+ id,
12844
+ styleId,
12845
+ replaceSync: text
12846
+ });
12847
+ }
12848
+ return target.apply(thisArg, argumentsList);
12849
+ }
12850
+ )
12851
+ }),
12852
+ replaceSync
12853
+ );
12648
12854
  }
12649
12855
  const supportedNestedCSSRuleTypes = {};
12650
12856
  if (canMonkeyPatchNestedCSSRule("CSSGroupingRule")) {
@@ -12668,9 +12874,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12668
12874
  // eslint-disable-next-line @typescript-eslint/unbound-method
12669
12875
  deleteRule: type.prototype.deleteRule
12670
12876
  };
12671
- type.prototype.insertRule = new Proxy(
12672
- unmodifiedFunctions[typeKey].insertRule,
12673
- {
12877
+ type.prototype.insertRule = makeNativeFn(
12878
+ new Proxy$1(unmodifiedFunctions[typeKey].insertRule, {
12674
12879
  apply: callbackWrapper(
12675
12880
  (target, thisArg, argumentsList) => {
12676
12881
  const [rule2, index2] = argumentsList;
@@ -12698,11 +12903,11 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12698
12903
  return target.apply(thisArg, argumentsList);
12699
12904
  }
12700
12905
  )
12701
- }
12906
+ }),
12907
+ unmodifiedFunctions[typeKey].insertRule
12702
12908
  );
12703
- type.prototype.deleteRule = new Proxy(
12704
- unmodifiedFunctions[typeKey].deleteRule,
12705
- {
12909
+ type.prototype.deleteRule = makeNativeFn(
12910
+ new Proxy$1(unmodifiedFunctions[typeKey].deleteRule, {
12706
12911
  apply: callbackWrapper(
12707
12912
  (target, thisArg, argumentsList) => {
12708
12913
  const [index2] = argumentsList;
@@ -12723,7 +12928,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror: mirror2, stylesheetM
12723
12928
  return target.apply(thisArg, argumentsList);
12724
12929
  }
12725
12930
  )
12726
- }
12931
+ }),
12932
+ unmodifiedFunctions[typeKey].deleteRule
12727
12933
  );
12728
12934
  });
12729
12935
  return callbackWrapper(() => {
@@ -12790,7 +12996,7 @@ function initStyleDeclarationObserver({
12790
12996
  stylesheetManager
12791
12997
  }, { win }) {
12792
12998
  const setProperty = win.CSSStyleDeclaration.prototype.setProperty;
12793
- win.CSSStyleDeclaration.prototype.setProperty = new Proxy(setProperty, {
12999
+ win.CSSStyleDeclaration.prototype.setProperty = new Proxy$1(setProperty, {
12794
13000
  apply: callbackWrapper(
12795
13001
  (target, thisArg, argumentsList) => {
12796
13002
  var _a2;
@@ -12821,7 +13027,7 @@ function initStyleDeclarationObserver({
12821
13027
  )
12822
13028
  });
12823
13029
  const removeProperty = win.CSSStyleDeclaration.prototype.removeProperty;
12824
- win.CSSStyleDeclaration.prototype.removeProperty = new Proxy(removeProperty, {
13030
+ win.CSSStyleDeclaration.prototype.removeProperty = new Proxy$1(removeProperty, {
12825
13031
  apply: callbackWrapper(
12826
13032
  (target, thisArg, argumentsList) => {
12827
13033
  var _a2;
@@ -12903,16 +13109,19 @@ function initFontObserver({ fontCb, doc }) {
12903
13109
  const handlers = [];
12904
13110
  const fontMap = /* @__PURE__ */ new WeakMap();
12905
13111
  const originalFontFace = win.FontFace;
12906
- win.FontFace = function FontFace2(family, source, descriptors) {
12907
- const fontFace = new originalFontFace(family, source, descriptors);
12908
- fontMap.set(fontFace, {
12909
- family,
12910
- buffer: typeof source !== "string",
12911
- descriptors,
12912
- fontSource: typeof source === "string" ? source : JSON.stringify(Array.from(new Uint8Array(source)))
12913
- });
12914
- return fontFace;
12915
- };
13112
+ win.FontFace = makeNativeFn(
13113
+ function FontFace2(family, source, descriptors) {
13114
+ const fontFace = new originalFontFace(family, source, descriptors);
13115
+ fontMap.set(fontFace, {
13116
+ family,
13117
+ buffer: typeof source !== "string",
13118
+ descriptors,
13119
+ fontSource: typeof source === "string" ? source : JSON.stringify(Array.from(new Uint8Array(source)))
13120
+ });
13121
+ return fontFace;
13122
+ },
13123
+ originalFontFace
13124
+ );
12916
13125
  const restoreHandler = patch(
12917
13126
  doc.fonts,
12918
13127
  "add",
@@ -13225,7 +13434,7 @@ class CrossOriginIframeMirror {
13225
13434
  return remoteIdToIdMap;
13226
13435
  }
13227
13436
  }
13228
- class IframeManager {
13437
+ const _IframeManager = class _IframeManager {
13229
13438
  constructor(options) {
13230
13439
  __publicField(this, "iframes", /* @__PURE__ */ new WeakMap());
13231
13440
  __publicField(this, "crossOriginIframeMap", /* @__PURE__ */ new WeakMap());
@@ -13238,6 +13447,9 @@ class IframeManager {
13238
13447
  __publicField(this, "loadListener");
13239
13448
  __publicField(this, "stylesheetManager");
13240
13449
  __publicField(this, "recordCrossOriginIframes");
13450
+ // Loop detection: track rapid re-navigations per iframe to prevent CPU spikes
13451
+ // from redirect loops (e.g. OAuth silent-refresh frames that can't complete auth).
13452
+ __publicField(this, "iframeNavStats", /* @__PURE__ */ new WeakMap());
13241
13453
  this.mutationCb = options.mutationCb;
13242
13454
  this.wrappedEmit = options.wrappedEmit;
13243
13455
  this.stylesheetManager = options.stylesheetManager;
@@ -13260,6 +13472,21 @@ class IframeManager {
13260
13472
  addLoadListener(cb) {
13261
13473
  this.loadListener = cb;
13262
13474
  }
13475
+ isIframeLooping(iframeEl) {
13476
+ const now = Date.now();
13477
+ const stats = this.iframeNavStats.get(iframeEl);
13478
+ if (!stats || now - stats.windowStart > _IframeManager.LOOP_NAV_WINDOW_MS) {
13479
+ this.iframeNavStats.set(iframeEl, { count: 1, windowStart: now });
13480
+ return false;
13481
+ }
13482
+ stats.count++;
13483
+ if (stats.count > _IframeManager.LOOP_NAV_LIMIT) {
13484
+ stats.windowStart = now;
13485
+ stats.count = 0;
13486
+ return true;
13487
+ }
13488
+ return false;
13489
+ }
13263
13490
  attachIframe(iframeEl, childSn) {
13264
13491
  var _a2, _b;
13265
13492
  this.mutationCb({
@@ -13280,7 +13507,9 @@ class IframeManager {
13280
13507
  "message",
13281
13508
  this.handleMessage.bind(this)
13282
13509
  );
13283
- (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
13510
+ if (!this.isIframeLooping(iframeEl)) {
13511
+ (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
13512
+ }
13284
13513
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
13285
13514
  this.stylesheetManager.adoptStyleSheets(
13286
13515
  iframeEl.contentDocument.adoptedStyleSheets,
@@ -13458,7 +13687,10 @@ class IframeManager {
13458
13687
  });
13459
13688
  }
13460
13689
  }
13461
- }
13690
+ };
13691
+ __publicField(_IframeManager, "LOOP_NAV_LIMIT", 5);
13692
+ __publicField(_IframeManager, "LOOP_NAV_WINDOW_MS", 3e3);
13693
+ let IframeManager = _IframeManager;
13462
13694
  class ShadowDomManager {
13463
13695
  constructor(options) {
13464
13696
  __publicField(this, "shadowDoms", /* @__PURE__ */ new WeakSet());
@@ -14842,9 +15074,20 @@ function record(options = {}) {
14842
15074
  hooks
14843
15075
  );
14844
15076
  };
15077
+ const iframeObservers = /* @__PURE__ */ new Map();
14845
15078
  iframeManager.addLoadListener((iframeEl) => {
14846
15079
  try {
14847
- handlers.push(observe(iframeEl.contentDocument));
15080
+ const prevCleanup = iframeObservers.get(iframeEl);
15081
+ if (prevCleanup) {
15082
+ try {
15083
+ prevCleanup();
15084
+ } catch {
15085
+ }
15086
+ iframeObservers.delete(iframeEl);
15087
+ }
15088
+ const cleanup = observe(iframeEl.contentDocument);
15089
+ handlers.push(cleanup);
15090
+ iframeObservers.set(iframeEl, cleanup);
14848
15091
  } catch (error) {
14849
15092
  console.warn(error);
14850
15093
  }