1616 */
1717
1818import { FirebaseNamespace } from './public-types' ;
19- import { isBrowser } from '@firebase/util' ;
19+ import { getGlobal } from '@firebase/util' ;
2020import { firebase as firebaseNamespace } from './firebaseNamespace' ;
2121import { logger } from './logger' ;
2222import { registerCoreComponents } from './registerCoreComponents' ;
@@ -27,22 +27,28 @@ declare global {
2727 }
2828}
2929
30- // Firebase Lite detection
31- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32- if ( isBrowser ( ) && window . firebase !== undefined ) {
33- logger . warn ( `
34- Warning: Firebase is already defined in the global scope. Please make sure
35- Firebase library is only loaded once.
36- ` ) ;
37-
38- // eslint-disable-next-line
39- const sdkVersion = ( window . firebase as FirebaseNamespace ) . SDK_VERSION ;
40- if ( sdkVersion && sdkVersion . indexOf ( 'LITE' ) >= 0 ) {
30+ try {
31+ const globals = getGlobal ( ) ;
32+ // Firebase Lite detection
33+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34+ if ( ( globals as any ) . firebase !== undefined ) {
4135 logger . warn ( `
42- Warning: You are trying to load Firebase while using Firebase Performance standalone script.
43- You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code .
36+ Warning: Firebase is already defined in the global scope. Please make sure
37+ Firebase library is only loaded once .
4438 ` ) ;
39+
40+ // eslint-disable-next-line
41+ const sdkVersion = ( ( globals as any ) . firebase as FirebaseNamespace )
42+ . SDK_VERSION ;
43+ if ( sdkVersion && sdkVersion . indexOf ( 'LITE' ) >= 0 ) {
44+ logger . warn ( `
45+ Warning: You are trying to load Firebase while using Firebase Performance standalone script.
46+ You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.
47+ ` ) ;
48+ }
4549 }
50+ } catch {
51+ // ignore errors thrown by getGlobal
4652}
4753
4854const firebase = firebaseNamespace ;
0 commit comments