@@ -44,15 +44,17 @@ declare global {
44
44
}
45
45
}
46
46
47
+ const NAMESPACE_EXPORTS = {
48
+ isSupported
49
+ } ;
50
+
47
51
export function registerRemoteConfig (
48
52
firebaseInstance : _FirebaseNamespace
49
53
) : void {
50
54
firebaseInstance . INTERNAL . registerComponent (
51
- new Component (
52
- 'remoteConfig' ,
53
- remoteConfigFactory ,
54
- ComponentType . PUBLIC
55
- ) . setMultipleInstances ( true )
55
+ new Component ( 'remoteConfig' , remoteConfigFactory , ComponentType . PUBLIC )
56
+ . setMultipleInstances ( true )
57
+ . setServiceProps ( NAMESPACE_EXPORTS )
56
58
) ;
57
59
58
60
firebaseInstance . registerVersion ( packageName , version ) ;
@@ -72,6 +74,10 @@ export function registerRemoteConfig(
72
74
throw ERROR_FACTORY . create ( ErrorCode . REGISTRATION_WINDOW ) ;
73
75
}
74
76
77
+ if ( ! isSupported ( ) ) {
78
+ throw ERROR_FACTORY . create ( ErrorCode . UNSUPPORTED_BROWSER ) ;
79
+ }
80
+
75
81
// Normalizes optional inputs.
76
82
const { projectId, apiKey, appId } = app . options ;
77
83
if ( ! projectId ) {
@@ -133,9 +139,51 @@ declare module '@firebase/app-types' {
133
139
interface FirebaseNamespace {
134
140
remoteConfig ?: {
135
141
( app ?: FirebaseApp ) : RemoteConfigType ;
142
+ isSupported ( ) : boolean ;
136
143
} ;
137
144
}
138
145
interface FirebaseApp {
139
146
remoteConfig ( ) : RemoteConfigType ;
140
147
}
141
148
}
149
+
150
+ function isSupported ( ) : boolean {
151
+ if ( self && 'ServiceWorkerGlobalScope' in self ) {
152
+ // Running in ServiceWorker context
153
+ return isSWControllerSupported ( ) ;
154
+ } else {
155
+ // Assume we are in the window context.
156
+ return isWindowControllerSupported ( ) ;
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Checks to see if the required APIs exist.
162
+ */
163
+ function isWindowControllerSupported ( ) : boolean {
164
+ return (
165
+ 'indexedDB' in window &&
166
+ indexedDB !== null &&
167
+ navigator . cookieEnabled &&
168
+ 'serviceWorker' in navigator &&
169
+ 'PushManager' in window &&
170
+ 'Notification' in window &&
171
+ 'fetch' in window &&
172
+ ServiceWorkerRegistration . prototype . hasOwnProperty ( 'showNotification' ) &&
173
+ PushSubscription . prototype . hasOwnProperty ( 'getKey' )
174
+ ) ;
175
+ }
176
+
177
+ /**
178
+ * Checks to see if the required APIs exist within SW Context.
179
+ */
180
+ function isSWControllerSupported ( ) : boolean {
181
+ return (
182
+ 'indexedDB' in self &&
183
+ indexedDB !== null &&
184
+ 'PushManager' in self &&
185
+ 'Notification' in self &&
186
+ ServiceWorkerRegistration . prototype . hasOwnProperty ( 'showNotification' ) &&
187
+ PushSubscription . prototype . hasOwnProperty ( 'getKey' )
188
+ ) ;
189
+ }
0 commit comments