@posthog/rrweb-player 0.0.37 → 0.0.38

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.
@@ -412,7 +412,182 @@ var NodeType$1$1 = /* @__PURE__ */ ((NodeType2) => {
412
412
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
413
413
  return NodeType2;
414
414
  })(NodeType$1$1 || {});
415
- function isElement(n2) {
415
+ const testableAccessors$2 = {
416
+ Node: ["childNodes", "parentNode", "parentElement", "textContent"],
417
+ ShadowRoot: ["host", "styleSheets"],
418
+ Element: ["shadowRoot", "querySelector", "querySelectorAll"],
419
+ MutationObserver: []
420
+ };
421
+ const testableMethods$2 = {
422
+ Node: ["contains", "getRootNode"],
423
+ ShadowRoot: ["getSelection"],
424
+ Element: [],
425
+ MutationObserver: ["constructor"]
426
+ };
427
+ const untaintedBasePrototype$2 = {};
428
+ function angularZoneUnpatchedAlternative$2(key) {
429
+ var _a2, _b2;
430
+ const angularUnpatchedVersionSymbol = (_b2 = (_a2 = globalThis == null ? void 0 : globalThis.Zone) == null ? void 0 : _a2.__symbol__) == null ? void 0 : _b2.call(_a2, key);
431
+ if (angularUnpatchedVersionSymbol && globalThis[angularUnpatchedVersionSymbol]) {
432
+ return globalThis[angularUnpatchedVersionSymbol];
433
+ } else {
434
+ return void 0;
435
+ }
436
+ }
437
+ function getUntaintedPrototype$2(key) {
438
+ if (untaintedBasePrototype$2[key])
439
+ return untaintedBasePrototype$2[key];
440
+ const candidate = angularZoneUnpatchedAlternative$2(key) || globalThis[key];
441
+ const defaultPrototype = candidate.prototype;
442
+ const accessorNames = key in testableAccessors$2 ? testableAccessors$2[key] : void 0;
443
+ const isUntaintedAccessors = Boolean(
444
+ accessorNames && // @ts-expect-error 2345
445
+ accessorNames.every(
446
+ (accessor) => {
447
+ var _a2, _b2;
448
+ return Boolean(
449
+ (_b2 = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b2.toString().includes("[native code]")
450
+ );
451
+ }
452
+ )
453
+ );
454
+ const methodNames = key in testableMethods$2 ? testableMethods$2[key] : void 0;
455
+ const isUntaintedMethods = Boolean(
456
+ methodNames && methodNames.every(
457
+ // @ts-expect-error 2345
458
+ (method) => {
459
+ var _a2;
460
+ return typeof defaultPrototype[method] === "function" && ((_a2 = defaultPrototype[method]) == null ? void 0 : _a2.toString().includes("[native code]"));
461
+ }
462
+ )
463
+ );
464
+ if (isUntaintedAccessors && isUntaintedMethods) {
465
+ untaintedBasePrototype$2[key] = candidate.prototype;
466
+ return candidate.prototype;
467
+ }
468
+ try {
469
+ const iframeEl = document.createElement("iframe");
470
+ document.body.appendChild(iframeEl);
471
+ const win = iframeEl.contentWindow;
472
+ if (!win) return candidate.prototype;
473
+ const untaintedObject = win[key].prototype;
474
+ document.body.removeChild(iframeEl);
475
+ if (!untaintedObject) return defaultPrototype;
476
+ return untaintedBasePrototype$2[key] = untaintedObject;
477
+ } catch {
478
+ return defaultPrototype;
479
+ }
480
+ }
481
+ const untaintedAccessorCache$2 = {};
482
+ function getUntaintedAccessor$2(key, instance2, accessor) {
483
+ var _a2;
484
+ const cacheKey = `${key}.${String(accessor)}`;
485
+ if (untaintedAccessorCache$2[cacheKey])
486
+ return untaintedAccessorCache$2[cacheKey].call(
487
+ instance2
488
+ );
489
+ const untaintedPrototype = getUntaintedPrototype$2(key);
490
+ const untaintedAccessor = (_a2 = Object.getOwnPropertyDescriptor(
491
+ untaintedPrototype,
492
+ accessor
493
+ )) == null ? void 0 : _a2.get;
494
+ if (!untaintedAccessor) return instance2[accessor];
495
+ untaintedAccessorCache$2[cacheKey] = untaintedAccessor;
496
+ return untaintedAccessor.call(instance2);
497
+ }
498
+ const untaintedMethodCache$2 = {};
499
+ function getUntaintedMethod$2(key, instance2, method) {
500
+ const cacheKey = `${key}.${String(method)}`;
501
+ if (untaintedMethodCache$2[cacheKey])
502
+ return untaintedMethodCache$2[cacheKey].bind(
503
+ instance2
504
+ );
505
+ const untaintedPrototype = getUntaintedPrototype$2(key);
506
+ const untaintedMethod = untaintedPrototype[method];
507
+ if (typeof untaintedMethod !== "function") return instance2[method];
508
+ untaintedMethodCache$2[cacheKey] = untaintedMethod;
509
+ return untaintedMethod.bind(instance2);
510
+ }
511
+ function childNodes$2(n2) {
512
+ return getUntaintedAccessor$2("Node", n2, "childNodes");
513
+ }
514
+ function parentNode$2(n2) {
515
+ return getUntaintedAccessor$2("Node", n2, "parentNode");
516
+ }
517
+ function parentElement$2(n2) {
518
+ return getUntaintedAccessor$2("Node", n2, "parentElement");
519
+ }
520
+ function textContent$2(n2) {
521
+ return getUntaintedAccessor$2("Node", n2, "textContent");
522
+ }
523
+ function contains$2(n2, other) {
524
+ return getUntaintedMethod$2("Node", n2, "contains")(other);
525
+ }
526
+ function getRootNode$2(n2) {
527
+ return getUntaintedMethod$2("Node", n2, "getRootNode")();
528
+ }
529
+ function host$2(n2) {
530
+ if (!n2 || !("host" in n2)) return null;
531
+ return getUntaintedAccessor$2("ShadowRoot", n2, "host");
532
+ }
533
+ function styleSheets$2(n2) {
534
+ return n2.styleSheets;
535
+ }
536
+ function shadowRoot$2(n2) {
537
+ if (!n2 || !("shadowRoot" in n2)) return null;
538
+ return getUntaintedAccessor$2("Element", n2, "shadowRoot");
539
+ }
540
+ function querySelector$2(n2, selectors) {
541
+ return getUntaintedAccessor$2("Element", n2, "querySelector")(selectors);
542
+ }
543
+ function querySelectorAll$2(n2, selectors) {
544
+ return getUntaintedAccessor$2("Element", n2, "querySelectorAll")(selectors);
545
+ }
546
+ function mutationObserverCtor$2() {
547
+ return getUntaintedPrototype$2("MutationObserver").constructor;
548
+ }
549
+ function patch$2(source, name, replacement) {
550
+ try {
551
+ if (!(name in source)) {
552
+ return () => {
553
+ };
554
+ }
555
+ const original = source[name];
556
+ const wrapped = replacement(original);
557
+ if (typeof wrapped === "function") {
558
+ wrapped.prototype = wrapped.prototype || {};
559
+ Object.defineProperties(wrapped, {
560
+ __rrweb_original__: {
561
+ enumerable: false,
562
+ value: original
563
+ }
564
+ });
565
+ }
566
+ source[name] = wrapped;
567
+ return () => {
568
+ source[name] = original;
569
+ };
570
+ } catch {
571
+ return () => {
572
+ };
573
+ }
574
+ }
575
+ const index$2 = {
576
+ childNodes: childNodes$2,
577
+ parentNode: parentNode$2,
578
+ parentElement: parentElement$2,
579
+ textContent: textContent$2,
580
+ contains: contains$2,
581
+ getRootNode: getRootNode$2,
582
+ host: host$2,
583
+ styleSheets: styleSheets$2,
584
+ shadowRoot: shadowRoot$2,
585
+ querySelector: querySelector$2,
586
+ querySelectorAll: querySelectorAll$2,
587
+ mutationObserver: mutationObserverCtor$2,
588
+ patch: patch$2
589
+ };
590
+ function isElement$1(n2) {
416
591
  return n2.nodeType === n2.ELEMENT_NODE;
417
592
  }
418
593
  class Mirror {
@@ -445,6 +620,17 @@ class Mirror {
445
620
  (childNode) => this.removeNodeFromMap(childNode)
446
621
  );
447
622
  }
623
+ if (isElement$1(n2)) {
624
+ const shadowRootEl = index$2.shadowRoot(n2);
625
+ if (shadowRootEl) {
626
+ this.removeNodeFromMap(shadowRootEl);
627
+ }
628
+ if (n2.nodeName === "IFRAME" && n2.contentDocument) {
629
+ this.removeNodeFromMap(
630
+ n2.contentDocument
631
+ );
632
+ }
633
+ }
448
634
  }
449
635
  has(id) {
450
636
  return this.idNodeMap.has(id);
@@ -4777,7 +4963,7 @@ function buildNodeWithSN(n2, options) {
4777
4963
  console.warn("Failed to rebuild", childN);
4778
4964
  continue;
4779
4965
  }
4780
- if (childN.isShadow && isElement(node2) && node2.shadowRoot) {
4966
+ if (childN.isShadow && isElement$1(node2) && node2.shadowRoot) {
4781
4967
  node2.shadowRoot.appendChild(childNode);
4782
4968
  } else if (n2.type === NodeType$1$1.Document && childN.type == NodeType$1$1.Element) {
4783
4969
  const htmlElement = childNode;
@@ -4868,6 +5054,184 @@ var __publicField22 = (obj, key, value) => __defNormalProp22(obj, typeof key !==
4868
5054
  var __defProp222 = Object.defineProperty;
4869
5055
  var __defNormalProp222 = (obj, key, value) => key in obj ? __defProp222(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4870
5056
  var __publicField222 = (obj, key, value) => __defNormalProp222(obj, typeof key !== "symbol" ? key + "" : key, value);
5057
+ const testableAccessors$1 = {
5058
+ Node: ["childNodes", "parentNode", "parentElement", "textContent"],
5059
+ ShadowRoot: ["host", "styleSheets"],
5060
+ Element: ["shadowRoot", "querySelector", "querySelectorAll"],
5061
+ MutationObserver: []
5062
+ };
5063
+ const testableMethods$1 = {
5064
+ Node: ["contains", "getRootNode"],
5065
+ ShadowRoot: ["getSelection"],
5066
+ Element: [],
5067
+ MutationObserver: ["constructor"]
5068
+ };
5069
+ const untaintedBasePrototype$1 = {};
5070
+ function angularZoneUnpatchedAlternative$1(key) {
5071
+ var _a2, _b2;
5072
+ const angularUnpatchedVersionSymbol = (_b2 = (_a2 = globalThis == null ? void 0 : globalThis.Zone) == null ? void 0 : _a2.__symbol__) == null ? void 0 : _b2.call(_a2, key);
5073
+ if (angularUnpatchedVersionSymbol && globalThis[angularUnpatchedVersionSymbol]) {
5074
+ return globalThis[angularUnpatchedVersionSymbol];
5075
+ } else {
5076
+ return void 0;
5077
+ }
5078
+ }
5079
+ function getUntaintedPrototype$1(key) {
5080
+ if (untaintedBasePrototype$1[key])
5081
+ return untaintedBasePrototype$1[key];
5082
+ const candidate = angularZoneUnpatchedAlternative$1(key) || globalThis[key];
5083
+ const defaultPrototype = candidate.prototype;
5084
+ const accessorNames = key in testableAccessors$1 ? testableAccessors$1[key] : void 0;
5085
+ const isUntaintedAccessors = Boolean(
5086
+ accessorNames && // @ts-expect-error 2345
5087
+ accessorNames.every(
5088
+ (accessor) => {
5089
+ var _a2, _b2;
5090
+ return Boolean(
5091
+ (_b2 = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b2.toString().includes("[native code]")
5092
+ );
5093
+ }
5094
+ )
5095
+ );
5096
+ const methodNames = key in testableMethods$1 ? testableMethods$1[key] : void 0;
5097
+ const isUntaintedMethods = Boolean(
5098
+ methodNames && methodNames.every(
5099
+ // @ts-expect-error 2345
5100
+ (method) => {
5101
+ var _a2;
5102
+ return typeof defaultPrototype[method] === "function" && ((_a2 = defaultPrototype[method]) == null ? void 0 : _a2.toString().includes("[native code]"));
5103
+ }
5104
+ )
5105
+ );
5106
+ if (isUntaintedAccessors && isUntaintedMethods) {
5107
+ untaintedBasePrototype$1[key] = candidate.prototype;
5108
+ return candidate.prototype;
5109
+ }
5110
+ try {
5111
+ const iframeEl = document.createElement("iframe");
5112
+ document.body.appendChild(iframeEl);
5113
+ const win = iframeEl.contentWindow;
5114
+ if (!win) return candidate.prototype;
5115
+ const untaintedObject = win[key].prototype;
5116
+ document.body.removeChild(iframeEl);
5117
+ if (!untaintedObject) return defaultPrototype;
5118
+ return untaintedBasePrototype$1[key] = untaintedObject;
5119
+ } catch {
5120
+ return defaultPrototype;
5121
+ }
5122
+ }
5123
+ const untaintedAccessorCache$1 = {};
5124
+ function getUntaintedAccessor$1(key, instance2, accessor) {
5125
+ var _a2;
5126
+ const cacheKey = `${key}.${String(accessor)}`;
5127
+ if (untaintedAccessorCache$1[cacheKey])
5128
+ return untaintedAccessorCache$1[cacheKey].call(
5129
+ instance2
5130
+ );
5131
+ const untaintedPrototype = getUntaintedPrototype$1(key);
5132
+ const untaintedAccessor = (_a2 = Object.getOwnPropertyDescriptor(
5133
+ untaintedPrototype,
5134
+ accessor
5135
+ )) == null ? void 0 : _a2.get;
5136
+ if (!untaintedAccessor) return instance2[accessor];
5137
+ untaintedAccessorCache$1[cacheKey] = untaintedAccessor;
5138
+ return untaintedAccessor.call(instance2);
5139
+ }
5140
+ const untaintedMethodCache$1 = {};
5141
+ function getUntaintedMethod$1(key, instance2, method) {
5142
+ const cacheKey = `${key}.${String(method)}`;
5143
+ if (untaintedMethodCache$1[cacheKey])
5144
+ return untaintedMethodCache$1[cacheKey].bind(
5145
+ instance2
5146
+ );
5147
+ const untaintedPrototype = getUntaintedPrototype$1(key);
5148
+ const untaintedMethod = untaintedPrototype[method];
5149
+ if (typeof untaintedMethod !== "function") return instance2[method];
5150
+ untaintedMethodCache$1[cacheKey] = untaintedMethod;
5151
+ return untaintedMethod.bind(instance2);
5152
+ }
5153
+ function childNodes$1(n2) {
5154
+ return getUntaintedAccessor$1("Node", n2, "childNodes");
5155
+ }
5156
+ function parentNode$1(n2) {
5157
+ return getUntaintedAccessor$1("Node", n2, "parentNode");
5158
+ }
5159
+ function parentElement$1(n2) {
5160
+ return getUntaintedAccessor$1("Node", n2, "parentElement");
5161
+ }
5162
+ function textContent$1(n2) {
5163
+ return getUntaintedAccessor$1("Node", n2, "textContent");
5164
+ }
5165
+ function contains$1(n2, other) {
5166
+ return getUntaintedMethod$1("Node", n2, "contains")(other);
5167
+ }
5168
+ function getRootNode$1(n2) {
5169
+ return getUntaintedMethod$1("Node", n2, "getRootNode")();
5170
+ }
5171
+ function host$1(n2) {
5172
+ if (!n2 || !("host" in n2)) return null;
5173
+ return getUntaintedAccessor$1("ShadowRoot", n2, "host");
5174
+ }
5175
+ function styleSheets$1(n2) {
5176
+ return n2.styleSheets;
5177
+ }
5178
+ function shadowRoot$1(n2) {
5179
+ if (!n2 || !("shadowRoot" in n2)) return null;
5180
+ return getUntaintedAccessor$1("Element", n2, "shadowRoot");
5181
+ }
5182
+ function querySelector$1(n2, selectors) {
5183
+ return getUntaintedAccessor$1("Element", n2, "querySelector")(selectors);
5184
+ }
5185
+ function querySelectorAll$1(n2, selectors) {
5186
+ return getUntaintedAccessor$1("Element", n2, "querySelectorAll")(selectors);
5187
+ }
5188
+ function mutationObserverCtor$1() {
5189
+ return getUntaintedPrototype$1("MutationObserver").constructor;
5190
+ }
5191
+ function patch$1(source, name, replacement) {
5192
+ try {
5193
+ if (!(name in source)) {
5194
+ return () => {
5195
+ };
5196
+ }
5197
+ const original = source[name];
5198
+ const wrapped = replacement(original);
5199
+ if (typeof wrapped === "function") {
5200
+ wrapped.prototype = wrapped.prototype || {};
5201
+ Object.defineProperties(wrapped, {
5202
+ __rrweb_original__: {
5203
+ enumerable: false,
5204
+ value: original
5205
+ }
5206
+ });
5207
+ }
5208
+ source[name] = wrapped;
5209
+ return () => {
5210
+ source[name] = original;
5211
+ };
5212
+ } catch {
5213
+ return () => {
5214
+ };
5215
+ }
5216
+ }
5217
+ const index$1 = {
5218
+ childNodes: childNodes$1,
5219
+ parentNode: parentNode$1,
5220
+ parentElement: parentElement$1,
5221
+ textContent: textContent$1,
5222
+ contains: contains$1,
5223
+ getRootNode: getRootNode$1,
5224
+ host: host$1,
5225
+ styleSheets: styleSheets$1,
5226
+ shadowRoot: shadowRoot$1,
5227
+ querySelector: querySelector$1,
5228
+ querySelectorAll: querySelectorAll$1,
5229
+ mutationObserver: mutationObserverCtor$1,
5230
+ patch: patch$1
5231
+ };
5232
+ function isElement(n2) {
5233
+ return n2.nodeType === n2.ELEMENT_NODE;
5234
+ }
4871
5235
  let Mirror$1 = class Mirror2 {
4872
5236
  constructor() {
4873
5237
  __publicField222(this, "idNodeMap", /* @__PURE__ */ new Map());
@@ -4898,6 +5262,17 @@ let Mirror$1 = class Mirror2 {
4898
5262
  (childNode) => this.removeNodeFromMap(childNode)
4899
5263
  );
4900
5264
  }
5265
+ if (isElement(n2)) {
5266
+ const shadowRootEl = index$1.shadowRoot(n2);
5267
+ if (shadowRootEl) {
5268
+ this.removeNodeFromMap(shadowRootEl);
5269
+ }
5270
+ if (n2.nodeName === "IFRAME" && n2.contentDocument) {
5271
+ this.removeNodeFromMap(
5272
+ n2.contentDocument
5273
+ );
5274
+ }
5275
+ }
4901
5276
  }
4902
5277
  has(id) {
4903
5278
  return this.idNodeMap.has(id);