@posthog/rrweb 0.0.46 → 0.0.47

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