@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.
@@ -396,11 +396,9 @@ function toLowerCase(str) {
396
396
  }
397
397
  const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
398
398
  const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
399
- function getReadableCanvasContext(canvas) {
399
+ function getReadableCanvasContext(canvas, cachedContext) {
400
400
  if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
401
- return canvas.getContext("2d");
402
- console.log("cloning canvas for is2DCanvasBlank");
403
- const start = performance.now();
401
+ return cachedContext != null ? cachedContext : canvas.getContext("2d");
404
402
  const offscreen = document.createElement("canvas");
405
403
  offscreen.width = canvas.width;
406
404
  offscreen.height = canvas.height;
@@ -408,16 +406,11 @@ function getReadableCanvasContext(canvas) {
408
406
  if (ctx) {
409
407
  ctx.drawImage(canvas, 0, 0);
410
408
  }
411
- console.log(
412
- "cloned canvas for is2DCanvasBlank took",
413
- performance.now() - start,
414
- "ms"
415
- );
416
409
  return offscreen.getContext("2d", { willReadFrequently: true });
417
410
  }
418
- function is2DCanvasBlank(canvas) {
411
+ function is2DCanvasBlank(canvas, cachedContext) {
419
412
  if (canvas.width === 0 || canvas.height === 0) return true;
420
- const ctx = getReadableCanvasContext(canvas);
413
+ const ctx = getReadableCanvasContext(canvas, cachedContext);
421
414
  if (!ctx) return true;
422
415
  const chunkSize = canvas.width > 512 || canvas.height > 512 ? 100 : 50;
423
416
  const getImageData = ctx.getImageData;
@@ -938,6 +931,13 @@ function getRootId(doc, mirror2) {
938
931
  const docId = mirror2.getId(doc);
939
932
  return docId === 1 ? void 0 : docId;
940
933
  }
934
+ const runIdleCallback = (cb) => {
935
+ if ("requestIdleCallback" in window) {
936
+ window.requestIdleCallback(cb);
937
+ } else {
938
+ setTimeout(cb, 100);
939
+ }
940
+ };
941
941
  function serializeTextNode(n2, options) {
942
942
  const { needsMask, maskTextFn, rootId, cssCaptured } = options;
943
943
  const parent = index$1.parentNode(n2);
@@ -1045,22 +1045,21 @@ function serializeElementNode(n2, options) {
1045
1045
  attributes.rr_open_mode = n2.matches("dialog:modal") ? "modal" : "non-modal";
1046
1046
  }
1047
1047
  if (tagName === "canvas" && recordCanvas) {
1048
- if (n2.__context === "2d") {
1049
- const start2dCanvas = performance.now();
1050
- if (!is2DCanvasBlank(n2)) {
1048
+ let context = "getContext" in n2 ? n2.getContext("2d") : null;
1049
+ if (context != null) {
1050
+ if (!is2DCanvasBlank(n2, context)) {
1051
1051
  attributes.rr_dataURL = n2.toDataURL(
1052
1052
  dataURLOptions.type,
1053
1053
  dataURLOptions.quality
1054
1054
  );
1055
1055
  }
1056
- console.log("2d canvas took", performance.now() - start2dCanvas, "ms");
1057
- } else if (!("__context" in n2)) {
1056
+ } else if (n2.width !== 0 && n2.height !== 0) {
1058
1057
  const canvasDataURL = n2.toDataURL(
1059
1058
  dataURLOptions.type,
1060
1059
  dataURLOptions.quality
1061
1060
  );
1062
1061
  attributes.rr_dataURL = canvasDataURL;
1063
- requestIdleCallback(() => {
1062
+ runIdleCallback(() => {
1064
1063
  try {
1065
1064
  const blankCanvas = doc.createElement("canvas");
1066
1065
  blankCanvas.width = n2.width;
@@ -1070,13 +1069,9 @@ function serializeElementNode(n2, options) {
1070
1069
  dataURLOptions.quality
1071
1070
  );
1072
1071
  if (canvasDataURL === blankCanvasDataURL) {
1073
- console.log(
1074
- "deleting dataURL because it's the same as blank canvas"
1075
- );
1076
1072
  delete attributes.rr_dataURL;
1077
1073
  }
1078
1074
  } catch (e2) {
1079
- console.log("did get context canvas error", e2);
1080
1075
  }
1081
1076
  });
1082
1077
  }
@@ -9894,25 +9889,30 @@ class MutationBuffer {
9894
9889
  for (let i2 = 0; i2 < m.addedNodes.length; i2++) {
9895
9890
  this.genAdds(m.addedNodes[i2], m.target);
9896
9891
  }
9892
+ const parentId = isShadowRoot(m.target) ? this.mirror.getId(index.host(m.target)) : this.mirror.getId(m.target);
9893
+ if (isBlocked(m.target, this.blockClass, this.blockSelector, false))
9894
+ return;
9895
+ const addedSetHas = this.addedSet.has(m.target);
9896
+ const ancestorRemoved = isAncestorRemoved(m.target, this.mirror);
9897
+ const isShadow = isShadowRoot(m.target) && isNativeShadowDom(m.target) ? true : void 0;
9897
9898
  for (let i2 = 0; i2 < m.removedNodes.length; i2++) {
9898
9899
  const n2 = m.removedNodes[i2];
9899
9900
  const nodeId = this.mirror.getId(n2);
9900
- const parentId = isShadowRoot(m.target) ? this.mirror.getId(index.host(m.target)) : this.mirror.getId(m.target);
9901
- if (isBlocked(m.target, this.blockClass, this.blockSelector, false) || isIgnored(n2, this.mirror, this.slimDOMOptions) || !isSerialized(n2, this.mirror)) {
9901
+ if (isIgnored(n2, this.mirror, this.slimDOMOptions) || !isSerialized(n2, this.mirror)) {
9902
9902
  return;
9903
9903
  }
9904
9904
  if (this.addedSet.has(n2)) {
9905
9905
  deepDelete(this.addedSet, n2);
9906
9906
  this.droppedSet.add(n2);
9907
- } else if (this.addedSet.has(m.target) && nodeId === -1) ;
9908
- else if (isAncestorRemoved(m.target, this.mirror)) ;
9907
+ } else if (addedSetHas && nodeId === -1) ;
9908
+ else if (ancestorRemoved) ;
9909
9909
  else if (this.movedSet.has(n2) && this.movedMap[moveKey(nodeId, parentId)]) {
9910
9910
  deepDelete(this.movedSet, n2);
9911
9911
  } else {
9912
9912
  this.removes.push({
9913
9913
  parentId,
9914
9914
  id: nodeId,
9915
- isShadow: isShadowRoot(m.target) && isNativeShadowDom(m.target) ? true : void 0
9915
+ isShadow
9916
9916
  });
9917
9917
  processRemoves(n2, this.removesSubTreeCache);
9918
9918
  }