@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.
package/dist/record.js CHANGED
@@ -361,19 +361,31 @@ function toLowerCase(str) {
361
361
  return str.toLowerCase();
362
362
  }
363
363
  const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
364
+ const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
365
+ function getReadableCanvasContext(canvas) {
366
+ if (canvas.width === 0 || canvas.height === 0) return canvas.getContext("2d");
367
+ if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
368
+ return canvas.getContext("2d");
369
+ console.log(
370
+ "detected large canvas, copying to offscreen canvas for willReadFrequently"
371
+ );
372
+ const offscreen = document.createElement("canvas");
373
+ offscreen.width = canvas.width;
374
+ offscreen.height = canvas.height;
375
+ const ctx = offscreen.getContext("2d");
376
+ if (ctx) {
377
+ ctx.drawImage(canvas, 0, 0);
378
+ }
379
+ return offscreen.getContext("2d", { willReadFrequently: true });
380
+ }
364
381
  function is2DCanvasBlank(canvas) {
365
- console.log("Creating context with willReadFrequently:", canvas);
366
- const ctx = canvas.getContext("2d", {
367
- willReadFrequently: true
368
- });
382
+ const ctx = getReadableCanvasContext(canvas);
369
383
  if (!ctx) return true;
370
384
  const chunkSize = 50;
371
385
  for (let x2 = 0; x2 < canvas.width; x2 += chunkSize) {
372
386
  for (let y = 0; y < canvas.height; y += chunkSize) {
373
387
  const getImageData = ctx.getImageData;
374
388
  const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
375
- console.log("Calling getImageData on ctx:", ctx);
376
- console.trace();
377
389
  const pixelBuffer = new Uint32Array(
378
390
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
379
391
  originalGetImageData.call(