1
- import { getCanvasManager } from '@sentry-internal/rrweb' ;
1
+ import { getCanvasManager , _getCanvasManager } from '@sentry-internal/rrweb' ;
2
2
import 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' ;
4
5
5
6
interface 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 ;
8
17
}
9
18
10
19
/** An integration to add canvas recording to replay. */
@@ -19,16 +28,20 @@ export class ReplayCanvas implements Integration {
19
28
*/
20
29
public name : string ;
21
30
31
+ public canvasManager : ( options : GetCanvasManagerOptions ) => CanvasManagerInterface ;
32
+
22
33
private _canvasOptions : ReplayCanvasOptions ;
23
34
24
35
public constructor ( ) {
25
36
this . name = ReplayCanvas . id ;
26
37
// TODO FN: Allow to configure this
27
38
// But since we haven't finalized how to configure this, this is predefined for now
28
39
// to avoid breaking changes
40
+ this . canvasManager = getCanvasManager ;
29
41
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 ,
32
45
} ;
33
46
}
34
47
@@ -46,9 +59,32 @@ export class ReplayCanvas implements Integration {
46
59
_experiments : {
47
60
canvas : {
48
61
...this . _canvasOptions ,
49
- manager : getCanvasManager ,
62
+ manager : opts =>
63
+ this . canvasManager ( {
64
+ ...opts ,
65
+ manualSnapshot : this . _canvasOptions . manualSnapshot ,
66
+ } ) ,
50
67
} ,
51
68
} ,
52
69
} ;
53
70
}
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
+ }
54
90
}
0 commit comments