File tree 4 files changed +34
-3
lines changed
4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @firebase/util ' : patch
3
+ ---
4
+
5
+ fix: browser detection (detect either window or web worker)
Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @firebase/app ' : patch
3
+ ---
4
+
5
+ fix: server app should initialize in web workers
Original file line number Diff line number Diff line change @@ -48,7 +48,12 @@ import {
48
48
LogOptions ,
49
49
setUserLogHandler
50
50
} from '@firebase/logger' ;
51
- import { deepEqual , getDefaultAppConfig , isBrowser } from '@firebase/util' ;
51
+ import {
52
+ deepEqual ,
53
+ getDefaultAppConfig ,
54
+ isBrowser ,
55
+ isWebWorker
56
+ } from '@firebase/util' ;
52
57
53
58
export { FirebaseError } from '@firebase/util' ;
54
59
@@ -230,7 +235,7 @@ export function initializeServerApp(
230
235
_options : FirebaseOptions | FirebaseApp ,
231
236
_serverAppConfig : FirebaseServerAppSettings
232
237
) : FirebaseServerApp {
233
- if ( isBrowser ( ) ) {
238
+ if ( isBrowser ( ) && ! isWebWorker ( ) ) {
234
239
// FirebaseServerApp isn't designed to be run in browsers.
235
240
throw ERROR_FACTORY . create ( AppError . INVALID_SERVER_APP_ENVIRONMENT ) ;
236
241
}
Original file line number Diff line number Diff line change 18
18
import { CONSTANTS } from './constants' ;
19
19
import { getDefaults } from './defaults' ;
20
20
21
+ /**
22
+ * Type placeholder for `WorkerGlobalScope` from `webworker`
23
+ */
24
+ declare class WorkerGlobalScope { }
25
+
21
26
/**
22
27
* Returns navigator.userAgent string or '' if it's not defined.
23
28
* @return user agent string
@@ -77,7 +82,18 @@ export function isNode(): boolean {
77
82
* Detect Browser Environment
78
83
*/
79
84
export function isBrowser ( ) : boolean {
80
- return typeof self === 'object' && self . self === self ;
85
+ return typeof window !== 'undefined' || isWebWorker ( ) ;
86
+ }
87
+
88
+ /**
89
+ * Detect Web Worker context
90
+ */
91
+ export function isWebWorker ( ) : boolean {
92
+ return (
93
+ typeof WorkerGlobalScope !== 'undefined' &&
94
+ typeof self !== 'undefined' &&
95
+ self instanceof WorkerGlobalScope
96
+ ) ;
81
97
}
82
98
83
99
/**
You can’t perform that action at this time.
0 commit comments