Skip to content

Commit

Permalink
fix regression in 0.12.x for app: (#239)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ikreymer authored Jul 7, 2024
1 parent 39c57bb commit 7c16857
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -141,15 +143,27 @@ 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()) {
self.location.reload();
}
}
}

// 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() {
Expand All @@ -159,7 +173,7 @@ class ArchiveWebApp extends ReplayWebApp
return super.firstUpdated();
}

this.checkDoubleSW();
this.checkSW();

this.initRoute();

Expand Down

0 comments on commit 7c16857

Please sign in to comment.