Course contentsShow
← Web Development
Lesson 2309 of 2,98242. Progressive Web AppsFree lesson

Service Worker Browser Support and Detection

Check for service worker support and understand compatibility across browsers and contexts.

Service Worker Browser Support and Detection

You'll learn how to check if a browser supports service workers and understand where they can (and can't) run.

Why Detection Matters

Not every browser or context supports service workers. Before attempting to register one, you need to check if the feature exists. Failing to detect support will throw errors and break your Progressive Web App experience for users on unsupported platforms.

Think of it like checking if a building has an elevator before directing someone to press the button—if it doesn't exist, you need a backup plan (or graceful degradation).

Browser Support Landscape

Modern browsers—Chrome, Edge, Firefox, Safari (iOS 11.3+)—support service workers well. However, they only work over HTTPS (except on localhost for development). This security requirement prevents man-in-the-middle attacks since service workers intercept network requests.

Service workers also won't run in:

  • Private/incognito modes (in some browsers)
  • HTTP sites (non-secure origins)
  • Older browsers (IE11, older Android browsers)

Detection Code

Check for the serviceWorker property in the navigator object:

if ('serviceWorker' in navigator) {
  console.log('Service workers are supported!');
  // Safe to proceed with registration
} else {
  console.warn('Service workers are not supported.');
  // Provide fallback experience
}

This detection should happen before any registration attempt. It's a simple property check that prevents runtime errors on unsupported platforms.

Graceful Degradation

When service workers aren't available, your app should still function—just without offline capabilities or advanced caching. The core content and features remain accessible; users simply miss the PWA enhancements.

Key Takeaway: Always check 'serviceWorker' in navigator before registering; service workers require HTTPS and aren't universally supported, so plan for graceful degradation.