1- import { getCanvasManager } from '@sentry-internal/rrweb' ;
1+ import { getCanvasManager , _getCanvasManager } from '@sentry-internal/rrweb' ;
22import type { Integration } from '@sentry/types' ;
3- import type { ReplayConfiguration } from './types' ;
3+ import type { CanvasManagerInterface , GetCanvasManagerOptions , ReplayConfiguration } from './types' ;
4+ import { CANVAS_QUALITY } from './constants' ;
45
56interface ReplayCanvasOptions {
6- fps : number ;
7- quality : number ;
7+ canvasQuality : {
8+ sampling : {
9+ canvas : number ;
10+ } ;
11+ dataURLOptions : {
12+ type : string ;
13+ quality : number ;
14+ } ;
15+ } ;
16+ manualSnapshot ?: boolean ;
817}
918
1019/** An integration to add canvas recording to replay. */
@@ -19,16 +28,20 @@ export class ReplayCanvas implements Integration {
1928 */
2029 public name : string ;
2130
31+ public canvasManager : ( options : GetCanvasManagerOptions ) => CanvasManagerInterface ;
32+
2233 private _canvasOptions : ReplayCanvasOptions ;
2334
2435 public constructor ( ) {
2536 this . name = ReplayCanvas . id ;
2637 // TODO FN: Allow to configure this
2738 // But since we haven't finalized how to configure this, this is predefined for now
2839 // to avoid breaking changes
40+ this . canvasManager = getCanvasManager ;
2941 this . _canvasOptions = {
30- fps : 4 ,
31- quality : 0.6 ,
42+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
43+ canvasQuality : CANVAS_QUALITY . medium ,
44+ manualSnapshot : true ,
3245 } ;
3346 }
3447
@@ -46,9 +59,32 @@ export class ReplayCanvas implements Integration {
4659 _experiments : {
4760 canvas : {
4861 ...this . _canvasOptions ,
49- manager : getCanvasManager ,
62+ manager : opts =>
63+ this . canvasManager ( {
64+ ...opts ,
65+ manualSnapshot : this . _canvasOptions . manualSnapshot ,
66+ } ) ,
5067 } ,
5168 } ,
5269 } ;
5370 }
71+
72+ /**
73+ * Take manual snapshot of canvas
74+ */
75+ public snapshotCanvas ( canvasElement ?: HTMLCanvasElement ) : void {
76+ const canvasManager : CanvasManagerInterface = _getCanvasManager ( this . canvasManager , {
77+ recordCanvas : true ,
78+ blockClass : '' ,
79+ blockSelector : null ,
80+ unblockSelector : null ,
81+ dataURLOptions : this . _canvasOptions . canvasQuality . dataURLOptions ,
82+ } ) ;
83+
84+ return canvasManager . snapshot (
85+ this . _canvasOptions . canvasQuality . dataURLOptions ,
86+ this . _canvasOptions . canvasQuality . sampling . canvas ,
87+ canvasElement ,
88+ ) ;
89+ }
5490}
0 commit comments