1717
1818import { getDebugState } from './state' ;
1919import { readOrCreateDebugTokenFromStorage } from './storage' ;
20- import { Deferred } from '@firebase/util' ;
20+ import { Deferred , getGlobal } from '@firebase/util' ;
2121
2222declare global {
23- interface Window {
24- /**
25- * When it is a string, we treat it as the debug token and give it to consumers as the app check token
26- * When it is `true`, we will try to read the debug token from the indexeddb,
27- * if it doesn't exist, create one, print it to console, and ask developers to register it in the Firebase console.
28- * When it is `undefined`, `false` or any unsupported value type, the SDK will operate in production mode
29- */
30- FIREBASE_APPCHECK_DEBUG_TOKEN ?: boolean | string ;
31- }
23+ // var must be used for global scopes
24+ // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#type-checking-for-globalthis
25+ // eslint-disable-next-line no-var
26+ var FIREBASE_APPCHECK_DEBUG_TOKEN : boolean | string | undefined ;
3227}
3328
3429export function isDebugMode ( ) : boolean {
@@ -50,9 +45,10 @@ export async function getDebugToken(): Promise<string> {
5045}
5146
5247export function initializeDebugMode ( ) : void {
48+ const globals = getGlobal ( ) ;
5349 if (
54- typeof self . FIREBASE_APPCHECK_DEBUG_TOKEN !== 'string' &&
55- self . FIREBASE_APPCHECK_DEBUG_TOKEN !== true
50+ typeof globals . FIREBASE_APPCHECK_DEBUG_TOKEN !== 'string' &&
51+ globals . FIREBASE_APPCHECK_DEBUG_TOKEN !== true
5652 ) {
5753 return ;
5854 }
@@ -62,8 +58,8 @@ export function initializeDebugMode(): void {
6258 const deferredToken = new Deferred < string > ( ) ;
6359 debugState . token = deferredToken ;
6460
65- if ( typeof self . FIREBASE_APPCHECK_DEBUG_TOKEN === 'string' ) {
66- deferredToken . resolve ( self . FIREBASE_APPCHECK_DEBUG_TOKEN ) ;
61+ if ( typeof globals . FIREBASE_APPCHECK_DEBUG_TOKEN === 'string' ) {
62+ deferredToken . resolve ( globals . FIREBASE_APPCHECK_DEBUG_TOKEN ) ;
6763 } else {
6864 deferredToken . resolve ( readOrCreateDebugTokenFromStorage ( ) ) ;
6965 }
0 commit comments