Saturday, February 13, 2021

The script has an unsupported MIME type ('text/html').

ServiceWorker: The script has an unsupported MIME type (chrome-extension) 


The Error is showing because of the incorrect path and service worker is not accessible.

Path defined for js is not correct, might be you have taken relative path and this is vary on different pages.

Replacing:

'service-worker.js'

with:

'/service-worker.js' OR './service-worker.js'

in (navigator.serviceWorker.register('/service-worker.js')


The service worker file is not present at http://domain.com/service-worker.js so the server is returning index.html instead. Then the registration function has no idea of what to do with a index.html file and tells you that the MIME-type is not correct. 

A quick fix would be to copy the service-worker.js file to the public folder so that when you hit http://domain.com/service-worker.js you see the file in the browser. 

Remember to go to ChromeDev > Applications > ServiceWorkers and hit Unsubscribe. in order to remove the errored one. Remember also disable cache 

No comments: