1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
2
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
3
import { Event , EventProcessor , Hub , Integration } from '@sentry/types' ;
4
- import { getGlobalObject , logger , normalize , uuid4 } from '@sentry/utils' ;
4
+ import { logger , normalize , uuid4 , WINDOW } from '@sentry/utils' ;
5
5
import localForage from 'localforage' ;
6
6
7
7
type LocalForage = {
@@ -30,12 +30,6 @@ export class Offline implements Integration {
30
30
*/
31
31
public readonly name : string = Offline . id ;
32
32
33
- /**
34
- * the global instance
35
- */
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- public global : any ;
38
-
39
33
/**
40
34
* the current hub instance
41
35
*/
@@ -55,8 +49,6 @@ export class Offline implements Integration {
55
49
* @inheritDoc
56
50
*/
57
51
public constructor ( options : { maxStoredEvents ?: number } = { } ) {
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- this . global = getGlobalObject < any > ( ) ;
60
52
this . maxStoredEvents = options . maxStoredEvents || 30 ; // set a reasonable default
61
53
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
62
54
this . offlineEventStore = localForage . createInstance ( {
@@ -70,8 +62,8 @@ export class Offline implements Integration {
70
62
public setupOnce ( addGlobalEventProcessor : ( callback : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
71
63
this . hub = getCurrentHub ( ) ;
72
64
73
- if ( 'addEventListener' in this . global ) {
74
- this . global . addEventListener ( 'online' , ( ) => {
65
+ if ( 'addEventListener' in WINDOW ) {
66
+ WINDOW . addEventListener ( 'online' , ( ) => {
75
67
void this . _sendEvents ( ) . catch ( ( ) => {
76
68
__DEBUG_BUILD__ && logger . warn ( 'could not send cached events' ) ;
77
69
} ) ;
@@ -81,7 +73,7 @@ export class Offline implements Integration {
81
73
const eventProcessor : EventProcessor = event => {
82
74
if ( this . hub && this . hub . getIntegration ( Offline ) ) {
83
75
// cache if we are positively offline
84
- if ( 'navigator' in this . global && 'onLine' in this . global . navigator && ! this . global . navigator . onLine ) {
76
+ if ( 'navigator' in WINDOW && 'onLine' in WINDOW . navigator && ! WINDOW . navigator . onLine ) {
85
77
__DEBUG_BUILD__ && logger . log ( 'Event dropped due to being a offline - caching instead' ) ;
86
78
87
79
void this . _cacheEvent ( event )
@@ -102,7 +94,7 @@ export class Offline implements Integration {
102
94
addGlobalEventProcessor ( eventProcessor ) ;
103
95
104
96
// if online now, send any events stored in a previous offline session
105
- if ( 'navigator' in this . global && 'onLine' in this . global . navigator && this . global . navigator . onLine ) {
97
+ if ( 'navigator' in WINDOW && 'onLine' in WINDOW . navigator && WINDOW . navigator . onLine ) {
106
98
void this . _sendEvents ( ) . catch ( ( ) => {
107
99
__DEBUG_BUILD__ && logger . warn ( 'could not send cached events' ) ;
108
100
} ) ;
0 commit comments