@glimt/record 0.0.13 → 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.
package/dist/record.cjs CHANGED
@@ -363,10 +363,25 @@ function toLowerCase(str) {
363
363
  return str.toLowerCase();
364
364
  }
365
365
  const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
366
+ const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
367
+ function getReadableCanvasContext(canvas) {
368
+ if (canvas.width === 0 || canvas.height === 0) return canvas.getContext("2d");
369
+ if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
370
+ return canvas.getContext("2d");
371
+ console.log(
372
+ "detected large canvas, copying to offscreen canvas for willReadFrequently"
373
+ );
374
+ const offscreen = document.createElement("canvas");
375
+ offscreen.width = canvas.width;
376
+ offscreen.height = canvas.height;
377
+ const ctx = offscreen.getContext("2d");
378
+ if (ctx) {
379
+ ctx.drawImage(canvas, 0, 0);
380
+ }
381
+ return offscreen.getContext("2d", { willReadFrequently: true });
382
+ }
366
383
  function is2DCanvasBlank(canvas) {
367
- const ctx = canvas.getContext("2d", {
368
- willReadFrequently: true
369
- });
384
+ const ctx = getReadableCanvasContext(canvas);
370
385
  if (!ctx) return true;
371
386
  const chunkSize = 50;
372
387
  for (let x2 = 0; x2 < canvas.width; x2 += chunkSize) {