1
1
/* eslint-disable max-lines */ // TODO: We might want to split this file up
2
+ import { WINDOW } from '@sentry/browser' ;
2
3
import { addGlobalEventProcessor , getCurrentHub , Scope , setContext } from '@sentry/core' ;
3
4
import { Breadcrumb , Client , Event , Integration } from '@sentry/types' ;
4
5
import { addInstrumentationHandler , createEnvelope , logger } from '@sentry/utils' ;
@@ -232,7 +233,7 @@ export class Replay implements Integration {
232
233
return ;
233
234
}
234
235
// XXX: See method comments above
235
- window . setTimeout ( ( ) => this . start ( ) ) ;
236
+ setTimeout ( ( ) => this . start ( ) ) ;
236
237
}
237
238
238
239
/**
@@ -396,8 +397,8 @@ export class Replay implements Integration {
396
397
* first flush.
397
398
*/
398
399
setInitialState ( ) : void {
399
- const urlPath = `${ window . location . pathname } ${ window . location . hash } ${ window . location . search } ` ;
400
- const url = `${ window . location . origin } ${ urlPath } ` ;
400
+ const urlPath = `${ WINDOW . location . pathname } ${ WINDOW . location . hash } ${ WINDOW . location . search } ` ;
401
+ const url = `${ WINDOW . location . origin } ${ urlPath } ` ;
401
402
402
403
this . performanceEvents = [ ] ;
403
404
@@ -414,9 +415,9 @@ export class Replay implements Integration {
414
415
*/
415
416
addListeners ( ) : void {
416
417
try {
417
- document . addEventListener ( 'visibilitychange' , this . handleVisibilityChange ) ;
418
- window . addEventListener ( 'blur' , this . handleWindowBlur ) ;
419
- window . addEventListener ( 'focus' , this . handleWindowFocus ) ;
418
+ WINDOW . document . addEventListener ( 'visibilitychange' , this . handleVisibilityChange ) ;
419
+ WINDOW . addEventListener ( 'blur' , this . handleWindowBlur ) ;
420
+ WINDOW . addEventListener ( 'focus' , this . handleWindowFocus ) ;
420
421
421
422
// There is no way to remove these listeners, so ensure they are only added once
422
423
if ( ! this . hasInitializedCoreListeners ) {
@@ -440,7 +441,7 @@ export class Replay implements Integration {
440
441
}
441
442
442
443
// PerformanceObserver //
443
- if ( ! ( 'PerformanceObserver' in window ) ) {
444
+ if ( ! ( 'PerformanceObserver' in WINDOW ) ) {
444
445
return ;
445
446
}
446
447
@@ -475,10 +476,10 @@ export class Replay implements Integration {
475
476
*/
476
477
removeListeners ( ) : void {
477
478
try {
478
- document . removeEventListener ( 'visibilitychange' , this . handleVisibilityChange ) ;
479
+ WINDOW . document . removeEventListener ( 'visibilitychange' , this . handleVisibilityChange ) ;
479
480
480
- window . removeEventListener ( 'blur' , this . handleWindowBlur ) ;
481
- window . removeEventListener ( 'focus' , this . handleWindowFocus ) ;
481
+ WINDOW . removeEventListener ( 'blur' , this . handleWindowBlur ) ;
482
+ WINDOW . removeEventListener ( 'focus' , this . handleWindowFocus ) ;
482
483
483
484
if ( this . performanceObserver ) {
484
485
this . performanceObserver . disconnect ( ) ;
@@ -665,7 +666,7 @@ export class Replay implements Integration {
665
666
* page will also trigger a change to a hidden state.
666
667
*/
667
668
handleVisibilityChange : ( ) => void = ( ) => {
668
- if ( document . visibilityState === 'visible' ) {
669
+ if ( WINDOW . document . visibilityState === 'visible' ) {
669
670
this . doChangeToForegroundTasks ( ) ;
670
671
} else {
671
672
this . doChangeToBackgroundTasks ( ) ;
@@ -980,13 +981,13 @@ export class Replay implements Integration {
980
981
addMemoryEntry ( ) : Promise < void [ ] > | undefined {
981
982
// window.performance.memory is a non-standard API and doesn't work on all browsers
982
983
// so we check before creating the event.
983
- if ( ! ( 'memory' in window . performance ) ) {
984
+ if ( ! ( 'memory' in WINDOW . performance ) ) {
984
985
return ;
985
986
}
986
987
987
988
return this . createPerformanceSpans ( [
988
989
// @ts -ignore memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
989
- createMemoryEntry ( window . performance . memory ) ,
990
+ createMemoryEntry ( WINDOW . performance . memory ) ,
990
991
] ) ;
991
992
}
992
993
0 commit comments