@posthog/rrweb-record 0.0.27 → 0.0.29

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.
@@ -10293,6 +10293,11 @@ class MutationBuffer {
10293
10293
  this.shadowDomManager.reset();
10294
10294
  this.canvasManager.reset();
10295
10295
  }
10296
+ destroy() {
10297
+ while (this.mapRemoves.length) {
10298
+ this.mirror.removeNodeFromMap(this.mapRemoves.shift());
10299
+ }
10300
+ }
10296
10301
  }
10297
10302
  function deepDelete(addsSet, n2) {
10298
10303
  addsSet.delete(n2);
@@ -11339,6 +11344,7 @@ function initObservers(o2, hooks = {}) {
11339
11344
  );
11340
11345
  }
11341
11346
  return callbackWrapper(() => {
11347
+ mutationBuffers.forEach((b) => b.destroy());
11342
11348
  mutationBuffers.forEach((b) => b.reset());
11343
11349
  mutationObserver == null ? void 0 : mutationObserver.disconnect();
11344
11350
  mousemoveHandler();
@@ -11676,6 +11682,8 @@ class IframeManager {
11676
11682
  contentWindow.removeEventListener("message", handler);
11677
11683
  });
11678
11684
  this.nestedIframeListeners.clear();
11685
+ this.crossOriginIframeMirror.reset();
11686
+ this.crossOriginIframeStyleMirror.reset();
11679
11687
  }
11680
11688
  }
11681
11689
  class ShadowDomManager {
@@ -11824,9 +11832,9 @@ const saveWebGLVar = (value, win, ctx) => {
11824
11832
  }
11825
11833
  return index2;
11826
11834
  };
11827
- function serializeArg(value, win, ctx) {
11835
+ function serializeArg(value, win, ctx, dataURLOptions) {
11828
11836
  if (value instanceof Array) {
11829
- return value.map((arg) => serializeArg(arg, win, ctx));
11837
+ return value.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11830
11838
  } else if (value === null) {
11831
11839
  return value;
11832
11840
  } else if (value instanceof Float32Array || value instanceof Float64Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Uint8Array || value instanceof Uint16Array || value instanceof Int16Array || value instanceof Int8Array || value instanceof Uint8ClampedArray) {
@@ -11852,7 +11860,7 @@ function serializeArg(value, win, ctx) {
11852
11860
  return {
11853
11861
  rr_type: name,
11854
11862
  args: [
11855
- serializeArg(value.buffer, win, ctx),
11863
+ serializeArg(value.buffer, win, ctx, dataURLOptions),
11856
11864
  value.byteOffset,
11857
11865
  value.byteLength
11858
11866
  ]
@@ -11866,7 +11874,7 @@ function serializeArg(value, win, ctx) {
11866
11874
  };
11867
11875
  } else if (value instanceof HTMLCanvasElement) {
11868
11876
  const name = "HTMLImageElement";
11869
- const src = value.toDataURL();
11877
+ const src = value.toDataURL(dataURLOptions.type, dataURLOptions.quality);
11870
11878
  return {
11871
11879
  rr_type: name,
11872
11880
  src
@@ -11875,7 +11883,11 @@ function serializeArg(value, win, ctx) {
11875
11883
  const name = value.constructor.name;
11876
11884
  return {
11877
11885
  rr_type: name,
11878
- args: [serializeArg(value.data, win, ctx), value.width, value.height]
11886
+ args: [
11887
+ serializeArg(value.data, win, ctx, dataURLOptions),
11888
+ value.width,
11889
+ value.height
11890
+ ]
11879
11891
  };
11880
11892
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
11881
11893
  const name = value.constructor.name;
@@ -11887,8 +11899,8 @@ function serializeArg(value, win, ctx) {
11887
11899
  }
11888
11900
  return value;
11889
11901
  }
11890
- const serializeArgs = (args, win, ctx) => {
11891
- return args.map((arg) => serializeArg(arg, win, ctx));
11902
+ const serializeArgs = (args, win, ctx, dataURLOptions) => {
11903
+ return args.map((arg) => serializeArg(arg, win, ctx, dataURLOptions));
11892
11904
  };
11893
11905
  const isInstanceOfWebGLObject = (value, win) => {
11894
11906
  const webGLConstructorNames = [
@@ -11914,7 +11926,7 @@ const isInstanceOfWebGLObject = (value, win) => {
11914
11926
  )
11915
11927
  );
11916
11928
  };
11917
- function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11929
+ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
11918
11930
  const handlers = [];
11919
11931
  const props2D = Object.getOwnPropertyNames(
11920
11932
  win.CanvasRenderingContext2D.prototype
@@ -11931,7 +11943,12 @@ function initCanvas2DMutationObserver(cb, win, blockClass, blockSelector) {
11931
11943
  return function(...args) {
11932
11944
  if (!isBlocked(this.canvas, blockClass, blockSelector, true)) {
11933
11945
  setTimeout(() => {
11934
- const recordArgs = serializeArgs(args, win, this);
11946
+ const recordArgs = serializeArgs(
11947
+ args,
11948
+ win,
11949
+ this,
11950
+ dataURLOptions
11951
+ );
11935
11952
  cb(this.canvas, {
11936
11953
  type: CanvasContext["2D"],
11937
11954
  property: prop,
@@ -12005,7 +12022,7 @@ function initCanvasContextObserver(win, blockClass, blockSelector, setPreserveDr
12005
12022
  handlers.forEach((h) => h());
12006
12023
  };
12007
12024
  }
12008
- function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12025
+ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win, dataURLOptions) {
12009
12026
  const handlers = [];
12010
12027
  const props = Object.getOwnPropertyNames(prototype);
12011
12028
  for (const prop of props) {
@@ -12032,7 +12049,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12032
12049
  const result2 = original.apply(this, args);
12033
12050
  saveWebGLVar(result2, win, this);
12034
12051
  if ("tagName" in this.canvas && !isBlocked(this.canvas, blockClass, blockSelector, true)) {
12035
- const recordArgs = serializeArgs(args, win, this);
12052
+ const recordArgs = serializeArgs(args, win, this, dataURLOptions);
12036
12053
  const mutation = {
12037
12054
  type,
12038
12055
  property: prop,
@@ -12061,7 +12078,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, blockSelector, win) {
12061
12078
  }
12062
12079
  return handlers;
12063
12080
  }
12064
- function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12081
+ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, dataURLOptions) {
12065
12082
  const handlers = [];
12066
12083
  handlers.push(
12067
12084
  ...patchGLPrototype(
@@ -12070,7 +12087,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12070
12087
  cb,
12071
12088
  blockClass,
12072
12089
  blockSelector,
12073
- win
12090
+ win,
12091
+ dataURLOptions
12074
12092
  )
12075
12093
  );
12076
12094
  if (typeof win.WebGL2RenderingContext !== "undefined") {
@@ -12081,7 +12099,8 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector) {
12081
12099
  cb,
12082
12100
  blockClass,
12083
12101
  blockSelector,
12084
- win
12102
+ win,
12103
+ dataURLOptions
12085
12104
  )
12086
12105
  );
12087
12106
  }
@@ -12123,6 +12142,8 @@ class CanvasManager {
12123
12142
  __publicField(this, "resetObservers");
12124
12143
  __publicField(this, "frozen", false);
12125
12144
  __publicField(this, "locked", false);
12145
+ __publicField(this, "rafIdTimestamp", null);
12146
+ __publicField(this, "rafIdFlush", null);
12126
12147
  __publicField(this, "processMutation", (target, mutation) => {
12127
12148
  const newFrame = this.rafStamps.invokeId && this.rafStamps.latestId !== this.rafStamps.invokeId;
12128
12149
  if (newFrame || !this.rafStamps.invokeId)
@@ -12143,7 +12164,12 @@ class CanvasManager {
12143
12164
  this.mutationCb = options.mutationCb;
12144
12165
  this.mirror = options.mirror;
12145
12166
  if (recordCanvas && sampling === "all")
12146
- this.initCanvasMutationObserver(win, blockClass, blockSelector);
12167
+ this.initCanvasMutationObserver(
12168
+ win,
12169
+ blockClass,
12170
+ blockSelector,
12171
+ dataURLOptions
12172
+ );
12147
12173
  if (recordCanvas && typeof sampling === "number")
12148
12174
  this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, {
12149
12175
  dataURLOptions
@@ -12152,6 +12178,14 @@ class CanvasManager {
12152
12178
  reset() {
12153
12179
  this.pendingCanvasMutations.clear();
12154
12180
  this.resetObservers && this.resetObservers();
12181
+ if (this.rafIdTimestamp !== null) {
12182
+ cancelAnimationFrame(this.rafIdTimestamp);
12183
+ this.rafIdTimestamp = null;
12184
+ }
12185
+ if (this.rafIdFlush !== null) {
12186
+ cancelAnimationFrame(this.rafIdFlush);
12187
+ this.rafIdFlush = null;
12188
+ }
12155
12189
  }
12156
12190
  freeze() {
12157
12191
  this.frozen = true;
@@ -12272,7 +12306,7 @@ class CanvasManager {
12272
12306
  cancelAnimationFrame(rafId);
12273
12307
  };
12274
12308
  }
12275
- initCanvasMutationObserver(win, blockClass, blockSelector) {
12309
+ initCanvasMutationObserver(win, blockClass, blockSelector, dataURLOptions) {
12276
12310
  this.startRAFTimestamping();
12277
12311
  this.startPendingCanvasMutationFlusher();
12278
12312
  const canvasContextReset = initCanvasContextObserver(
@@ -12285,13 +12319,15 @@ class CanvasManager {
12285
12319
  this.processMutation.bind(this),
12286
12320
  win,
12287
12321
  blockClass,
12288
- blockSelector
12322
+ blockSelector,
12323
+ dataURLOptions
12289
12324
  );
12290
12325
  const canvasWebGL1and2Reset = initCanvasWebGLMutationObserver(
12291
12326
  this.processMutation.bind(this),
12292
12327
  win,
12293
12328
  blockClass,
12294
- blockSelector
12329
+ blockSelector,
12330
+ dataURLOptions
12295
12331
  );
12296
12332
  this.resetObservers = () => {
12297
12333
  canvasContextReset();
@@ -12300,14 +12336,16 @@ class CanvasManager {
12300
12336
  };
12301
12337
  }
12302
12338
  startPendingCanvasMutationFlusher() {
12303
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
12339
+ this.rafIdFlush = requestAnimationFrame(
12340
+ () => this.flushPendingCanvasMutations()
12341
+ );
12304
12342
  }
12305
12343
  startRAFTimestamping() {
12306
12344
  const setLatestRAFTimestamp = (timestamp) => {
12307
12345
  this.rafStamps.latestId = timestamp;
12308
- requestAnimationFrame(setLatestRAFTimestamp);
12346
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
12309
12347
  };
12310
- requestAnimationFrame(setLatestRAFTimestamp);
12348
+ this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
12311
12349
  }
12312
12350
  flushPendingCanvasMutations() {
12313
12351
  this.pendingCanvasMutations.forEach(
@@ -12316,7 +12354,9 @@ class CanvasManager {
12316
12354
  this.flushPendingCanvasMutationFor(canvas, id);
12317
12355
  }
12318
12356
  );
12319
- requestAnimationFrame(() => this.flushPendingCanvasMutations());
12357
+ this.rafIdFlush = requestAnimationFrame(
12358
+ () => this.flushPendingCanvasMutations()
12359
+ );
12320
12360
  }
12321
12361
  flushPendingCanvasMutationFor(canvas, id) {
12322
12362
  if (this.frozen || this.locked) {
@@ -12895,6 +12935,7 @@ function record(options = {}) {
12895
12935
  processedNodeManager.destroy();
12896
12936
  iframeManager.removeLoadListener();
12897
12937
  iframeManager.destroy();
12938
+ mirror.reset();
12898
12939
  recording = false;
12899
12940
  unregisterErrorHandler();
12900
12941
  };