Skip to content

Restore service worker registration code#4

Merged
below43 merged 1 commit into
below43:mainfrom
Rubixdarcy:fix/register-service-worker
Feb 4, 2026
Merged

Restore service worker registration code#4
below43 merged 1 commit into
below43:mainfrom
Rubixdarcy:fix/register-service-worker

Conversation

@Rubixdarcy
Copy link
Copy Markdown
Contributor

Fixes #3

Restores just the SW registration code from c29d8b1. Still leaves out the other PWA events that were removed in that commit.

@below43 below43 merged commit 6331ee8 into below43:main Feb 4, 2026
@below43 below43 requested a review from Copilot February 4, 2026 21:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request restores the service worker registration code that was previously removed, aiming to enable Progressive Web App functionality for offline capabilities. The changes add a setupServiceWorker() method and call it during app initialization.

Changes:

  • Added setupServiceWorker() method to register the service worker at /sw.js
  • Integrated service worker registration into the app's initialization flow
  • Removed trailing whitespace throughout the file for code cleanup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app.js
Comment on lines +120 to +128
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then((registration) => {
console.log('SW registered: ', registration);
})
.catch((registrationError) => {
console.log('SW registration failed: ', registrationError);
});
});
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The service worker registration is wrapped in a 'load' event listener, but this method is already called from setup() which runs after DOMContentLoaded (see lines 16-20). This creates a problematic nested event listener pattern.

If setupServiceWorker() is called after the window 'load' event has already fired, the inner event listener will never execute and the service worker will not be registered. This is likely to happen when the app loads quickly.

Consider one of these alternatives:

  1. Register the service worker immediately without the nested 'load' event listener, since setup() already ensures DOM is ready
  2. Move the service worker registration to happen directly in the constructor or init() method with a proper 'load' check
Suggested change
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then((registration) => {
console.log('SW registered: ', registration);
})
.catch((registrationError) => {
console.log('SW registration failed: ', registrationError);
});
});
navigator.serviceWorker.register('/sw.js')
.then((registration) => {
console.log('SW registered: ', registration);
})
.catch((registrationError) => {
console.log('SW registration failed: ', registrationError);
});

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ServiceWorker not registering

3 participants