@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.
package/dist/rrweb.cjs CHANGED
@@ -1508,7 +1508,10 @@ const pseudoClassPlugin = {
1508
1508
  fixed.push(rule2);
1509
1509
  rule2.selectors.forEach(function(selector) {
1510
1510
  if (selector.includes(":hover")) {
1511
- rule2.selector += ",\n" + selector.replace(/:hover/g, ".\\:hover");
1511
+ const newSelector = selector.replace(new RegExp("(?<!\\\\):hover", "g"), ".\\:hover");
1512
+ if (newSelector !== selector) {
1513
+ rule2.selector += ",\n" + newSelector;
1514
+ }
1512
1515
  }
1513
1516
  });
1514
1517
  }
@@ -12617,7 +12620,7 @@ function initMutationObserver(options, rootEl) {
12617
12620
  childList: true,
12618
12621
  subtree: true
12619
12622
  });
12620
- return observer;
12623
+ return { observer, buffer: mutationBuffer };
12621
12624
  }
12622
12625
  function initMoveObserver({
12623
12626
  mousemoveCb,
@@ -13538,8 +13541,11 @@ function initObservers(o2, hooks = {}) {
13538
13541
  }
13539
13542
  mergeHooks(o2, hooks);
13540
13543
  let mutationObserver;
13544
+ let mutationBuffer;
13541
13545
  if (o2.recordDOM) {
13542
- mutationObserver = initMutationObserver(o2, o2.doc);
13546
+ const result2 = initMutationObserver(o2, o2.doc);
13547
+ mutationObserver = result2.observer;
13548
+ mutationBuffer = result2.buffer;
13543
13549
  }
13544
13550
  const mousemoveHandler = initMoveObserver(o2);
13545
13551
  const mouseInteractionHandler = initMouseInteractionObserver(o2);
@@ -13576,8 +13582,14 @@ function initObservers(o2, hooks = {}) {
13576
13582
  );
13577
13583
  }
13578
13584
  return callbackWrapper(() => {
13579
- mutationBuffers.forEach((b) => b.destroy());
13580
- mutationBuffers.forEach((b) => b.reset());
13585
+ if (mutationBuffer) {
13586
+ mutationBuffer.destroy();
13587
+ mutationBuffer.reset();
13588
+ const index2 = mutationBuffers.indexOf(mutationBuffer);
13589
+ if (index2 !== -1) {
13590
+ mutationBuffers.splice(index2, 1);
13591
+ }
13592
+ }
13581
13593
  mutationObserver == null ? void 0 : mutationObserver.disconnect();
13582
13594
  mousemoveHandler();
13583
13595
  mouseInteractionHandler();
@@ -13592,7 +13604,6 @@ function initObservers(o2, hooks = {}) {
13592
13604
  selectionObserver();
13593
13605
  customElementObserver();
13594
13606
  pluginHandlers.forEach((h) => h());
13595
- mutationBuffers.length = 0;
13596
13607
  });
13597
13608
  }
13598
13609
  function hasNestedCSSRule(prop) {
@@ -13993,7 +14004,7 @@ class ShadowDomManager {
13993
14004
  if (!isNativeShadowDom(shadowRoot2)) return;
13994
14005
  if (this.shadowDoms.has(shadowRoot2)) return;
13995
14006
  this.shadowDoms.add(shadowRoot2);
13996
- const observer = initMutationObserver(
14007
+ const { observer, buffer } = initMutationObserver(
13997
14008
  {
13998
14009
  ...this.bypassOptions,
13999
14010
  doc,
@@ -14003,7 +14014,15 @@ class ShadowDomManager {
14003
14014
  },
14004
14015
  shadowRoot2
14005
14016
  );
14006
- this.restoreHandlers.push(() => observer.disconnect());
14017
+ this.restoreHandlers.push(() => {
14018
+ observer.disconnect();
14019
+ buffer.destroy();
14020
+ buffer.reset();
14021
+ const index2 = mutationBuffers.indexOf(buffer);
14022
+ if (index2 !== -1) {
14023
+ mutationBuffers.splice(index2, 1);
14024
+ }
14025
+ });
14007
14026
  this.restoreHandlers.push(
14008
14027
  initScrollObserver({
14009
14028
  ...this.bypassOptions,
@@ -14880,6 +14899,26 @@ function record(options = {}) {
14880
14899
  polyfill$1();
14881
14900
  let lastFullSnapshotEvent;
14882
14901
  let incrementalSnapshotCount = 0;
14902
+ const iframeObserverCleanups = /* @__PURE__ */ new Map();
14903
+ function cleanupDetachedIframeObservers() {
14904
+ for (const [iframeId, cleanup] of iframeObserverCleanups) {
14905
+ const iframe = mirror.getNode(iframeId);
14906
+ if (!iframe) {
14907
+ cleanup();
14908
+ iframeObserverCleanups.delete(iframeId);
14909
+ continue;
14910
+ }
14911
+ try {
14912
+ if (!iframe.contentDocument || !iframe.contentDocument.defaultView) {
14913
+ cleanup();
14914
+ iframeObserverCleanups.delete(iframeId);
14915
+ }
14916
+ } catch {
14917
+ cleanup();
14918
+ iframeObserverCleanups.delete(iframeId);
14919
+ }
14920
+ }
14921
+ }
14883
14922
  const eventProcessor = (e2) => {
14884
14923
  for (const plugin of plugins || []) {
14885
14924
  if (plugin.eventProcessor) {
@@ -14930,9 +14969,15 @@ function record(options = {}) {
14930
14969
  const addedIds = m.adds.length > 0 ? new Set(m.adds.map((add) => add.node.id)) : null;
14931
14970
  m.removes.forEach(({ id }) => {
14932
14971
  if (!addedIds || !addedIds.has(id)) {
14972
+ const cleanup = iframeObserverCleanups.get(id);
14973
+ if (cleanup) {
14974
+ cleanup();
14975
+ iframeObserverCleanups.delete(id);
14976
+ }
14933
14977
  iframeManager.removeIframeById(id);
14934
14978
  }
14935
14979
  });
14980
+ cleanupDetachedIframeObservers();
14936
14981
  }
14937
14982
  wrappedEmit({
14938
14983
  type: EventType.IncrementalSnapshot,
@@ -15220,7 +15265,12 @@ function record(options = {}) {
15220
15265
  };
15221
15266
  const loadListener = (iframeEl) => {
15222
15267
  try {
15223
- handlers.push(observe(iframeEl.contentDocument));
15268
+ const iframeId = mirror.getId(iframeEl);
15269
+ const cleanup = observe(iframeEl.contentDocument);
15270
+ handlers.push(cleanup);
15271
+ if (iframeId !== -1) {
15272
+ iframeObserverCleanups.set(iframeId, cleanup);
15273
+ }
15224
15274
  } catch (error) {
15225
15275
  console.warn(error);
15226
15276
  }
@@ -15262,6 +15312,7 @@ function record(options = {}) {
15262
15312
  processedNodeManager.destroy();
15263
15313
  iframeManager.removeLoadListener();
15264
15314
  iframeManager.destroy();
15315
+ iframeObserverCleanups.clear();
15265
15316
  mirror.reset();
15266
15317
  recording = false;
15267
15318
  unregisterErrorHandler();