File tree Expand file tree Collapse file tree 5 files changed +21
-14
lines changed Expand file tree Collapse file tree 5 files changed +21
-14
lines changed Original file line number Diff line number Diff line change 15
15
* limitations under the License.
16
16
*/
17
17
18
- import { getUA } from '@firebase/util' ;
18
+ import { getUA , isIndexedDBAvailable } from '@firebase/util' ;
19
19
20
20
import { debugAssert } from '../util/assert' ;
21
21
import { Code , FirestoreError } from '../util/error' ;
@@ -158,7 +158,7 @@ export class SimpleDb {
158
158
159
159
/** Returns true if IndexedDB is available in the current environment. */
160
160
static isAvailable ( ) : boolean {
161
- if ( typeof indexedDB === 'undefined' ) {
161
+ if ( ! isIndexedDBAvailable ( ) ) {
162
162
return false ;
163
163
}
164
164
Original file line number Diff line number Diff line change 16
16
*/
17
17
18
18
import * as firestore from '@firebase/firestore-types' ;
19
+ import { isIndexedDBAvailable } from '@firebase/util' ;
19
20
20
21
import * as firebaseExport from './firebase_export' ;
21
22
import {
@@ -44,7 +45,7 @@ function isIeOrEdge(): boolean {
44
45
export function isPersistenceAvailable ( ) : boolean {
45
46
return (
46
47
typeof window === 'object' &&
47
- typeof window . indexedDB === 'object' &&
48
+ isIndexedDBAvailable ( ) &&
48
49
! isIeOrEdge ( ) &&
49
50
( typeof process === 'undefined' ||
50
51
process . env ?. INCLUDE_FIRESTORE_PERSISTENCE !== 'false' )
Original file line number Diff line number Diff line change @@ -26,7 +26,13 @@ import {
26
26
getToken ,
27
27
onMessage
28
28
} from '@firebase/messaging' ;
29
- import { NextFn , Observer , Unsubscribe } from '@firebase/util' ;
29
+ import {
30
+ areCookiesEnabled ,
31
+ isIndexedDBAvailable ,
32
+ NextFn ,
33
+ Observer ,
34
+ Unsubscribe
35
+ } from '@firebase/util' ;
30
36
31
37
import { onBackgroundMessage } from '@firebase/messaging/sw' ;
32
38
@@ -62,9 +68,8 @@ export function isSupported(): boolean {
62
68
*/
63
69
function isWindowSupported ( ) : boolean {
64
70
return (
65
- 'indexedDB' in window &&
66
- indexedDB !== null &&
67
- navigator . cookieEnabled &&
71
+ isIndexedDBAvailable ( ) &&
72
+ areCookiesEnabled ( ) &&
68
73
'serviceWorker' in navigator &&
69
74
'PushManager' in window &&
70
75
'Notification' in window &&
@@ -79,8 +84,7 @@ function isWindowSupported(): boolean {
79
84
*/
80
85
function isSwSupported ( ) : boolean {
81
86
return (
82
- 'indexedDB' in self &&
83
- indexedDB !== null &&
87
+ isIndexedDBAvailable ( ) &&
84
88
'PushManager' in self &&
85
89
'Notification' in self &&
86
90
ServiceWorkerRegistration . prototype . hasOwnProperty ( 'showNotification' ) &&
Original file line number Diff line number Diff line change 15
15
* limitations under the License.
16
16
*/
17
17
18
- import { validateIndexedDBOpenable } from '@firebase/util' ;
18
+ import {
19
+ isIndexedDBAvailable ,
20
+ validateIndexedDBOpenable
21
+ } from '@firebase/util' ;
19
22
20
23
/**
21
24
* Checks if all required APIs exist in the browser.
@@ -29,7 +32,7 @@ export async function isWindowSupported(): Promise<boolean> {
29
32
// instantiating phase, informing the developers to import/call isSupported for special handling.
30
33
return (
31
34
typeof window !== 'undefined' &&
32
- typeof indexedDB !== 'undefined' &&
35
+ isIndexedDBAvailable ( ) &&
33
36
( await validateIndexedDBOpenable ( ) ) &&
34
37
navigator . cookieEnabled &&
35
38
'serviceWorker' in navigator &&
@@ -52,9 +55,8 @@ export async function isSwSupported(): Promise<boolean> {
52
55
// might be prohibited to run. In these contexts, an error would be thrown during the messaging
53
56
// instantiating phase, informing the developers to import/call isSupported for special handling.
54
57
return (
58
+ isIndexedDBAvailable ( ) &&
55
59
( await validateIndexedDBOpenable ( ) ) &&
56
- 'indexedDB' in self &&
57
- indexedDB !== null &&
58
60
'PushManager' in self &&
59
61
'Notification' in self &&
60
62
ServiceWorkerRegistration . prototype . hasOwnProperty ( 'showNotification' ) &&
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ export function isSafari(): boolean {
140
140
* @return true if indexedDB is supported by current browser/service worker context
141
141
*/
142
142
export function isIndexedDBAvailable ( ) : boolean {
143
- return 'indexedDB' in self && indexedDB != null ;
143
+ return typeof indexedDB === 'object' ;
144
144
}
145
145
146
146
/**
You can’t perform that action at this time.
0 commit comments