File tree Expand file tree Collapse file tree 4 files changed +18
-2
lines changed Expand file tree Collapse file tree 4 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ Some common patterns may emit lots of events are:
21
21
22
22
## Sampling
23
23
24
- Use the sampling config in the recording can reduce the storage size by dropping some events:
24
+ Use the sampling config in the recording can reduce the storage size by dropping or merging some events:
25
25
26
26
** Scenario 1**
27
27
@@ -35,6 +35,8 @@ rrweb.record({
35
35
mouseInteraction: false
36
36
// set the interval of scrolling event
37
37
scroll: 150 // do not emit twice in 150ms
38
+ // set the interval of mutation events (page changes)
39
+ mutation: 50 // do not emit more than 20 mutations per second
38
40
// set the interval of media interaction event
39
41
media: 800
40
42
// set the timing of record input
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import {
31
31
inDom ,
32
32
getShadowHost ,
33
33
closestElementOfNode ,
34
+ throttle ,
34
35
} from '../utils' ;
35
36
import dom from '@deepprediction/rrweb-utils' ;
36
37
@@ -184,6 +185,7 @@ export default class MutationBuffer {
184
185
private recordCanvas : observerParam [ 'recordCanvas' ] ;
185
186
private inlineImages : observerParam [ 'inlineImages' ] ;
186
187
private slimDOMOptions : observerParam [ 'slimDOMOptions' ] ;
188
+ private sampling : observerParam [ 'sampling' ] ;
187
189
private dataURLOptions : observerParam [ 'dataURLOptions' ] ;
188
190
private doc : observerParam [ 'doc' ] ;
189
191
private mirror : observerParam [ 'mirror' ] ;
@@ -210,6 +212,7 @@ export default class MutationBuffer {
210
212
'recordCanvas' ,
211
213
'inlineImages' ,
212
214
'slimDOMOptions' ,
215
+ 'sampling' ,
213
216
'dataURLOptions' ,
214
217
'doc' ,
215
218
'mirror' ,
@@ -223,6 +226,10 @@ export default class MutationBuffer {
223
226
// just a type trick, the runtime result is correct
224
227
this [ key ] = options [ key ] as never ;
225
228
} ) ;
229
+
230
+ if ( this . sampling . mutation ) {
231
+ this . emit = throttle ( this . emit , this . sampling . mutation ) ;
232
+ }
226
233
}
227
234
228
235
public freeze ( ) {
Original file line number Diff line number Diff line change @@ -143,6 +143,7 @@ export type MutationBufferParam = Pick<
143
143
| 'recordCanvas'
144
144
| 'inlineImages'
145
145
| 'slimDOMOptions'
146
+ | 'sampling'
146
147
| 'dataURLOptions'
147
148
| 'doc'
148
149
| 'mirror'
Original file line number Diff line number Diff line change @@ -201,9 +201,15 @@ export type SamplingStrategy = Partial<{
201
201
*/
202
202
mouseInteraction : boolean | Record < string , boolean | undefined > ;
203
203
/**
204
- * number is the throttle threshold of recording scroll
204
+ * number is the throttle threshold of recording scroll in ms
205
+ * default: 100
205
206
*/
206
207
scroll : number ;
208
+ /**
209
+ * number is the throttle threshold of mutation emission in ms
210
+ * off by default
211
+ */
212
+ mutation : number ;
207
213
/**
208
214
* number is the throttle threshold of recording media interactions
209
215
*/
You can’t perform that action at this time.
0 commit comments