@glimt/record 0.0.14 → 0.0.15

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.
@@ -395,19 +395,31 @@ function toLowerCase(str) {
395
395
  return str.toLowerCase();
396
396
  }
397
397
  const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
398
+ const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
399
+ function getReadableCanvasContext(canvas) {
400
+ if (canvas.width === 0 || canvas.height === 0) return canvas.getContext("2d");
401
+ if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
402
+ return canvas.getContext("2d");
403
+ console.log(
404
+ "detected large canvas, copying to offscreen canvas for willReadFrequently"
405
+ );
406
+ const offscreen = document.createElement("canvas");
407
+ offscreen.width = canvas.width;
408
+ offscreen.height = canvas.height;
409
+ const ctx = offscreen.getContext("2d");
410
+ if (ctx) {
411
+ ctx.drawImage(canvas, 0, 0);
412
+ }
413
+ return offscreen.getContext("2d", { willReadFrequently: true });
414
+ }
398
415
  function is2DCanvasBlank(canvas) {
399
- console.log("Creating context with willReadFrequently:", canvas);
400
- const ctx = canvas.getContext("2d", {
401
- willReadFrequently: true
402
- });
416
+ const ctx = getReadableCanvasContext(canvas);
403
417
  if (!ctx) return true;
404
418
  const chunkSize = 50;
405
419
  for (let x2 = 0; x2 < canvas.width; x2 += chunkSize) {
406
420
  for (let y = 0; y < canvas.height; y += chunkSize) {
407
421
  const getImageData = ctx.getImageData;
408
422
  const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
409
- console.log("Calling getImageData on ctx:", ctx);
410
- console.trace();
411
423
  const pixelBuffer = new Uint32Array(
412
424
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
413
425
  originalGetImageData.call(