Skip to content

Commit 0a04a1c

Browse files
authored
Fix isWindowSupported() check (#5957)
1 parent 8b51375 commit 0a04a1c

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.changeset/tame-apes-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/messaging': patch
3+
---
4+
5+
Fix uncaught rejection in `isSupported()` if environment does not support IndexedDB's `open()` method.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export function isSupported(): boolean {
6565

6666
/**
6767
* Checks to see if the required APIs exist.
68+
* Unlike the modular version, it does not check if IndexedDB.open() is allowed
69+
* in order to keep isSupported() synchronous and maintain v8 compatibility.
6870
*/
6971
function isWindowSupported(): boolean {
7072
return (

packages/messaging/src/api/isSupported.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ import {
2828
* @public
2929
*/
3030
export async function isWindowSupported(): Promise<boolean> {
31+
try {
32+
// This throws if open() is unsupported, so adding it to the conditional
33+
// statement below can cause an uncaught error.
34+
await validateIndexedDBOpenable();
35+
} catch (e) {
36+
return false;
37+
}
3138
// firebase-js-sdk/issues/2393 reveals that idb#open in Safari iframe and Firefox private browsing
3239
// might be prohibited to run. In these contexts, an error would be thrown during the messaging
3340
// instantiating phase, informing the developers to import/call isSupported for special handling.
3441
return (
3542
typeof window !== 'undefined' &&
3643
isIndexedDBAvailable() &&
37-
(await validateIndexedDBOpenable()) &&
3844
areCookiesEnabled() &&
3945
'serviceWorker' in navigator &&
4046
'PushManager' in window &&

0 commit comments

Comments
 (0)