Console Logging in Service Workers
What you'll learn: How to access and view service worker console logs separately from your main page console to effectively debug background operations.
The Challenge of Service Worker Logging
Service workers run in a separate thread from your main web page, which means their console.log() statements don't appear in the same console as your page code. This can be confusing when debugging—you add logging statements but see nothing in your usual DevTools console!
Where Service Worker Logs Actually Live
Think of your service worker as a backstage crew member at a theater: they're doing important work, but in a completely different space from the actors on stage (your web page). To hear what they're saying, you need to go backstage.
In Chrome/Edge DevTools:
- Open DevTools on your page
- Go to the Application tab
- Click Service Workers in the left sidebar
- Look for the "inspect" link next to your active service worker
- Clicking it opens a separate DevTools window dedicated to that service worker
Any console.log(), console.error(), or console.warn() statements in your service worker code will appear in that separate console.
Example Context
// In your service worker file
self.addEventListener('fetch', (event) => {
console.log('Intercepted fetch for:', event.request.url);
// This logs in the SERVICE WORKER console, not the page console
});
You won't see this log in your page's regular console—only in the dedicated service worker inspector.
Key Takeaway: Service worker console logs appear in a separate DevTools window accessed via the "inspect" link in the Application → Service Workers panel, not in your main page console.