@glimt/record 0.0.25 → 0.0.27

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.
package/dist/record.cjs CHANGED
@@ -364,11 +364,9 @@ function toLowerCase(str) {
364
364
  }
365
365
  const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
366
366
  const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
367
- function getReadableCanvasContext(canvas) {
367
+ function getReadableCanvasContext(canvas, cachedContext) {
368
368
  if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
369
- return canvas.getContext("2d");
370
- console.log("cloning canvas for is2DCanvasBlank");
371
- const start = performance.now();
369
+ return cachedContext ?? canvas.getContext("2d");
372
370
  const offscreen = document.createElement("canvas");
373
371
  offscreen.width = canvas.width;
374
372
  offscreen.height = canvas.height;
@@ -376,16 +374,11 @@ function getReadableCanvasContext(canvas) {
376
374
  if (ctx) {
377
375
  ctx.drawImage(canvas, 0, 0);
378
376
  }
379
- console.log(
380
- "cloned canvas for is2DCanvasBlank took",
381
- performance.now() - start,
382
- "ms"
383
- );
384
377
  return offscreen.getContext("2d", { willReadFrequently: true });
385
378
  }
386
- function is2DCanvasBlank(canvas) {
379
+ function is2DCanvasBlank(canvas, cachedContext) {
387
380
  if (canvas.width === 0 || canvas.height === 0) return true;
388
- const ctx = getReadableCanvasContext(canvas);
381
+ const ctx = getReadableCanvasContext(canvas, cachedContext);
389
382
  if (!ctx) return true;
390
383
  const chunkSize = canvas.width > 512 || canvas.height > 512 ? 100 : 50;
391
384
  const getImageData = ctx.getImageData;
@@ -905,6 +898,13 @@ function getRootId(doc, mirror2) {
905
898
  const docId = mirror2.getId(doc);
906
899
  return docId === 1 ? void 0 : docId;
907
900
  }
901
+ const runIdleCallback = (cb) => {
902
+ if ("requestIdleCallback" in window) {
903
+ window.requestIdleCallback(cb);
904
+ } else {
905
+ setTimeout(cb, 100);
906
+ }
907
+ };
908
908
  function serializeTextNode(n2, options) {
909
909
  const { needsMask, maskTextFn, rootId, cssCaptured } = options;
910
910
  const parent = index$1.parentNode(n2);
@@ -1012,22 +1012,21 @@ function serializeElementNode(n2, options) {
1012
1012
  attributes.rr_open_mode = n2.matches("dialog:modal") ? "modal" : "non-modal";
1013
1013
  }
1014
1014
  if (tagName === "canvas" && recordCanvas) {
1015
- if (n2.__context === "2d") {
1016
- const start2dCanvas = performance.now();
1017
- if (!is2DCanvasBlank(n2)) {
1015
+ let context = "getContext" in n2 ? n2.getContext("2d") : null;
1016
+ if (context != null) {
1017
+ if (!is2DCanvasBlank(n2, context)) {
1018
1018
  attributes.rr_dataURL = n2.toDataURL(
1019
1019
  dataURLOptions.type,
1020
1020
  dataURLOptions.quality
1021
1021
  );
1022
1022
  }
1023
- console.log("2d canvas took", performance.now() - start2dCanvas, "ms");
1024
- } else if (!("__context" in n2)) {
1023
+ } else if (n2.width !== 0 && n2.height !== 0) {
1025
1024
  const canvasDataURL = n2.toDataURL(
1026
1025
  dataURLOptions.type,
1027
1026
  dataURLOptions.quality
1028
1027
  );
1029
1028
  attributes.rr_dataURL = canvasDataURL;
1030
- requestIdleCallback(() => {
1029
+ runIdleCallback(() => {
1031
1030
  try {
1032
1031
  const blankCanvas = doc.createElement("canvas");
1033
1032
  blankCanvas.width = n2.width;
@@ -1037,13 +1036,9 @@ function serializeElementNode(n2, options) {
1037
1036
  dataURLOptions.quality
1038
1037
  );
1039
1038
  if (canvasDataURL === blankCanvasDataURL) {
1040
- console.log(
1041
- "deleting dataURL because it's the same as blank canvas"
1042
- );
1043
1039
  delete attributes.rr_dataURL;
1044
1040
  }
1045
1041
  } catch (e2) {
1046
- console.log("did get context canvas error", e2);
1047
1042
  }
1048
1043
  });
1049
1044
  }
@@ -9852,25 +9847,30 @@ class MutationBuffer {
9852
9847
  for (let i2 = 0; i2 < m.addedNodes.length; i2++) {
9853
9848
  this.genAdds(m.addedNodes[i2], m.target);
9854
9849
  }
9850
+ const parentId = isShadowRoot(m.target) ? this.mirror.getId(index.host(m.target)) : this.mirror.getId(m.target);
9851
+ if (isBlocked(m.target, this.blockClass, this.blockSelector, false))
9852
+ return;
9853
+ const addedSetHas = this.addedSet.has(m.target);
9854
+ const ancestorRemoved = isAncestorRemoved(m.target, this.mirror);
9855
+ const isShadow = isShadowRoot(m.target) && isNativeShadowDom(m.target) ? true : void 0;
9855
9856
  for (let i2 = 0; i2 < m.removedNodes.length; i2++) {
9856
9857
  const n2 = m.removedNodes[i2];
9857
9858
  const nodeId = this.mirror.getId(n2);
9858
- const parentId = isShadowRoot(m.target) ? this.mirror.getId(index.host(m.target)) : this.mirror.getId(m.target);
9859
- if (isBlocked(m.target, this.blockClass, this.blockSelector, false) || isIgnored(n2, this.mirror, this.slimDOMOptions) || !isSerialized(n2, this.mirror)) {
9859
+ if (isIgnored(n2, this.mirror, this.slimDOMOptions) || !isSerialized(n2, this.mirror)) {
9860
9860
  return;
9861
9861
  }
9862
9862
  if (this.addedSet.has(n2)) {
9863
9863
  deepDelete(this.addedSet, n2);
9864
9864
  this.droppedSet.add(n2);
9865
- } else if (this.addedSet.has(m.target) && nodeId === -1) ;
9866
- else if (isAncestorRemoved(m.target, this.mirror)) ;
9865
+ } else if (addedSetHas && nodeId === -1) ;
9866
+ else if (ancestorRemoved) ;
9867
9867
  else if (this.movedSet.has(n2) && this.movedMap[moveKey(nodeId, parentId)]) {
9868
9868
  deepDelete(this.movedSet, n2);
9869
9869
  } else {
9870
9870
  this.removes.push({
9871
9871
  parentId,
9872
9872
  id: nodeId,
9873
- isShadow: isShadowRoot(m.target) && isNativeShadowDom(m.target) ? true : void 0
9873
+ isShadow
9874
9874
  });
9875
9875
  processRemoves(n2, this.removesSubTreeCache);
9876
9876
  }