Console: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script
The browser could not fetch, parse or install the service worker script, or the page is not allowed to register one (HTTPS and scope rules).
Failed to register a ServiceWorkerA bad HTTP response code (404) was received when fetching the scriptThe script has an unsupported MIME typeSecurityError: Failed to register a ServiceWorkerThe path of the provided scope is not under the max scope allowed Meaning
Service workers need a secure context (HTTPS or localhost), a script reachable at its URL with a JavaScript MIME type, and a scope no wider than the script's folder unless Service-Worker-Allowed is sent. The console message names the exact reason: 404, MIME type, scope or SSL certificate error.
Common causes
- Wrong URL for
sw.js(404 or SPA fallback returning HTML) - Not served over HTTPS (except localhost)
- Script served with a non-JavaScript MIME type
- Scope wider than the script location
- Syntax error in the worker or certificate error
⚡ Quick fix
- Open the script URL directly — it must return JavaScript
- Use HTTPS (or localhost for development)
- Place
sw.jsat the site root or sendService-Worker-Allowed
Detailed fix by platform
JavaScript
navigator.serviceWorker.register('/sw.js', { scope: '/' }).catch(console.error);— read the rejected error message- DevTools → Application → Service Workers shows status and errors
Nginx
- Serve with the right header for scope:
location = /static/sw.js { add_header Service-Worker-Allowed "/"; }
How to diagnose
- URL — Does /sw.js load as JavaScript?
- Context — HTTPS or localhost?
- Scope — Within the script's folder?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Browser
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026