@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.
@@ -11396,6 +11396,7 @@ function initObservers(o2, hooks = {}) {
11396
11396
  selectionObserver();
11397
11397
  customElementObserver();
11398
11398
  pluginHandlers.forEach((h) => h());
11399
+ mutationBuffers.length = 0;
11399
11400
  });
11400
11401
  }
11401
11402
  function hasNestedCSSRule(prop) {
@@ -11482,6 +11483,8 @@ class IframeManager {
11482
11483
  __publicField(this, "loadListener");
11483
11484
  __publicField(this, "stylesheetManager");
11484
11485
  __publicField(this, "recordCrossOriginIframes");
11486
+ __publicField(this, "messageHandler");
11487
+ __publicField(this, "nestedIframeListeners", /* @__PURE__ */ new Map());
11485
11488
  this.mutationCb = options.mutationCb;
11486
11489
  this.wrappedEmit = options.wrappedEmit;
11487
11490
  this.stylesheetManager = options.stylesheetManager;
@@ -11492,8 +11495,9 @@ class IframeManager {
11492
11495
  )
11493
11496
  );
11494
11497
  this.mirror = options.mirror;
11498
+ this.messageHandler = this.handleMessage.bind(this);
11495
11499
  if (this.recordCrossOriginIframes) {
11496
- window.addEventListener("message", this.handleMessage.bind(this));
11500
+ window.addEventListener("message", this.messageHandler);
11497
11501
  }
11498
11502
  }
11499
11503
  addIframe(iframeEl) {
@@ -11504,8 +11508,11 @@ class IframeManager {
11504
11508
  addLoadListener(cb) {
11505
11509
  this.loadListener = cb;
11506
11510
  }
11511
+ removeLoadListener() {
11512
+ this.loadListener = void 0;
11513
+ }
11507
11514
  attachIframe(iframeEl, childSn) {
11508
- var _a2, _b;
11515
+ var _a2;
11509
11516
  this.mutationCb({
11510
11517
  adds: [
11511
11518
  {
@@ -11519,12 +11526,13 @@ class IframeManager {
11519
11526
  attributes: [],
11520
11527
  isAttachIframe: true
11521
11528
  });
11522
- if (this.recordCrossOriginIframes)
11523
- (_a2 = iframeEl.contentWindow) == null ? void 0 : _a2.addEventListener(
11524
- "message",
11525
- this.handleMessage.bind(this)
11526
- );
11527
- (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
11529
+ const win = iframeEl.contentWindow;
11530
+ if (this.recordCrossOriginIframes && win && !this.nestedIframeListeners.has(win)) {
11531
+ const nestedHandler = this.handleMessage.bind(this);
11532
+ this.nestedIframeListeners.set(win, nestedHandler);
11533
+ win.addEventListener("message", nestedHandler);
11534
+ }
11535
+ (_a2 = this.loadListener) == null ? void 0 : _a2.call(this, iframeEl);
11528
11536
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
11529
11537
  this.stylesheetManager.adoptStyleSheets(
11530
11538
  iframeEl.contentDocument.adoptedStyleSheets,
@@ -11702,6 +11710,15 @@ class IframeManager {
11702
11710
  });
11703
11711
  }
11704
11712
  }
11713
+ destroy() {
11714
+ if (this.recordCrossOriginIframes) {
11715
+ window.removeEventListener("message", this.messageHandler);
11716
+ }
11717
+ this.nestedIframeListeners.forEach((handler, contentWindow) => {
11718
+ contentWindow.removeEventListener("message", handler);
11719
+ });
11720
+ this.nestedIframeListeners.clear();
11721
+ }
11705
11722
  }
11706
11723
  class ShadowDomManager {
11707
11724
  constructor(options) {
@@ -12861,13 +12878,14 @@ function record(options = {}) {
12861
12878
  hooks
12862
12879
  );
12863
12880
  };
12864
- iframeManager.addLoadListener((iframeEl) => {
12881
+ const loadListener = (iframeEl) => {
12865
12882
  try {
12866
12883
  handlers.push(observe(iframeEl.contentDocument));
12867
12884
  } catch (error) {
12868
12885
  console.warn(error);
12869
12886
  }
12870
- });
12887
+ };
12888
+ iframeManager.addLoadListener(loadListener);
12871
12889
  const init = () => {
12872
12890
  takeFullSnapshot$1();
12873
12891
  handlers.push(observe(document));
@@ -12902,6 +12920,8 @@ function record(options = {}) {
12902
12920
  return () => {
12903
12921
  handlers.forEach((h) => h());
12904
12922
  processedNodeManager.destroy();
12923
+ iframeManager.removeLoadListener();
12924
+ iframeManager.destroy();
12905
12925
  recording = false;
12906
12926
  unregisterErrorHandler();
12907
12927
  };