Skip to content

Commit

Permalink
fixup! Cleanup background service worker code
Browse files Browse the repository at this point in the history
  • Loading branch information
bas080 committed Jun 19, 2024
1 parent 209ea6d commit 34e4586
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"start_url": "index.html",
"display": "standalone",
"background": {
"service_worker": "./service-worker.mjs"
"service_worker": "service-worker.mjs",
"type": "module"
},
"background_color": "#228b22",
"theme_color": "#af0c1a",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
},
"targets": {
"default": {
"source": ["./index.html", "./service-worker.mjs"]
"source": [
"./index.html"
]
}
}
}
13 changes: 13 additions & 0 deletions toplist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ function rerender() {

rerender();

if ("serviceWorker" in navigator) {
try {
const registration = await navigator.serviceWorker.register(
new URL("./service-worker.mjs", import.meta.url),
{type: 'module'}
);

console.log("Service Worker registered with scope:", registration.scope);
} catch (error) {
console.error("Service Worker registration failed:", error);
}
}

tryReject(function () {
const url = new URL(window.location.href);
const append = url.searchParams.get("append");
Expand Down

0 comments on commit 34e4586

Please sign in to comment.