11/* eslint-disable @typescript-eslint/no-explicit-any */
22/* eslint-disable @typescript-eslint/no-unsafe-member-access */
33import { 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' ;
55import localForage from 'localforage' ;
66
77type LocalForage = {
@@ -30,12 +30,6 @@ export class Offline implements Integration {
3030 */
3131 public readonly name : string = Offline . id ;
3232
33- /**
34- * the global instance
35- */
36- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37- public global : any ;
38-
3933 /**
4034 * the current hub instance
4135 */
@@ -55,8 +49,6 @@ export class Offline implements Integration {
5549 * @inheritDoc
5650 */
5751 public constructor ( options : { maxStoredEvents ?: number } = { } ) {
58- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59- this . global = getGlobalObject < any > ( ) ;
6052 this . maxStoredEvents = options . maxStoredEvents || 30 ; // set a reasonable default
6153 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6254 this . offlineEventStore = localForage . createInstance ( {
@@ -70,8 +62,8 @@ export class Offline implements Integration {
7062 public setupOnce ( addGlobalEventProcessor : ( callback : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
7163 this . hub = getCurrentHub ( ) ;
7264
73- if ( 'addEventListener' in this . global ) {
74- this . global . addEventListener ( 'online' , ( ) => {
65+ if ( 'addEventListener' in WINDOW ) {
66+ WINDOW . addEventListener ( 'online' , ( ) => {
7567 void this . _sendEvents ( ) . catch ( ( ) => {
7668 __DEBUG_BUILD__ && logger . warn ( 'could not send cached events' ) ;
7769 } ) ;
@@ -81,7 +73,7 @@ export class Offline implements Integration {
8173 const eventProcessor : EventProcessor = event => {
8274 if ( this . hub && this . hub . getIntegration ( Offline ) ) {
8375 // 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 ) {
8577 __DEBUG_BUILD__ && logger . log ( 'Event dropped due to being a offline - caching instead' ) ;
8678
8779 void this . _cacheEvent ( event )
@@ -102,7 +94,7 @@ export class Offline implements Integration {
10294 addGlobalEventProcessor ( eventProcessor ) ;
10395
10496 // 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 ) {
10698 void this . _sendEvents ( ) . catch ( ( ) => {
10799 __DEBUG_BUILD__ && logger . warn ( 'could not send cached events' ) ;
108100 } ) ;
0 commit comments