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