Can't register a service worker in chrome but in Firefox it is working

Viewed 1844

Having a problem in registering a service worker in chrome is say in console log is Service worker registration failed: DOMException. I used https on my site. and its running in livesite. please see my code.

main.js

if ('serviceWorker' in navigator) {
  // Register a service worker hosted at the root of the
  // site using the default scope.
  navigator.serviceWorker.register('sw.js').then(function(registration) {
    console.log('Service worker registration succeeded:', registration);
  }, /*catch*/ function(error) {
    console.log('Service worker registration failed:', error);
  });
} else {
  console.log('Service workers are not supported.');
}

sw.js is empty Im trying to register my worker first before I add a code in this file.

Console log in mozilla ServiceWorker registration successful with scope: https://m.domain.com/ main.js:5:7

Console log in chrome Service worker registration failed: DOMException.

0 Answers
Related