@posthog/rrweb-record 0.0.24 → 0.0.26

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.
@@ -240,8 +240,8 @@ function stringifyStylesheet(s2) {
240
240
  return null;
241
241
  }
242
242
  let sheetHref = s2.href;
243
- if (!sheetHref && s2.ownerNode && s2.ownerNode.ownerDocument) {
244
- sheetHref = s2.ownerNode.ownerDocument.baseURI;
243
+ if (!sheetHref && s2.ownerNode) {
244
+ sheetHref = s2.ownerNode.baseURI;
245
245
  }
246
246
  const stringifiedRules = Array.from(
247
247
  rules2,
@@ -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) {
@@ -11463,7 +11467,7 @@ class IframeManager {
11463
11467
  this.loadListener = cb;
11464
11468
  }
11465
11469
  attachIframe(iframeEl, childSn) {
11466
- var _a2, _b;
11470
+ var _a2;
11467
11471
  this.mutationCb({
11468
11472
  adds: [
11469
11473
  {
@@ -11477,12 +11481,13 @@ class IframeManager {
11477
11481
  attributes: [],
11478
11482
  isAttachIframe: true
11479
11483
  });
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);
11484
+ const win = iframeEl.contentWindow;
11485
+ if (this.recordCrossOriginIframes && win && !this.nestedIframeListeners.has(win)) {
11486
+ const nestedHandler = this.handleMessage.bind(this);
11487
+ this.nestedIframeListeners.set(win, nestedHandler);
11488
+ win.addEventListener("message", nestedHandler);
11489
+ }
11490
+ (_a2 = this.loadListener) == null ? void 0 : _a2.call(this, iframeEl);
11486
11491
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
11487
11492
  this.stylesheetManager.adoptStyleSheets(
11488
11493
  iframeEl.contentDocument.adoptedStyleSheets,
@@ -11660,6 +11665,15 @@ class IframeManager {
11660
11665
  });
11661
11666
  }
11662
11667
  }
11668
+ destroy() {
11669
+ if (this.recordCrossOriginIframes) {
11670
+ window.removeEventListener("message", this.messageHandler);
11671
+ }
11672
+ this.nestedIframeListeners.forEach((handler, contentWindow) => {
11673
+ contentWindow.removeEventListener("message", handler);
11674
+ });
11675
+ this.nestedIframeListeners.clear();
11676
+ }
11663
11677
  }
11664
11678
  class ShadowDomManager {
11665
11679
  constructor(options) {
@@ -12875,6 +12889,7 @@ function record(options = {}) {
12875
12889
  return () => {
12876
12890
  handlers.forEach((h) => h());
12877
12891
  processedNodeManager.destroy();
12892
+ iframeManager.destroy();
12878
12893
  recording = false;
12879
12894
  unregisterErrorHandler();
12880
12895
  };