Skip to content

Commit 4a53465

Browse files
committed
feat(replay): Add option to skip requestAnimationFrame for canvas snapshots
This adds an option to `snapshot()` to skip `requestAnimationFrame` when manually snapshotting.
1 parent 93d9b09 commit 4a53465

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

packages/replay-canvas/src/canvas.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import { defineIntegration } from '@sentry/core';
33
import type { CanvasManagerInterface, CanvasManagerOptions } from '@sentry-internal/replay';
44
import { CanvasManager } from '@sentry-internal/rrweb';
55

6+
interface SnapshotOptions {
7+
skipRequestAnimationFrame?: boolean;
8+
}
9+
610
interface ReplayCanvasIntegration extends Integration {
7-
snapshot: (canvasElement?: HTMLCanvasElement) => Promise<void>;
11+
snapshot: (canvasElement?: HTMLCanvasElement, options?: SnapshotOptions) => Promise<void>;
812
}
913

1014
interface ReplayCanvasOptions {
@@ -106,9 +110,29 @@ export const _replayCanvasIntegration = ((options: Partial<ReplayCanvasOptions>
106110
...(CANVAS_QUALITY[quality || 'medium'] || CANVAS_QUALITY.medium),
107111
};
108112
},
109-
async snapshot(canvasElement?: HTMLCanvasElement) {
113+
async snapshot(canvasElement?: HTMLCanvasElement, options?: SnapshotOptions) {
110114
const canvasManager = await _canvasManager;
111-
canvasManager.snapshot(canvasElement);
115+
116+
canvasManager.snapshot(canvasElement, options);
117+
// createImageBitmap(canvasElement).then(async imageBitmap => {
118+
// // debug
119+
// const canvas = document.getElementById('test');
120+
// canvas.height = imageBitmap.height;
121+
// canvas.width = imageBitmap.width;
122+
// // temp1.getContext("2d").drawImage(bitmap, 0, 0);
123+
// // const canvas = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
124+
// const ctx = canvas.getContext('2d');
125+
//
126+
// // Draw the ImageBitmap onto the canvas
127+
// ctx.drawImage(imageBitmap, 0, 0);
128+
//
129+
// // Convert the canvas content to a data URL (Base64 encoded PNG by default)
130+
// const dataURL = await canvas.toDataURL('image/webp'); // Specify format if needed
131+
//
132+
// console.log(dataURL);
133+
// canvasManager.snapshotBitmap(canvasElement, imageBitmap);
134+
// imageBitmap.close();
135+
// });
112136
},
113137
};
114138
}) satisfies IntegrationFn<ReplayCanvasIntegration>;

0 commit comments

Comments
 (0)