7
7
8
8
import { Integration } from '@sentry/types' ;
9
9
10
- /** Internal */
11
- interface SentryGlobal {
10
+ /** An object representing properties that can be found on all globals */
11
+ interface GlobalObject {
12
+ navigator ?: Navigator ;
13
+ }
14
+
15
+ /** Internal Sentry extensions on global */
16
+ interface SentryGlobal extends GlobalObject {
12
17
Sentry ?: {
13
18
Integrations ?: Integration [ ] ;
14
19
} ;
@@ -24,7 +29,7 @@ interface SentryGlobal {
24
29
} ;
25
30
}
26
31
27
- // The code below for 'isGlobalObj' and 'GLOBAL ' was copied from core-js before modification
32
+ // The code below for 'isGlobalObj' and 'GLOBAL_OBJ ' was copied from core-js before modification
28
33
// https://github.com/zloirock/core-js/blob/1b944df55282cdc99c90db5f49eb0b6eda2cc0a3/packages/core-js/internals/global.js
29
34
// core-js has the following licence:
30
35
//
@@ -53,7 +58,7 @@ function isGlobalObj(obj: { Math?: Math }): any | undefined {
53
58
return obj && obj . Math == Math ? obj : undefined ;
54
59
}
55
60
56
- const GLOBAL =
61
+ export const GLOBAL_OBJ : SentryGlobal =
57
62
( typeof globalThis == 'object' && isGlobalObj ( globalThis ) ) ||
58
63
// eslint-disable-next-line no-restricted-globals
59
64
( typeof window == 'object' && isGlobalObj ( window ) ) ||
@@ -70,7 +75,7 @@ const GLOBAL =
70
75
* @returns Global scope object
71
76
*/
72
77
export function getGlobalObject < T > ( ) : T & SentryGlobal {
73
- return GLOBAL as T & SentryGlobal ;
78
+ return GLOBAL_OBJ as T & SentryGlobal ;
74
79
}
75
80
76
81
/**
@@ -85,7 +90,7 @@ export function getGlobalObject<T>(): T & SentryGlobal {
85
90
* @returns the singleton
86
91
*/
87
92
export function getGlobalSingleton < T > ( name : keyof SentryGlobal [ '__SENTRY__' ] , creator : ( ) => T , obj ?: unknown ) : T {
88
- const global = ( obj || GLOBAL ) as SentryGlobal ;
93
+ const global = ( obj || GLOBAL_OBJ ) as SentryGlobal ;
89
94
const __SENTRY__ = ( global . __SENTRY__ = global . __SENTRY__ || { } ) ;
90
95
const singleton = __SENTRY__ [ name ] || ( __SENTRY__ [ name ] = creator ( ) ) ;
91
96
return singleton ;
0 commit comments