@posthog/rrweb-record 0.0.25 → 0.0.27

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.
@@ -11354,6 +11354,7 @@ function initObservers(o2, hooks = {}) {
11354
11354
  selectionObserver();
11355
11355
  customElementObserver();
11356
11356
  pluginHandlers.forEach((h) => h());
11357
+ mutationBuffers.length = 0;
11357
11358
  });
11358
11359
  }
11359
11360
  function hasNestedCSSRule(prop) {
@@ -11440,6 +11441,8 @@ class IframeManager {
11440
11441
  __publicField(this, "loadListener");
11441
11442
  __publicField(this, "stylesheetManager");
11442
11443
  __publicField(this, "recordCrossOriginIframes");
11444
+ __publicField(this, "messageHandler");
11445
+ __publicField(this, "nestedIframeListeners", /* @__PURE__ */ new Map());
11443
11446
  this.mutationCb = options.mutationCb;
11444
11447
  this.wrappedEmit = options.wrappedEmit;
11445
11448
  this.stylesheetManager = options.stylesheetManager;
@@ -11450,8 +11453,9 @@ class IframeManager {
11450
11453
  )
11451
11454
  );
11452
11455
  this.mirror = options.mirror;
11456
+ this.messageHandler = this.handleMessage.bind(this);
11453
11457
  if (this.recordCrossOriginIframes) {
11454
- window.addEventListener("message", this.handleMessage.bind(this));
11458
+ window.addEventListener("message", this.messageHandler);
11455
11459
  }
11456
11460
  }
11457
11461
  addIframe(iframeEl) {
@@ -11462,8 +11466,11 @@ class IframeManager {
11462
11466
  addLoadListener(cb) {
11463
11467
  this.loadListener = cb;
11464
11468
  }
11469
+ removeLoadListener() {
11470
+ this.loadListener = void 0;
11471
+ }
11465
11472
  attachIframe(iframeEl, childSn) {
11466
- var _a2, _b;
11473
+ var _a2;
11467
11474
  this.mutationCb({
11468
11475
  adds: [
11469
11476
  {
@@ -11477,12 +11484,13 @@ class IframeManager {
11477
11484
  attributes: [],
11478
11485
  isAttachIframe: true
11479
11486
  });
11480
- if (this.recordCrossOriginIframes)
11481
- (_a2 = iframeEl.contentWindow) == null ? void 0 : _a2.addEventListener(
11482
- "message",
11483
- this.handleMessage.bind(this)
11484
- );
11485
- (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
11487
+ const win = iframeEl.contentWindow;
11488
+ if (this.recordCrossOriginIframes && win && !this.nestedIframeListeners.has(win)) {
11489
+ const nestedHandler = this.handleMessage.bind(this);
11490
+ this.nestedIframeListeners.set(win, nestedHandler);
11491
+ win.addEventListener("message", nestedHandler);
11492
+ }
11493
+ (_a2 = this.loadListener) == null ? void 0 : _a2.call(this, iframeEl);
11486
11494
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
11487
11495
  this.stylesheetManager.adoptStyleSheets(
11488
11496
  iframeEl.contentDocument.adoptedStyleSheets,
@@ -11660,6 +11668,15 @@ class IframeManager {
11660
11668
  });
11661
11669
  }
11662
11670
  }
11671
+ destroy() {
11672
+ if (this.recordCrossOriginIframes) {
11673
+ window.removeEventListener("message", this.messageHandler);
11674
+ }
11675
+ this.nestedIframeListeners.forEach((handler, contentWindow) => {
11676
+ contentWindow.removeEventListener("message", handler);
11677
+ });
11678
+ this.nestedIframeListeners.clear();
11679
+ }
11663
11680
  }
11664
11681
  class ShadowDomManager {
11665
11682
  constructor(options) {
@@ -12834,13 +12851,14 @@ function record(options = {}) {
12834
12851
  hooks
12835
12852
  );
12836
12853
  };
12837
- iframeManager.addLoadListener((iframeEl) => {
12854
+ const loadListener = (iframeEl) => {
12838
12855
  try {
12839
12856
  handlers.push(observe(iframeEl.contentDocument));
12840
12857
  } catch (error) {
12841
12858
  console.warn(error);
12842
12859
  }
12843
- });
12860
+ };
12861
+ iframeManager.addLoadListener(loadListener);
12844
12862
  const init = () => {
12845
12863
  takeFullSnapshot$1();
12846
12864
  handlers.push(observe(document));
@@ -12875,6 +12893,8 @@ function record(options = {}) {
12875
12893
  return () => {
12876
12894
  handlers.forEach((h) => h());
12877
12895
  processedNodeManager.destroy();
12896
+ iframeManager.removeLoadListener();
12897
+ iframeManager.destroy();
12878
12898
  recording = false;
12879
12899
  unregisterErrorHandler();
12880
12900
  };