From 056be01f15f7f9275ca2767cbb5ee333d5b55be1 Mon Sep 17 00:00:00 2001 From: ekzyis <27162016+ekzyis@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:38:43 +0100 Subject: [PATCH] Request persistent storage (#701) * Request persistent storage * Only prompt for persistent storage if push notifications enabled --------- Co-authored-by: ekzyis --- components/serviceworker.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/serviceworker.js b/components/serviceworker.js index 43815508..174aa312 100644 --- a/components/serviceworker.js +++ b/components/serviceworker.js @@ -99,7 +99,15 @@ export const ServiceWorkerProvider = ({ children }) => { if (pushSubscription) { return unsubscribeFromPushNotifications(pushSubscription) } - return subscribeToPushNotifications() + return subscribeToPushNotifications().then(async () => { + // request persistent storage: https://web.dev/learn/pwa/offline-data#data_persistence + const persisted = await navigator?.storage?.persisted?.() + if (!persisted && navigator?.storage?.persist) { + return navigator.storage.persist().then(persistent => { + logger.info('persistent storage:', persistent) + }).catch(logger.error) + } + }) }) useEffect(() => {