@posthog/rrweb 0.0.46 → 0.0.48

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.
@@ -1541,7 +1541,10 @@ const pseudoClassPlugin = {
1541
1541
  fixed.push(rule2);
1542
1542
  rule2.selectors.forEach(function(selector) {
1543
1543
  if (selector.includes(":hover")) {
1544
- rule2.selector += ",\n" + selector.replace(/:hover/g, ".\\:hover");
1544
+ const newSelector = selector.replace(new RegExp("(?<!\\\\):hover", "g"), ".\\:hover");
1545
+ if (newSelector !== selector) {
1546
+ rule2.selector += ",\n" + newSelector;
1547
+ }
1545
1548
  }
1546
1549
  });
1547
1550
  }
@@ -12627,7 +12630,7 @@ function initMutationObserver(options, rootEl) {
12627
12630
  childList: true,
12628
12631
  subtree: true
12629
12632
  });
12630
- return observer;
12633
+ return { observer, buffer: mutationBuffer };
12631
12634
  }
12632
12635
  function initMoveObserver({
12633
12636
  mousemoveCb,
@@ -13546,8 +13549,11 @@ function initObservers(o2, hooks = {}) {
13546
13549
  }
13547
13550
  mergeHooks(o2, hooks);
13548
13551
  let mutationObserver;
13552
+ let mutationBuffer;
13549
13553
  if (o2.recordDOM) {
13550
- mutationObserver = initMutationObserver(o2, o2.doc);
13554
+ const result2 = initMutationObserver(o2, o2.doc);
13555
+ mutationObserver = result2.observer;
13556
+ mutationBuffer = result2.buffer;
13551
13557
  }
13552
13558
  const mousemoveHandler = initMoveObserver(o2);
13553
13559
  const mouseInteractionHandler = initMouseInteractionObserver(o2);
@@ -13584,8 +13590,14 @@ function initObservers(o2, hooks = {}) {
13584
13590
  );
13585
13591
  }
13586
13592
  return callbackWrapper(() => {
13587
- mutationBuffers.forEach((b) => b.destroy());
13588
- mutationBuffers.forEach((b) => b.reset());
13593
+ if (mutationBuffer) {
13594
+ mutationBuffer.destroy();
13595
+ mutationBuffer.reset();
13596
+ const index2 = mutationBuffers.indexOf(mutationBuffer);
13597
+ if (index2 !== -1) {
13598
+ mutationBuffers.splice(index2, 1);
13599
+ }
13600
+ }
13589
13601
  mutationObserver == null ? void 0 : mutationObserver.disconnect();
13590
13602
  mousemoveHandler();
13591
13603
  mouseInteractionHandler();
@@ -13600,7 +13612,6 @@ function initObservers(o2, hooks = {}) {
13600
13612
  selectionObserver();
13601
13613
  customElementObserver();
13602
13614
  pluginHandlers.forEach((h) => h());
13603
- mutationBuffers.length = 0;
13604
13615
  });
13605
13616
  }
13606
13617
  function hasNestedCSSRule(prop) {
@@ -14000,7 +14011,7 @@ class ShadowDomManager {
14000
14011
  if (!isNativeShadowDom(shadowRoot2)) return;
14001
14012
  if (this.shadowDoms.has(shadowRoot2)) return;
14002
14013
  this.shadowDoms.add(shadowRoot2);
14003
- const observer = initMutationObserver(
14014
+ const { observer, buffer } = initMutationObserver(
14004
14015
  __spreadProps(__spreadValues({}, this.bypassOptions), {
14005
14016
  doc,
14006
14017
  mutationCb: this.mutationCb,
@@ -14009,7 +14020,15 @@ class ShadowDomManager {
14009
14020
  }),
14010
14021
  shadowRoot2
14011
14022
  );
14012
- this.restoreHandlers.push(() => observer.disconnect());
14023
+ this.restoreHandlers.push(() => {
14024
+ observer.disconnect();
14025
+ buffer.destroy();
14026
+ buffer.reset();
14027
+ const index2 = mutationBuffers.indexOf(buffer);
14028
+ if (index2 !== -1) {
14029
+ mutationBuffers.splice(index2, 1);
14030
+ }
14031
+ });
14013
14032
  this.restoreHandlers.push(
14014
14033
  initScrollObserver(__spreadProps(__spreadValues({}, this.bypassOptions), {
14015
14034
  scrollCb: this.scrollCb,
@@ -14884,6 +14903,26 @@ function record(options = {}) {
14884
14903
  polyfill$1();
14885
14904
  let lastFullSnapshotEvent;
14886
14905
  let incrementalSnapshotCount = 0;
14906
+ const iframeObserverCleanups = /* @__PURE__ */ new Map();
14907
+ function cleanupDetachedIframeObservers() {
14908
+ for (const [iframeId, cleanup] of iframeObserverCleanups) {
14909
+ const iframe = mirror.getNode(iframeId);
14910
+ if (!iframe) {
14911
+ cleanup();
14912
+ iframeObserverCleanups.delete(iframeId);
14913
+ continue;
14914
+ }
14915
+ try {
14916
+ if (!iframe.contentDocument || !iframe.contentDocument.defaultView) {
14917
+ cleanup();
14918
+ iframeObserverCleanups.delete(iframeId);
14919
+ }
14920
+ } catch (e2) {
14921
+ cleanup();
14922
+ iframeObserverCleanups.delete(iframeId);
14923
+ }
14924
+ }
14925
+ }
14887
14926
  const eventProcessor = (e2) => {
14888
14927
  for (const plugin of plugins || []) {
14889
14928
  if (plugin.eventProcessor) {
@@ -14934,9 +14973,15 @@ function record(options = {}) {
14934
14973
  const addedIds = m.adds.length > 0 ? new Set(m.adds.map((add) => add.node.id)) : null;
14935
14974
  m.removes.forEach(({ id }) => {
14936
14975
  if (!addedIds || !addedIds.has(id)) {
14976
+ const cleanup = iframeObserverCleanups.get(id);
14977
+ if (cleanup) {
14978
+ cleanup();
14979
+ iframeObserverCleanups.delete(id);
14980
+ }
14937
14981
  iframeManager.removeIframeById(id);
14938
14982
  }
14939
14983
  });
14984
+ cleanupDetachedIframeObservers();
14940
14985
  }
14941
14986
  wrappedEmit({
14942
14987
  type: EventType.IncrementalSnapshot,
@@ -15211,7 +15256,12 @@ function record(options = {}) {
15211
15256
  };
15212
15257
  const loadListener = (iframeEl) => {
15213
15258
  try {
15214
- handlers.push(observe(iframeEl.contentDocument));
15259
+ const iframeId = mirror.getId(iframeEl);
15260
+ const cleanup = observe(iframeEl.contentDocument);
15261
+ handlers.push(cleanup);
15262
+ if (iframeId !== -1) {
15263
+ iframeObserverCleanups.set(iframeId, cleanup);
15264
+ }
15215
15265
  } catch (error) {
15216
15266
  console.warn(error);
15217
15267
  }
@@ -15253,6 +15303,7 @@ function record(options = {}) {
15253
15303
  processedNodeManager.destroy();
15254
15304
  iframeManager.removeLoadListener();
15255
15305
  iframeManager.destroy();
15306
+ iframeObserverCleanups.clear();
15256
15307
  mirror.reset();
15257
15308
  recording = false;
15258
15309
  unregisterErrorHandler();