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