@posthog/rrweb 0.0.25 → 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.
@@ -13251,6 +13251,7 @@ function initObservers(o2, hooks = {}) {
13251
13251
  selectionObserver();
13252
13252
  customElementObserver();
13253
13253
  pluginHandlers.forEach((h) => h());
13254
+ mutationBuffers.length = 0;
13254
13255
  });
13255
13256
  }
13256
13257
  function hasNestedCSSRule(prop) {
@@ -13337,6 +13338,8 @@ class IframeManager {
13337
13338
  __publicField(this, "loadListener");
13338
13339
  __publicField(this, "stylesheetManager");
13339
13340
  __publicField(this, "recordCrossOriginIframes");
13341
+ __publicField(this, "messageHandler");
13342
+ __publicField(this, "nestedIframeListeners", /* @__PURE__ */ new Map());
13340
13343
  this.mutationCb = options.mutationCb;
13341
13344
  this.wrappedEmit = options.wrappedEmit;
13342
13345
  this.stylesheetManager = options.stylesheetManager;
@@ -13347,8 +13350,9 @@ class IframeManager {
13347
13350
  )
13348
13351
  );
13349
13352
  this.mirror = options.mirror;
13353
+ this.messageHandler = this.handleMessage.bind(this);
13350
13354
  if (this.recordCrossOriginIframes) {
13351
- window.addEventListener("message", this.handleMessage.bind(this));
13355
+ window.addEventListener("message", this.messageHandler);
13352
13356
  }
13353
13357
  }
13354
13358
  addIframe(iframeEl) {
@@ -13360,7 +13364,7 @@ class IframeManager {
13360
13364
  this.loadListener = cb;
13361
13365
  }
13362
13366
  attachIframe(iframeEl, childSn) {
13363
- var _a2, _b;
13367
+ var _a2;
13364
13368
  this.mutationCb({
13365
13369
  adds: [
13366
13370
  {
@@ -13374,12 +13378,13 @@ class IframeManager {
13374
13378
  attributes: [],
13375
13379
  isAttachIframe: true
13376
13380
  });
13377
- if (this.recordCrossOriginIframes)
13378
- (_a2 = iframeEl.contentWindow) == null ? void 0 : _a2.addEventListener(
13379
- "message",
13380
- this.handleMessage.bind(this)
13381
- );
13382
- (_b = this.loadListener) == null ? void 0 : _b.call(this, iframeEl);
13381
+ const win = iframeEl.contentWindow;
13382
+ if (this.recordCrossOriginIframes && win && !this.nestedIframeListeners.has(win)) {
13383
+ const nestedHandler = this.handleMessage.bind(this);
13384
+ this.nestedIframeListeners.set(win, nestedHandler);
13385
+ win.addEventListener("message", nestedHandler);
13386
+ }
13387
+ (_a2 = this.loadListener) == null ? void 0 : _a2.call(this, iframeEl);
13383
13388
  if (iframeEl.contentDocument && iframeEl.contentDocument.adoptedStyleSheets && iframeEl.contentDocument.adoptedStyleSheets.length > 0)
13384
13389
  this.stylesheetManager.adoptStyleSheets(
13385
13390
  iframeEl.contentDocument.adoptedStyleSheets,
@@ -13557,6 +13562,15 @@ class IframeManager {
13557
13562
  });
13558
13563
  }
13559
13564
  }
13565
+ destroy() {
13566
+ if (this.recordCrossOriginIframes) {
13567
+ window.removeEventListener("message", this.messageHandler);
13568
+ }
13569
+ this.nestedIframeListeners.forEach((handler, contentWindow) => {
13570
+ contentWindow.removeEventListener("message", handler);
13571
+ });
13572
+ this.nestedIframeListeners.clear();
13573
+ }
13560
13574
  }
13561
13575
  class ShadowDomManager {
13562
13576
  constructor(options) {
@@ -14777,6 +14791,7 @@ function record(options = {}) {
14777
14791
  return () => {
14778
14792
  handlers.forEach((h) => h());
14779
14793
  processedNodeManager.destroy();
14794
+ iframeManager.destroy();
14780
14795
  recording = false;
14781
14796
  unregisterErrorHandler();
14782
14797
  };
@@ -15990,6 +16005,11 @@ class Replayer {
15990
16005
  __publicField(this, "lastSelectionData", null);
15991
16006
  __publicField(this, "constructedStyleMutations", []);
15992
16007
  __publicField(this, "adoptedStyleSheets", []);
16008
+ __publicField(this, "emitterHandlers", []);
16009
+ __publicField(this, "serviceSubscription");
16010
+ __publicField(this, "speedServiceSubscription");
16011
+ __publicField(this, "timeouts", /* @__PURE__ */ new Set());
16012
+ __publicField(this, "styleSheetLoadListeners", /* @__PURE__ */ new Map());
15993
16013
  __publicField(this, "handleResize", (dimension) => {
15994
16014
  this.iframe.style.display = "inherit";
15995
16015
  for (const el of [this.mouseTail, this.iframe]) {
@@ -16149,12 +16169,12 @@ class Replayer {
16149
16169
  this.handleResize = this.handleResize.bind(this);
16150
16170
  this.getCastFn = this.getCastFn.bind(this);
16151
16171
  this.applyEventsSynchronously = this.applyEventsSynchronously.bind(this);
16152
- this.emitter.on(ReplayerEvents.Resize, this.handleResize);
16172
+ this.addEmitterHandler(ReplayerEvents.Resize, this.handleResize);
16153
16173
  this.setupDom();
16154
16174
  for (const plugin of this.config.plugins || []) {
16155
16175
  if (plugin.getMirror) plugin.getMirror({ nodeMirror: this.mirror });
16156
16176
  }
16157
- this.emitter.on(ReplayerEvents.Flush, () => {
16177
+ const flushHandler = () => {
16158
16178
  if (this.usingVirtualDom) {
16159
16179
  const replayerHandler = {
16160
16180
  mirror: this.mirror,
@@ -16250,13 +16270,15 @@ class Replayer {
16250
16270
  this.applySelection(this.lastSelectionData);
16251
16271
  this.lastSelectionData = null;
16252
16272
  }
16253
- });
16254
- this.emitter.on(ReplayerEvents.PlayBack, () => {
16273
+ };
16274
+ this.addEmitterHandler(ReplayerEvents.Flush, flushHandler);
16275
+ const playBackHandler = () => {
16255
16276
  this.firstFullSnapshot = null;
16256
16277
  this.mirror.reset();
16257
16278
  this.styleMirror.reset();
16258
16279
  this.mediaManager.reset();
16259
- });
16280
+ };
16281
+ this.addEmitterHandler(ReplayerEvents.PlayBack, playBackHandler);
16260
16282
  const timer = new Timer([], {
16261
16283
  speed: this.config.speed
16262
16284
  });
@@ -16280,7 +16302,7 @@ class Replayer {
16280
16302
  }
16281
16303
  );
16282
16304
  this.service.start();
16283
- this.service.subscribe((state) => {
16305
+ this.serviceSubscription = this.service.subscribe((state) => {
16284
16306
  this.emitter.emit(ReplayerEvents.StateChange, {
16285
16307
  player: state
16286
16308
  });
@@ -16290,7 +16312,7 @@ class Replayer {
16290
16312
  timer
16291
16313
  });
16292
16314
  this.speedService.start();
16293
- this.speedService.subscribe((state) => {
16315
+ this.speedServiceSubscription = this.speedService.subscribe((state) => {
16294
16316
  this.emitter.emit(ReplayerEvents.StateChange, {
16295
16317
  speed: state
16296
16318
  });
@@ -16310,7 +16332,7 @@ class Replayer {
16310
16332
  );
16311
16333
  if (firstMeta) {
16312
16334
  const { width, height } = firstMeta.data;
16313
- setTimeout(() => {
16335
+ this.addTimeout(() => {
16314
16336
  this.emitter.emit(ReplayerEvents.Resize, {
16315
16337
  width,
16316
16338
  height
@@ -16318,7 +16340,7 @@ class Replayer {
16318
16340
  }, 0);
16319
16341
  }
16320
16342
  if (firstFullsnapshot) {
16321
- setTimeout(() => {
16343
+ this.addTimeout(() => {
16322
16344
  var _a2;
16323
16345
  if (this.firstFullSnapshot) {
16324
16346
  return;
@@ -16347,6 +16369,24 @@ class Replayer {
16347
16369
  this.emitter.off(event, handler);
16348
16370
  return this;
16349
16371
  }
16372
+ /**
16373
+ * Track emitter handlers for cleanup
16374
+ */
16375
+ addEmitterHandler(event, handler) {
16376
+ this.emitter.on(event, handler);
16377
+ this.emitterHandlers.push({ event, handler });
16378
+ }
16379
+ /**
16380
+ * Track timeouts for cleanup
16381
+ */
16382
+ addTimeout(callback, delay) {
16383
+ const timeout = setTimeout(() => {
16384
+ this.timeouts.delete(timeout);
16385
+ callback();
16386
+ }, delay);
16387
+ this.timeouts.add(timeout);
16388
+ return timeout;
16389
+ }
16350
16390
  setConfig(config) {
16351
16391
  Object.keys(config).forEach((key) => {
16352
16392
  config[key];
@@ -16449,10 +16489,31 @@ class Replayer {
16449
16489
  * Memory occupation can be released by removing all references to this replayer.
16450
16490
  */
16451
16491
  destroy() {
16492
+ var _a2, _b;
16493
+ if (!this.wrapper || !this.wrapper.parentNode) {
16494
+ return;
16495
+ }
16452
16496
  this.pause();
16497
+ this.emitterHandlers.forEach(({ event, handler }) => {
16498
+ this.emitter.off(event, handler);
16499
+ });
16500
+ this.emitterHandlers = [];
16501
+ (_a2 = this.serviceSubscription) == null ? void 0 : _a2.unsubscribe();
16502
+ (_b = this.speedServiceSubscription) == null ? void 0 : _b.unsubscribe();
16503
+ this.serviceSubscription = void 0;
16504
+ this.speedServiceSubscription = void 0;
16505
+ this.timeouts.forEach((timeout) => clearTimeout(timeout));
16506
+ this.timeouts.clear();
16507
+ this.styleSheetLoadListeners.forEach((handler, element) => {
16508
+ element.removeEventListener("load", handler);
16509
+ });
16510
+ this.styleSheetLoadListeners.clear();
16511
+ this.imageMap.clear();
16512
+ this.canvasEventMap.clear();
16453
16513
  this.mirror.reset();
16454
16514
  this.styleMirror.reset();
16455
16515
  this.mediaManager.reset();
16516
+ this.resetCache();
16456
16517
  this.config.root.removeChild(this.wrapper);
16457
16518
  this.emitter.emit(ReplayerEvents.Destroy);
16458
16519
  }