Question: AbortError: Failed to register a ServiceWorker: ServiceWorker cannot be started

Question

AbortError: Failed to register a ServiceWorker: ServiceWorker cannot be started

Answers 1
Added at 2017-01-02 18:01
Tags
Question

I am trying to test push notifications functionality in Chrome. I cloned the sample Chrome push notification web-app provided by Google here: https://github.com/GoogleChrome/samples/tree/gh-pages/push-messaging-and-notifications

The code is working properly when I hosted the web app using Web server for Chrome extension HTTP server on localhost. When I wanted to test the web-app on a mobile device, I couldn't use the Web server for Chrome extension because of the fact that it is a HTTP server and other than localhost, service workers only work on HTTPS. So I created a python based HTTPS server using a self signed certificate and hosted the web-app there.

Now I am getting AbortError: Failed to register a ServiceWorker: ServiceWorker cannot be started while registering the service worker like below:

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

The service-worker.js is in the same directory as the html file as well as the js file from where i am calling this method.

There's not much documentation on service workers. Also the error is too vague to figure out anything. Please help me in figuring out the root cause of this error.

Answers to

AbortError: Failed to register a ServiceWorker: ServiceWorker cannot be started

nr: #1 dodano: 2017-01-03 08:01

I found the solution. Service Workers only work on secure HTTPS networks. The Python HTTPS Server that I had created was signed using self signed certificate and hence not secure. I used ngrok to create a secure https tunnel to localhost and then it worked

Source Show
◀ Wstecz