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