Skip to content

Commit a3ccc9b

Browse files
committed
indexedDb check was bad on AppCheck, dry up
1 parent 3a1e30d commit a3ccc9b

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

packages/firestore/src/local/simple_db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { getUA } from '@firebase/util';
18+
import { getUA, isIndexedDBAvailable } from '@firebase/util';
1919

2020
import { debugAssert } from '../util/assert';
2121
import { Code, FirestoreError } from '../util/error';
@@ -158,7 +158,7 @@ export class SimpleDb {
158158

159159
/** Returns true if IndexedDB is available in the current environment. */
160160
static isAvailable(): boolean {
161-
if (typeof indexedDB === 'undefined') {
161+
if (!isIndexedDBAvailable()) {
162162
return false;
163163
}
164164

packages/firestore/test/integration/util/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import * as firestore from '@firebase/firestore-types';
19+
import { isIndexedDBAvailable } from '@firebase/util';
1920

2021
import * as firebaseExport from './firebase_export';
2122
import {
@@ -44,7 +45,7 @@ function isIeOrEdge(): boolean {
4445
export function isPersistenceAvailable(): boolean {
4546
return (
4647
typeof window === 'object' &&
47-
typeof window.indexedDB === 'object' &&
48+
isIndexedDBAvailable() &&
4849
!isIeOrEdge() &&
4950
(typeof process === 'undefined' ||
5051
process.env?.INCLUDE_FIRESTORE_PERSISTENCE !== 'false')

packages/messaging-compat/src/messaging-compat.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import {
2626
getToken,
2727
onMessage
2828
} 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';
3036

3137
import { onBackgroundMessage } from '@firebase/messaging/sw';
3238

@@ -62,9 +68,8 @@ export function isSupported(): boolean {
6268
*/
6369
function isWindowSupported(): boolean {
6470
return (
65-
'indexedDB' in window &&
66-
indexedDB !== null &&
67-
navigator.cookieEnabled &&
71+
isIndexedDBAvailable() &&
72+
areCookiesEnabled() &&
6873
'serviceWorker' in navigator &&
6974
'PushManager' in window &&
7075
'Notification' in window &&
@@ -79,8 +84,7 @@ function isWindowSupported(): boolean {
7984
*/
8085
function isSwSupported(): boolean {
8186
return (
82-
'indexedDB' in self &&
83-
indexedDB !== null &&
87+
isIndexedDBAvailable() &&
8488
'PushManager' in self &&
8589
'Notification' in self &&
8690
ServiceWorkerRegistration.prototype.hasOwnProperty('showNotification') &&

packages/messaging/src/api/isSupported.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { validateIndexedDBOpenable } from '@firebase/util';
18+
import {
19+
isIndexedDBAvailable,
20+
validateIndexedDBOpenable
21+
} from '@firebase/util';
1922

2023
/**
2124
* Checks if all required APIs exist in the browser.
@@ -29,7 +32,7 @@ export async function isWindowSupported(): Promise<boolean> {
2932
// instantiating phase, informing the developers to import/call isSupported for special handling.
3033
return (
3134
typeof window !== 'undefined' &&
32-
typeof indexedDB !== 'undefined' &&
35+
isIndexedDBAvailable() &&
3336
(await validateIndexedDBOpenable()) &&
3437
navigator.cookieEnabled &&
3538
'serviceWorker' in navigator &&
@@ -52,9 +55,8 @@ export async function isSwSupported(): Promise<boolean> {
5255
// might be prohibited to run. In these contexts, an error would be thrown during the messaging
5356
// instantiating phase, informing the developers to import/call isSupported for special handling.
5457
return (
58+
isIndexedDBAvailable() &&
5559
(await validateIndexedDBOpenable()) &&
56-
'indexedDB' in self &&
57-
indexedDB !== null &&
5860
'PushManager' in self &&
5961
'Notification' in self &&
6062
ServiceWorkerRegistration.prototype.hasOwnProperty('showNotification') &&

packages/util/src/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function isSafari(): boolean {
140140
* @return true if indexedDB is supported by current browser/service worker context
141141
*/
142142
export function isIndexedDBAvailable(): boolean {
143-
return 'indexedDB' in self && indexedDB != null;
143+
return typeof indexedDB === 'object';
144144
}
145145

146146
/**

0 commit comments

Comments
 (0)