An unknown error occurred when fetching the script (Service Worker)

an ssl certificate error occurred when fetching the script. service worker
service worker not working offline
service worker browser support
an unknown error occurred when fetching the script youtube
service worker does not have the fetch handler
service worker lifecycle
not found service-worker js
service worker localhost

When going offline, I get the following error by my service worker:

(unknown) #3016 An unknown error occurred when fetching the script

my service worker looks like this:

var version = 'v1'

this.addEventListener('install', function(event){
  event.waitUntil(
     caches.open(version).then(cache => {
       return cache.addAll([
         'https://fonts.googleapis.com/icon?family=Material+Icons',
         'https://fonts.googleapis.com/css?family=Open+Sans:400,600,300',
         './index.html'
       ])
     })
   )
})

this.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request).then(function(resp) {
      // if it's not in the cache, server the regular network request. And save it to the cache
      return resp || fetch(event.request).then(function(response) {
        return caches.open(version).then(function(cache) {
          cache.put(event.request, response.clone())
          return response
        })
      })
    })
  )
})

It is at top level directory, right next to a manifest importing like this in index.html:

<link rel="manifest" href="/manifest.json">

I import the service worker in my entry js file. And register it right after.

require('tether-manifest.json')
import serviceWorker from 'sw'

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register(serviceWorker)
  .then(() => {
    // registration worked
  }).catch(error => {
    throw new Error(error)
  })
}

It registers fine. I don't encounter the error until I go offline.

I am using webpack with React, and doing the following in webpack to copy my sw.js file to the dist folder:

loaders: [
      { // Service worker
        test: /sw\.js$/,
        include: config.src,
        loader: 'file?name=[name].[ext]'
      },
      { // Manifest
        test: /manifest\.json$/,
        include: config.src,
        loader: 'file?name=[name].[ext]'
      }
]

The error doesn't give any information as to what is happening.

Anyone have any idea how to fix this?


I had exactly the same problem, I spent an hour trying to figure it out and it turned out that I had another tab for the same origin left opened somewhere (so using the same shared Service Worker) that had the "Offline" checkbox left checked and that prevented another tabs from requesting sw.js for some reason.

It seems that the offline state is leaking from the tab within Service Worker scope while not being properly reflected nor managed by the other tabs than the one that was turned Offline first.

So make sure you have no other clients running the same Service Worker - you should be able to find them listed in DevTools > Application > Service Workers.

Service workers for everyone! - Melanie Burger, Be forewarned, a common and not-so-helpful error message you might encounter is “An unknown error occurred when fetching the script.” To unregister service workers that you don't want go to, Application tab > Application > Service Workers, then check “Show all” and click “unregister”. ServiceWorker registration failed: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. Thanks. Solutions (UPDATE) - Include app.use('/', routes),or wherever the service-worker file at into index.js file.


For me this error went away when i added sw.js to the cache upon install. Simply forgot to do that, but it solved the issue.

Failed to load service-worker.js · Issue #97 · vuejs-templates/pwa , An unknown error occurred when fetching the script. Failed to load resource: net::​ERR_INTERNET_DISCONNECTED service-worker.js. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.


I had this issue while working in an Angular project. My problem was that I was using Angular CLI's built-in ng serve -prod command.

To make it work, I used ng build -prod and then host the resulting dist folder using http-server

Can't get service worker when offline · Issue #51 · goldhand/sw , Just get a generic An unknown error occurred when fetching the script. failure. I'm also working on localhost (not sure if that's relevant). Not sure  Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.


In Chrome, what I did was to check the option Bypass for network and then I was able to reload.

Service Workers aren't working, Service workers are, apparently, the recommended replacement for the no errors or I get An unknown error occurred when fetching the script. Call update() on the registration to manually refresh the Service Worker script. The Service Worker script automatically attempts to refresh when we call navigator.serviceWorker.register(), but we might want to poll for updates more often than that, e.g. once an hour or something.


Lab: Workbox | Web, How to write a service worker using the workbox-sw.js library; How to add unknown error occurred when fetching the script. service-worker.js  Service worker changes. The service worker will need to include the Auth library and the ability to get the current ID token if a user is signed in. // Initialize the Firebase app in the service worker script. firebase.initializeApp(config); /** * Returns a promise that resolves with an ID token if available.


Error ServiceWorker in Lighthouse, TypeError: Failed to update a ServiceWorker for… script ('https://dindludovic.​design/superpwa-sw.js'): An unknown error occurred when fetching the script. Q: When I have Developer Tools open, requests go straight to the network; the Service Worker does not get a fetch event. A: On the Developer Tools' Network tab, if Disable cache is checked, requests will go to the network instead of the Service Worker.


Angular Service Worker - Step-By-Step Guide, With the Angular Service Worker and the Angular CLI built-in PWA An unknown error occurred when fetching the script. ngsw-worker.js  Rebuild the app (including the service worker) and restart the server with the following command: npm run serve Refresh the app and activate the updated service worker in the browser. In Chrome