@posthog/rrweb-record 0.0.36 → 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.
@@ -48,20 +48,20 @@ var NodeType$1$1 = /* @__PURE__ */ ((NodeType2) => {
48
48
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
49
49
  return NodeType2;
50
50
  })(NodeType$1$1 || {});
51
- const testableAccessors$1 = {
51
+ const testableAccessors$2 = {
52
52
  Node: ["childNodes", "parentNode", "parentElement", "textContent"],
53
53
  ShadowRoot: ["host", "styleSheets"],
54
54
  Element: ["shadowRoot", "querySelector", "querySelectorAll"],
55
55
  MutationObserver: []
56
56
  };
57
- const testableMethods$1 = {
57
+ const testableMethods$2 = {
58
58
  Node: ["contains", "getRootNode"],
59
59
  ShadowRoot: ["getSelection"],
60
60
  Element: [],
61
61
  MutationObserver: ["constructor"]
62
62
  };
63
- const untaintedBasePrototype$1 = {};
64
- function angularZoneUnpatchedAlternative$1(key) {
63
+ const untaintedBasePrototype$2 = {};
64
+ function angularZoneUnpatchedAlternative$2(key) {
65
65
  var _a2, _b;
66
66
  const angularUnpatchedVersionSymbol = (_b = (_a2 = globalThis == null ? void 0 : globalThis.Zone) == null ? void 0 : _a2.__symbol__) == null ? void 0 : _b.call(_a2, key);
67
67
  if (angularUnpatchedVersionSymbol && globalThis[angularUnpatchedVersionSymbol]) {
@@ -70,12 +70,12 @@ function angularZoneUnpatchedAlternative$1(key) {
70
70
  return void 0;
71
71
  }
72
72
  }
73
- function getUntaintedPrototype$1(key) {
74
- if (untaintedBasePrototype$1[key])
75
- return untaintedBasePrototype$1[key];
76
- const candidate = angularZoneUnpatchedAlternative$1(key) || globalThis[key];
73
+ function getUntaintedPrototype$2(key) {
74
+ if (untaintedBasePrototype$2[key])
75
+ return untaintedBasePrototype$2[key];
76
+ const candidate = angularZoneUnpatchedAlternative$2(key) || globalThis[key];
77
77
  const defaultPrototype = candidate.prototype;
78
- const accessorNames = key in testableAccessors$1 ? testableAccessors$1[key] : void 0;
78
+ const accessorNames = key in testableAccessors$2 ? testableAccessors$2[key] : void 0;
79
79
  const isUntaintedAccessors = Boolean(
80
80
  accessorNames && // @ts-expect-error 2345
81
81
  accessorNames.every(
@@ -87,7 +87,7 @@ function getUntaintedPrototype$1(key) {
87
87
  }
88
88
  )
89
89
  );
90
- const methodNames = key in testableMethods$1 ? testableMethods$1[key] : void 0;
90
+ const methodNames = key in testableMethods$2 ? testableMethods$2[key] : void 0;
91
91
  const isUntaintedMethods = Boolean(
92
92
  methodNames && methodNames.every(
93
93
  // @ts-expect-error 2345
@@ -98,7 +98,7 @@ function getUntaintedPrototype$1(key) {
98
98
  )
99
99
  );
100
100
  if (isUntaintedAccessors && isUntaintedMethods) {
101
- untaintedBasePrototype$1[key] = candidate.prototype;
101
+ untaintedBasePrototype$2[key] = candidate.prototype;
102
102
  return candidate.prototype;
103
103
  }
104
104
  try {
@@ -109,80 +109,80 @@ function getUntaintedPrototype$1(key) {
109
109
  const untaintedObject = win[key].prototype;
110
110
  document.body.removeChild(iframeEl);
111
111
  if (!untaintedObject) return defaultPrototype;
112
- return untaintedBasePrototype$1[key] = untaintedObject;
112
+ return untaintedBasePrototype$2[key] = untaintedObject;
113
113
  } catch (e) {
114
114
  return defaultPrototype;
115
115
  }
116
116
  }
117
- const untaintedAccessorCache$1 = {};
118
- function getUntaintedAccessor$1(key, instance, accessor) {
117
+ const untaintedAccessorCache$2 = {};
118
+ function getUntaintedAccessor$2(key, instance, accessor) {
119
119
  var _a2;
120
120
  const cacheKey = `${key}.${String(accessor)}`;
121
- if (untaintedAccessorCache$1[cacheKey])
122
- return untaintedAccessorCache$1[cacheKey].call(
121
+ if (untaintedAccessorCache$2[cacheKey])
122
+ return untaintedAccessorCache$2[cacheKey].call(
123
123
  instance
124
124
  );
125
- const untaintedPrototype = getUntaintedPrototype$1(key);
125
+ const untaintedPrototype = getUntaintedPrototype$2(key);
126
126
  const untaintedAccessor = (_a2 = Object.getOwnPropertyDescriptor(
127
127
  untaintedPrototype,
128
128
  accessor
129
129
  )) == null ? void 0 : _a2.get;
130
130
  if (!untaintedAccessor) return instance[accessor];
131
- untaintedAccessorCache$1[cacheKey] = untaintedAccessor;
131
+ untaintedAccessorCache$2[cacheKey] = untaintedAccessor;
132
132
  return untaintedAccessor.call(instance);
133
133
  }
134
- const untaintedMethodCache$1 = {};
135
- function getUntaintedMethod$1(key, instance, method) {
134
+ const untaintedMethodCache$2 = {};
135
+ function getUntaintedMethod$2(key, instance, method) {
136
136
  const cacheKey = `${key}.${String(method)}`;
137
- if (untaintedMethodCache$1[cacheKey])
138
- return untaintedMethodCache$1[cacheKey].bind(
137
+ if (untaintedMethodCache$2[cacheKey])
138
+ return untaintedMethodCache$2[cacheKey].bind(
139
139
  instance
140
140
  );
141
- const untaintedPrototype = getUntaintedPrototype$1(key);
141
+ const untaintedPrototype = getUntaintedPrototype$2(key);
142
142
  const untaintedMethod = untaintedPrototype[method];
143
143
  if (typeof untaintedMethod !== "function") return instance[method];
144
- untaintedMethodCache$1[cacheKey] = untaintedMethod;
144
+ untaintedMethodCache$2[cacheKey] = untaintedMethod;
145
145
  return untaintedMethod.bind(instance);
146
146
  }
147
- function childNodes$1(n2) {
148
- return getUntaintedAccessor$1("Node", n2, "childNodes");
147
+ function childNodes$2(n2) {
148
+ return getUntaintedAccessor$2("Node", n2, "childNodes");
149
149
  }
150
- function parentNode$1(n2) {
151
- return getUntaintedAccessor$1("Node", n2, "parentNode");
150
+ function parentNode$2(n2) {
151
+ return getUntaintedAccessor$2("Node", n2, "parentNode");
152
152
  }
153
- function parentElement$1(n2) {
154
- return getUntaintedAccessor$1("Node", n2, "parentElement");
153
+ function parentElement$2(n2) {
154
+ return getUntaintedAccessor$2("Node", n2, "parentElement");
155
155
  }
156
- function textContent$1(n2) {
157
- return getUntaintedAccessor$1("Node", n2, "textContent");
156
+ function textContent$2(n2) {
157
+ return getUntaintedAccessor$2("Node", n2, "textContent");
158
158
  }
159
- function contains$1(n2, other) {
160
- return getUntaintedMethod$1("Node", n2, "contains")(other);
159
+ function contains$2(n2, other) {
160
+ return getUntaintedMethod$2("Node", n2, "contains")(other);
161
161
  }
162
- function getRootNode$1(n2) {
163
- return getUntaintedMethod$1("Node", n2, "getRootNode")();
162
+ function getRootNode$2(n2) {
163
+ return getUntaintedMethod$2("Node", n2, "getRootNode")();
164
164
  }
165
- function host$1(n2) {
165
+ function host$2(n2) {
166
166
  if (!n2 || !("host" in n2)) return null;
167
- return getUntaintedAccessor$1("ShadowRoot", n2, "host");
167
+ return getUntaintedAccessor$2("ShadowRoot", n2, "host");
168
168
  }
169
- function styleSheets$1(n2) {
169
+ function styleSheets$2(n2) {
170
170
  return n2.styleSheets;
171
171
  }
172
- function shadowRoot$1(n2) {
172
+ function shadowRoot$2(n2) {
173
173
  if (!n2 || !("shadowRoot" in n2)) return null;
174
- return getUntaintedAccessor$1("Element", n2, "shadowRoot");
174
+ return getUntaintedAccessor$2("Element", n2, "shadowRoot");
175
175
  }
176
- function querySelector$1(n2, selectors) {
177
- return getUntaintedAccessor$1("Element", n2, "querySelector")(selectors);
176
+ function querySelector$2(n2, selectors) {
177
+ return getUntaintedAccessor$2("Element", n2, "querySelector")(selectors);
178
178
  }
179
- function querySelectorAll$1(n2, selectors) {
180
- return getUntaintedAccessor$1("Element", n2, "querySelectorAll")(selectors);
179
+ function querySelectorAll$2(n2, selectors) {
180
+ return getUntaintedAccessor$2("Element", n2, "querySelectorAll")(selectors);
181
181
  }
182
- function mutationObserverCtor$1() {
183
- return getUntaintedPrototype$1("MutationObserver").constructor;
182
+ function mutationObserverCtor$2() {
183
+ return getUntaintedPrototype$2("MutationObserver").constructor;
184
184
  }
185
- function patch$1(source, name, replacement) {
185
+ function patch$2(source, name, replacement) {
186
186
  try {
187
187
  if (!(name in source)) {
188
188
  return () => {
@@ -208,32 +208,32 @@ function patch$1(source, name, replacement) {
208
208
  };
209
209
  }
210
210
  }
211
- const index$1 = {
212
- childNodes: childNodes$1,
213
- parentNode: parentNode$1,
214
- parentElement: parentElement$1,
215
- textContent: textContent$1,
216
- contains: contains$1,
217
- getRootNode: getRootNode$1,
218
- host: host$1,
219
- styleSheets: styleSheets$1,
220
- shadowRoot: shadowRoot$1,
221
- querySelector: querySelector$1,
222
- querySelectorAll: querySelectorAll$1,
223
- mutationObserver: mutationObserverCtor$1,
224
- patch: patch$1
211
+ const index$2 = {
212
+ childNodes: childNodes$2,
213
+ parentNode: parentNode$2,
214
+ parentElement: parentElement$2,
215
+ textContent: textContent$2,
216
+ contains: contains$2,
217
+ getRootNode: getRootNode$2,
218
+ host: host$2,
219
+ styleSheets: styleSheets$2,
220
+ shadowRoot: shadowRoot$2,
221
+ querySelector: querySelector$2,
222
+ querySelectorAll: querySelectorAll$2,
223
+ mutationObserver: mutationObserverCtor$2,
224
+ patch: patch$2
225
225
  };
226
- function isElement(n2) {
226
+ function isElement$1(n2) {
227
227
  return n2.nodeType === n2.ELEMENT_NODE;
228
228
  }
229
229
  function isShadowRoot(n2) {
230
230
  const hostEl = (
231
231
  // anchor and textarea elements also have a `host` property
232
232
  // but only shadow roots have a `mode` property
233
- n2 && "host" in n2 && "mode" in n2 && index$1.host(n2) || null
233
+ n2 && "host" in n2 && "mode" in n2 && index$2.host(n2) || null
234
234
  );
235
235
  return Boolean(
236
- hostEl && "shadowRoot" in hostEl && index$1.shadowRoot(hostEl) === n2
236
+ hostEl && "shadowRoot" in hostEl && index$2.shadowRoot(hostEl) === n2
237
237
  );
238
238
  }
239
239
  function isNativeShadowDom(shadowRoot2) {
@@ -354,6 +354,17 @@ class Mirror {
354
354
  (childNode) => this.removeNodeFromMap(childNode)
355
355
  );
356
356
  }
357
+ if (isElement$1(n2)) {
358
+ const shadowRootEl = index$2.shadowRoot(n2);
359
+ if (shadowRootEl) {
360
+ this.removeNodeFromMap(shadowRootEl);
361
+ }
362
+ if (n2.nodeName === "IFRAME" && n2.contentDocument) {
363
+ this.removeNodeFromMap(
364
+ n2.contentDocument
365
+ );
366
+ }
367
+ }
357
368
  }
358
369
  has(id) {
359
370
  return this.idNodeMap.has(id);
@@ -690,7 +701,7 @@ function classMatchesRegex(node2, regex, checkAncestors) {
690
701
  if (!node2) return false;
691
702
  if (node2.nodeType !== node2.ELEMENT_NODE) {
692
703
  if (!checkAncestors) return false;
693
- return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors);
704
+ return classMatchesRegex(index$2.parentNode(node2), regex, checkAncestors);
694
705
  }
695
706
  for (let eIndex = node2.classList.length; eIndex--; ) {
696
707
  const className = node2.classList[eIndex];
@@ -699,19 +710,19 @@ function classMatchesRegex(node2, regex, checkAncestors) {
699
710
  }
700
711
  }
701
712
  if (!checkAncestors) return false;
702
- return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors);
713
+ return classMatchesRegex(index$2.parentNode(node2), regex, checkAncestors);
703
714
  }
704
715
  function needMaskingText(node2, maskTextClass, maskTextSelector, checkAncestors) {
705
716
  let el;
706
- if (isElement(node2)) {
717
+ if (isElement$1(node2)) {
707
718
  el = node2;
708
- if (!index$1.childNodes(el).length) {
719
+ if (!index$2.childNodes(el).length) {
709
720
  return false;
710
721
  }
711
- } else if (index$1.parentElement(node2) === null) {
722
+ } else if (index$2.parentElement(node2) === null) {
712
723
  return false;
713
724
  } else {
714
- el = index$1.parentElement(node2);
725
+ el = index$2.parentElement(node2);
715
726
  }
716
727
  try {
717
728
  if (typeof maskTextClass === "string") {
@@ -860,7 +871,7 @@ function serializeNode(n2, options) {
860
871
  case n2.COMMENT_NODE:
861
872
  return {
862
873
  type: NodeType$1$1.Comment,
863
- textContent: index$1.textContent(n2) || "",
874
+ textContent: index$2.textContent(n2) || "",
864
875
  rootId
865
876
  };
866
877
  default:
@@ -875,9 +886,9 @@ function getRootId(doc, mirror2) {
875
886
  function serializeTextNode(n2, options) {
876
887
  var _a2;
877
888
  const { needsMask, maskTextFn, rootId } = options;
878
- const parent = index$1.parentNode(n2);
889
+ const parent = index$2.parentNode(n2);
879
890
  const parentTagName = parent && parent.tagName;
880
- let text = index$1.textContent(n2);
891
+ let text = index$2.textContent(n2);
881
892
  const isStyle = parentTagName === "STYLE" ? true : void 0;
882
893
  const isScript = parentTagName === "SCRIPT" ? true : void 0;
883
894
  if (isStyle && text) {
@@ -898,7 +909,7 @@ function serializeTextNode(n2, options) {
898
909
  text = "SCRIPT_PLACEHOLDER";
899
910
  }
900
911
  if (!isStyle && !isScript && text && needsMask) {
901
- text = maskTextFn ? maskTextFn(text, index$1.parentElement(n2)) : text.replace(/[\S]/g, "*");
912
+ text = maskTextFn ? maskTextFn(text, index$2.parentElement(n2)) : text.replace(/[\S]/g, "*");
902
913
  }
903
914
  return {
904
915
  type: NodeType$1$1.Text,
@@ -968,7 +979,7 @@ function serializeElementNode(n2, options) {
968
979
  }
969
980
  }
970
981
  if (tagName === "style" && n2.sheet && // TODO: Currently we only try to get dynamic stylesheet when it is an empty style element
971
- !(n2.innerText || index$1.textContent(n2) || "").trim().length) {
982
+ !(n2.innerText || index$2.textContent(n2) || "").trim().length) {
972
983
  const cssText = stringifyStylesheet(
973
984
  n2.sheet
974
985
  );
@@ -1234,7 +1245,7 @@ function serializeNodeWithId(n2, options) {
1234
1245
  if (serializedNode.type === NodeType$1$1.Element) {
1235
1246
  recordChild = recordChild && !serializedNode.needBlock;
1236
1247
  delete serializedNode.needBlock;
1237
- const shadowRootEl = index$1.shadowRoot(n2);
1248
+ const shadowRootEl = index$2.shadowRoot(n2);
1238
1249
  if (shadowRootEl && isNativeShadowDom(shadowRootEl))
1239
1250
  serializedNode.isShadowHost = true;
1240
1251
  }
@@ -1269,7 +1280,7 @@ function serializeNodeWithId(n2, options) {
1269
1280
  };
1270
1281
  if (serializedNode.type === NodeType$1$1.Element && serializedNode.tagName === "textarea" && serializedNode.attributes.value !== void 0) ;
1271
1282
  else {
1272
- for (const childN of Array.from(index$1.childNodes(n2))) {
1283
+ for (const childN of Array.from(index$2.childNodes(n2))) {
1273
1284
  const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1274
1285
  if (serializedChildNode) {
1275
1286
  serializedNode.childNodes.push(serializedChildNode);
@@ -1277,8 +1288,8 @@ function serializeNodeWithId(n2, options) {
1277
1288
  }
1278
1289
  }
1279
1290
  let shadowRootEl = null;
1280
- if (isElement(n2) && (shadowRootEl = index$1.shadowRoot(n2))) {
1281
- for (const childN of Array.from(index$1.childNodes(shadowRootEl))) {
1291
+ if (isElement$1(n2) && (shadowRootEl = index$2.shadowRoot(n2))) {
1292
+ for (const childN of Array.from(index$2.childNodes(shadowRootEl))) {
1282
1293
  const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
1283
1294
  if (serializedChildNode) {
1284
1295
  isNativeShadowDom(shadowRootEl) && (serializedChildNode.isShadow = true);
@@ -1287,7 +1298,7 @@ function serializeNodeWithId(n2, options) {
1287
1298
  }
1288
1299
  }
1289
1300
  }
1290
- const parent = index$1.parentNode(n2);
1301
+ const parent = index$2.parentNode(n2);
1291
1302
  if (parent && isShadowRoot(parent) && isNativeShadowDom(parent)) {
1292
1303
  serializedNode.isShadow = true;
1293
1304
  }
@@ -11835,14 +11846,22 @@ class IframeManager {
11835
11846
  }
11836
11847
  removeIframeById(iframeId) {
11837
11848
  const entry = this.attachedIframes.get(iframeId);
11838
- if (!entry) return;
11839
- const win = entry.element.contentWindow;
11840
- if (win && this.nestedIframeListeners.has(win)) {
11841
- const handler = this.nestedIframeListeners.get(win);
11842
- win.removeEventListener("message", handler);
11843
- this.nestedIframeListeners.delete(win);
11849
+ const iframe = (entry == null ? void 0 : entry.element) || this.mirror.getNode(iframeId);
11850
+ if (iframe) {
11851
+ const win = iframe.contentWindow;
11852
+ if (win && this.nestedIframeListeners.has(win)) {
11853
+ const handler = this.nestedIframeListeners.get(win);
11854
+ win.removeEventListener("message", handler);
11855
+ this.nestedIframeListeners.delete(win);
11856
+ }
11857
+ if (win) {
11858
+ this.crossOriginIframeMap.delete(win);
11859
+ }
11860
+ this.iframes.delete(iframe);
11861
+ }
11862
+ if (entry) {
11863
+ this.attachedIframes.delete(iframeId);
11844
11864
  }
11845
- this.attachedIframes.delete(iframeId);
11846
11865
  }
11847
11866
  reattachIframes() {
11848
11867
  this.attachedIframes.forEach(({ content }, iframeId) => {
@@ -12808,9 +12827,12 @@ function record(options = {}) {
12808
12827
  }
12809
12828
  };
12810
12829
  const wrappedMutationEmit = (m) => {
12811
- if (recordCrossOriginIframes && m.removes) {
12830
+ if (recordCrossOriginIframes && m.removes && m.removes.length > 0) {
12831
+ const addedIds = m.adds.length > 0 ? new Set(m.adds.map((add) => add.node.id)) : null;
12812
12832
  m.removes.forEach(({ id }) => {
12813
- iframeManager.removeIframeById(id);
12833
+ if (!addedIds || !addedIds.has(id)) {
12834
+ iframeManager.removeIframeById(id);
12835
+ }
12814
12836
  });
12815
12837
  }
12816
12838
  wrappedEmit({