From 7c1685728b56115f0fd3530226d2a9fe4774d731 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Sun, 7 Jul 2024 16:24:21 -0700 Subject: [PATCH] fix regression in 0.12.x for app: (#239) - still need to register service worker if in app - update checkSW() to check if no service worker and register on load - in extension, service worker always provided by system - fixes #233, #231, related to #217 --- src/ui/app.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ui/app.js b/src/ui/app.js index d6f3d406..4f941002 100644 --- a/src/ui/app.js +++ b/src/ui/app.js @@ -3,6 +3,8 @@ import { html, css, wrapCss, IS_APP, apiPrefix } from "replaywebpage/src/misc"; // replaywebpage imports import { ReplayWebApp, Embed, Loader } from "replaywebpage"; +import { SWManager } from "replaywebpage/src/swmanager"; + import fasHelp from "@fortawesome/fontawesome-free/svgs/solid/question-circle.svg"; import fasPlus from "@fortawesome/fontawesome-free/svgs/solid/plus.svg"; @@ -141,8 +143,9 @@ class ArchiveWebApp extends ReplayWebApp } } - async checkDoubleSW() { + async checkSW() { const regs = await navigator.serviceWorker.getRegistrations(); + // Remove double SW for (const reg of regs) { if (reg.active && reg.active.scriptURL.endsWith("/replay/sw.js")) { if (await reg.unregister()) { @@ -150,6 +153,17 @@ class ArchiveWebApp extends ReplayWebApp } } } + + // For App: If no SW, register here + if (IS_APP && !regs.length) { + this.swmanager = new SWManager({ name: this.swName, appName: this.appName }); + this.swmanager + .register() + .catch( + () => + (this.swErrorMsg = this.swmanager.renderErrorReport(this.mainLogo)), + ); + } } firstUpdated() { @@ -159,7 +173,7 @@ class ArchiveWebApp extends ReplayWebApp return super.firstUpdated(); } - this.checkDoubleSW(); + this.checkSW(); this.initRoute();