@@ -58,13 +58,14 @@ declare global {
58
58
const __RRWEB_EXCLUDE_IFRAME__ : boolean ;
59
59
}
60
60
61
- let wrappedEmit ! : ( e : eventWithTime , isCheckout ?: boolean ) => void ;
61
+ // These are stored in module scope because we access them in other exported methods
62
+ let _wrappedEmit :
63
+ | undefined
64
+ | ( ( e : eventWithoutTime , isCheckout ?: boolean ) => void ) ;
65
+ let _takeFullSnapshot : undefined | ( ( isCheckout ?: boolean ) => void ) ;
62
66
63
- let takeFullSnapshot ! : ( isCheckout ?: boolean ) => void ;
64
- let canvasManager : CanvasManagerInterface ;
65
- let recording = false ;
67
+ export const mirror = createMirror ( ) ;
66
68
67
- const mirror = createMirror ( ) ;
68
69
function record < T = eventWithTime > (
69
70
options : recordOptions < T > = { } ,
70
71
) : listenerHandler | undefined {
@@ -200,7 +201,7 @@ function record<T = eventWithTime>(
200
201
}
201
202
return e as unknown as T ;
202
203
} ;
203
- wrappedEmit = ( r : eventWithoutTime , isCheckout ?: boolean ) => {
204
+ const wrappedEmit = ( r : eventWithoutTime , isCheckout ?: boolean ) => {
204
205
const e = r as eventWithTime ;
205
206
e . timestamp = nowTimestamp ( ) ;
206
207
if (
@@ -251,6 +252,7 @@ function record<T = eventWithTime>(
251
252
}
252
253
}
253
254
} ;
255
+ _wrappedEmit = wrappedEmit ;
254
256
255
257
const wrappedMutationEmit = ( m : mutationCallbackParam ) => {
256
258
wrappedEmit ( {
@@ -310,7 +312,7 @@ function record<T = eventWithTime>(
310
312
311
313
const processedNodeManager = new ProcessedNodeManager ( ) ;
312
314
313
- canvasManager =
315
+ const canvasManager : CanvasManagerInterface =
314
316
typeof __RRWEB_EXCLUDE_CANVAS__ === 'boolean' && __RRWEB_EXCLUDE_CANVAS__
315
317
? new CanvasManagerNoop ( )
316
318
: new CanvasManager ( {
@@ -361,7 +363,7 @@ function record<T = eventWithTime>(
361
363
mirror,
362
364
} ) ;
363
365
364
- takeFullSnapshot = ( isCheckout = false ) => {
366
+ const takeFullSnapshot = ( isCheckout = false ) => {
365
367
if ( ! recordDOM ) {
366
368
return ;
367
369
}
@@ -446,6 +448,7 @@ function record<T = eventWithTime>(
446
448
mirror . getId ( document ) ,
447
449
) ;
448
450
} ;
451
+ _takeFullSnapshot = takeFullSnapshot ;
449
452
450
453
try {
451
454
const handlers : listenerHandler [ ] = [ ] ;
@@ -589,7 +592,6 @@ function record<T = eventWithTime>(
589
592
const init = ( ) => {
590
593
takeFullSnapshot ( ) ;
591
594
handlers . push ( observe ( document ) ) ;
592
- recording = true ;
593
595
} ;
594
596
if (
595
597
document . readyState === 'interactive' ||
@@ -623,7 +625,7 @@ function record<T = eventWithTime>(
623
625
return ( ) => {
624
626
handlers . forEach ( ( h ) => h ( ) ) ;
625
627
processedNodeManager . destroy ( ) ;
626
- recording = false ;
628
+ _takeFullSnapshot = undefined ;
627
629
unregisterErrorHandler ( ) ;
628
630
} ;
629
631
} catch ( error ) {
@@ -632,30 +634,35 @@ function record<T = eventWithTime>(
632
634
}
633
635
}
634
636
635
- record . addCustomEvent = < T > ( tag : string , payload : T ) => {
636
- if ( ! recording ) {
637
+ export function addCustomEvent < T > ( tag : string , payload : T ) {
638
+ if ( ! _wrappedEmit ) {
637
639
throw new Error ( 'please add custom event after start recording' ) ;
638
640
}
639
- wrappedEmit ( {
641
+ _wrappedEmit ( {
640
642
type : EventType . Custom ,
641
643
data : {
642
644
tag,
643
645
payload,
644
646
} ,
645
647
} ) ;
646
- } ;
648
+ }
647
649
648
- record . freezePage = ( ) => {
650
+ export function freezePage ( ) {
649
651
mutationBuffers . forEach ( ( buf ) => buf . freeze ( ) ) ;
650
- } ;
652
+ }
651
653
652
- record . takeFullSnapshot = ( isCheckout ?: boolean ) => {
653
- if ( ! recording ) {
654
+ export function takeFullSnapshot ( isCheckout ?: boolean ) {
655
+ if ( ! _takeFullSnapshot ) {
654
656
throw new Error ( 'please take full snapshot after start recording' ) ;
655
657
}
656
- takeFullSnapshot ( isCheckout ) ;
657
- } ;
658
+ _takeFullSnapshot ( isCheckout ) ;
659
+ }
660
+
661
+ // record.addCustomEvent is removed because Sentry Session Replay does not use it
662
+ // record.freezePage is removed because Sentry Session Replay does not use it
658
663
664
+ // For backwards compatibility - we can eventually remove this when we migrated to using the exported `mirror` & `takeFullSnapshot`
659
665
record . mirror = mirror ;
666
+ record . takeFullSnapshot = takeFullSnapshot ;
660
667
661
668
export default record ;
0 commit comments