@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.
@@ -284,8 +284,8 @@ function stringifyStylesheet(s2) {
284
284
  return null;
285
285
  }
286
286
  let sheetHref = s2.href;
287
- if (!sheetHref && s2.ownerNode && s2.ownerNode.ownerDocument) {
288
- sheetHref = s2.ownerNode.ownerDocument.baseURI;
287
+ if (!sheetHref && s2.ownerNode) {
288
+ sheetHref = s2.ownerNode.baseURI;
289
289
  }
290
290
  const stringifiedRules = Array.from(
291
291
  rules2,
@@ -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) {
@@ -11505,7 +11509,7 @@ class IframeManager {
11505
11509
  this.loadListener = cb;
11506
11510
  }
11507
11511
  attachIframe(iframeEl, childSn) {
11508
- var _a2, _b;
11512
+ var _a2;
11509
11513
  this.mutationCb({
11510
11514
  adds: [
11511
11515
  {
@@ -11519,12 +11523,13 @@ class IframeManager {
11519
11523
  attributes: [],
11520
11524
  isAttachIframe: true
11521
11525
  });
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);
11526
+ const win = iframeEl.contentWindow;
11527
+ if (this.recordCrossOriginIframes && win && !this.nestedIframeListeners.has(win)) {
11528
+ const nestedHandler = this.handleMessage.bind(this);
11529
+ this.nestedIframeListeners.set(win, nestedHandler);
11530
+ win.addEventListener("message", nestedHandler);
11531
+ }
11532
+ (_a2 = this.loadListener) == null ? void 0 : _a2.call(this, iframeEl);
11528
11533
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
11529
11534
  this.stylesheetManager.adoptStyleSheets(
11530
11535
  iframeEl.contentDocument.adoptedStyleSheets,
@@ -11702,6 +11707,15 @@ class IframeManager {
11702
11707
  });
11703
11708
  }
11704
11709
  }
11710
+ destroy() {
11711
+ if (this.recordCrossOriginIframes) {
11712
+ window.removeEventListener("message", this.messageHandler);
11713
+ }
11714
+ this.nestedIframeListeners.forEach((handler, contentWindow) => {
11715
+ contentWindow.removeEventListener("message", handler);
11716
+ });
11717
+ this.nestedIframeListeners.clear();
11718
+ }
11705
11719
  }
11706
11720
  class ShadowDomManager {
11707
11721
  constructor(options) {
@@ -12902,6 +12916,7 @@ function record(options = {}) {
12902
12916
  return () => {
12903
12917
  handlers.forEach((h) => h());
12904
12918
  processedNodeManager.destroy();
12919
+ iframeManager.destroy();
12905
12920
  recording = false;
12906
12921
  unregisterErrorHandler();
12907
12922
  };