1
1
/* eslint-disable max-lines */
2
2
import { Measurements } from '@sentry/types' ;
3
- import { browserPerformanceTimeOrigin , getGlobalObject , htmlTreeAsString , logger } from '@sentry/utils' ;
3
+ import { browserPerformanceTimeOrigin , htmlTreeAsString , logger , WINDOW } from '@sentry/utils' ;
4
4
5
5
import { IdleTransaction } from '../../idletransaction' ;
6
6
import { Transaction } from '../../transaction' ;
@@ -13,10 +13,8 @@ import { observe, PerformanceEntryHandler } from '../web-vitals/lib/observe';
13
13
import { NavigatorDeviceMemory , NavigatorNetworkInformation } from '../web-vitals/types' ;
14
14
import { _startChild , isMeasurementValue } from './utils' ;
15
15
16
- const global = getGlobalObject < Window > ( ) ;
17
-
18
16
function getBrowserPerformanceAPI ( ) : Performance | undefined {
19
- return global && global . addEventListener && global . performance ;
17
+ return WINDOW && WINDOW . addEventListener && WINDOW . performance ;
20
18
}
21
19
22
20
let _performanceCursor : number = 0 ;
@@ -32,7 +30,7 @@ export function startTrackingWebVitals(reportAllChanges: boolean = false): void
32
30
const performance = getBrowserPerformanceAPI ( ) ;
33
31
if ( performance && browserPerformanceTimeOrigin ) {
34
32
if ( performance . mark ) {
35
- global . performance . mark ( 'sentry-tracing-init' ) ;
33
+ WINDOW . performance . mark ( 'sentry-tracing-init' ) ;
36
34
}
37
35
_trackCLS ( ) ;
38
36
_trackLCP ( reportAllChanges ) ;
@@ -112,7 +110,7 @@ function _trackFID(): void {
112
110
/** Add performance related spans to a transaction */
113
111
export function addPerformanceEntries ( transaction : Transaction ) : void {
114
112
const performance = getBrowserPerformanceAPI ( ) ;
115
- if ( ! performance || ! global . performance . getEntries || ! browserPerformanceTimeOrigin ) {
113
+ if ( ! performance || ! WINDOW . performance . getEntries || ! browserPerformanceTimeOrigin ) {
116
114
// Gatekeeper if performance API not available
117
115
return ;
118
116
}
@@ -162,7 +160,7 @@ export function addPerformanceEntries(transaction: Transaction): void {
162
160
break ;
163
161
}
164
162
case 'resource' : {
165
- const resourceName = ( entry . name as string ) . replace ( global . location . origin , '' ) ;
163
+ const resourceName = ( entry . name as string ) . replace ( WINDOW . location . origin , '' ) ;
166
164
_addResourceSpans ( transaction , entry , resourceName , startTime , duration , timeOrigin ) ;
167
165
break ;
168
166
}
@@ -376,7 +374,7 @@ export function _addResourceSpans(
376
374
* Capture the information of the user agent.
377
375
*/
378
376
function _trackNavigator ( transaction : Transaction ) : void {
379
- const navigator = global . navigator as null | ( Navigator & NavigatorNetworkInformation & NavigatorDeviceMemory ) ;
377
+ const navigator = WINDOW . navigator as null | ( Navigator & NavigatorNetworkInformation & NavigatorDeviceMemory ) ;
380
378
if ( ! navigator ) {
381
379
return ;
382
380
}
0 commit comments