From 4fc8e4d7faf8a6ca8e0b90e32ec3009174bb7805 Mon Sep 17 00:00:00 2001 From: Imre Gera Date: Sat, 17 Sep 2022 19:58:31 +0200 Subject: [PATCH] fix(serviceworker): Fix service worker not registering (#270) --- app.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app.vue b/app.vue index 25e13db..bdf8563 100644 --- a/app.vue +++ b/app.vue @@ -22,9 +22,16 @@ if (!process.server) { onMounted(() => { if (typeof window !== 'undefined') { if ('serviceWorker' in navigator) { - window.addEventListener('load', function () { + const registerSw = () => { + console.debug(`Registering service worker at /${swPath}`) navigator.serviceWorker.register(`/${swPath}`) - }) + } + + if (document.readyState === 'complete') { + registerSw() + } else { + window.addEventListener('load', registerSw) + } } } })