0

I have made a React build, npm start build. When I have uploaded my build to my GitHub page: My React App Github Page .Then I get this error: "Error during service worker registration: DOMException: Only secure origins are allowed". I have tried to make some changes to the index.html file, to try register the service worker like this:

      <script type="text/javascript" src="/static/js/main.99691887.js">
  if('serviceWorker' in navigator){
       // Register service worker
        navigator.serviceWorkerContainer.register('service-worker.js').then(function(reg){
           console.log("SW registration succeeded. Scope is "+reg.scope);
       }).catch(function(err){
           console.error("SW registration failed with error "+err);
       });
   }
  </script>

But I still get the error. Is there a way to make this work on my GitHub page?

antonidag
  • 35
  • 2
  • 7
  • Possible duplicate of [Options for testing service workers via HTTP](https://stackoverflow.com/questions/34160509/options-for-testing-service-workers-via-http) – Jeff Posnick Dec 07 '17 at 23:08
  • See https://stackoverflow.com/a/34161385/385997 in particular, but the easier approach is just to use `https:` URLs, since GitHub pages supports HTTPS. – Jeff Posnick Dec 07 '17 at 23:08

0 Answers0