lbry-desktop/web/src/push-notifications/push-supported.js
Dan Peterson 704452732a
Add hints if an error occurs subscribing to notifications (#143)
* Add hints if an error occurs subscribing to notifications

* Update import (type/linting issue)

* disable optimization for debugging

* Revert "disable optimization for debugging"

This reverts commit 5b837f94e97b7488a7dc565e7f74d399e19c286f.

* improve detection of notification support + improve ux / ui surrounding that

* update translations
2021-11-01 14:51:23 -04:00

16 lines
676 B
JavaScript

// @flow
import { isSupported } from 'firebase/messaging';
export const isPushSupported = async (): Promise<boolean> => {
if ('serviceWorker' in navigator) {
// Some browsers incognito expose sw but not the registration, while other don't expose sw at all.
// $FlowIssue[incompatible-type]
const activeRegistrations: Array<ServiceWorkerRegistration> = await navigator.serviceWorker.getRegistrations();
const swRegistered = activeRegistrations.length > 0;
const firebaseSupported = await isSupported();
const notificationFeature = 'Notification' in window;
return swRegistered && firebaseSupported && notificationFeature;
}
return false;
};