5

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.

  • check with your cookie setting .. for similar error in firefox is resolve by cookie setting. https://stackoverflow.com/questions/49539306/firefox-service-worker-securityerror-domexception-the-operation-is-insecure – divyang4481 Jan 04 '19 at 02:48
  • How are you creating the worker process? What is `navigator`? – Get Off My Lawn Jan 04 '19 at 02:57
  • @GetOffMyLawn that is a ServiceWorker and you do generally register it through the `window.navigator.serviceWorker` API. The question's title was wrong. – Kaiido Jan 04 '19 at 03:00
  • Okay... I thought that this was a Web Worker... – Get Off My Lawn Jan 04 '19 at 03:01
  • Are you sure you don't have a clearer error message somewhere? That sounds like something in the worker's code failed. Try to remove things until it doesn't throw anymore. And anyway, we'll need to see an [MCVE] to be able to help you. – Kaiido Jan 04 '19 at 03:01

0 Answers0