Skip to content

Commit

Permalink
Fix service worker scope
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyparrish committed Jan 19, 2024
1 parent e2cf487 commit 0ca3b39
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions register-service-worker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
(async () => {
if ('serviceWorker' in navigator) {
// Register a service worker hosted at the root of the
// site using the default scope.
try {
const registration =
await navigator.serviceWorker.register('service-worker.js');
const thisFolder = location.pathname.replace(/\/index.html$/, '/');
const registration = await navigator.serviceWorker.register(
'service-worker.js', {scope: thisFolder});
console.log('Service worker registration succeeded:', registration);
} catch (error) {
console.error(`Service worker registration failed: ${error}`);
Expand Down

0 comments on commit 0ca3b39

Please sign in to comment.