Options for Testing Service Workers via Http

How to allow serviceworkers for http in chrome

As you want to send a link to other people, you need to expose your server through https to the public Internet. You could set an https server with an autosigned certificate up but I think the simplest option is to use ngrok. Once you have ngrok installed, launch a local server as:

$ python -m SimpleHTTPServer

And then launch ngrok with:

$ ngrok http 8000

Given 8000 is the port where the Python server started, you will see:

ngrok by @inconshreveable                                     (Ctrl+C to quit)

Tunnel Status online
Version 2.0.19/2.0.20
Web Interface http://127.0.0.1:4040
Forwarding http://27223554.ngrok.io -> localhost:8000
Forwarding https://27223554.ngrok.io -> localhost:8000

Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00

Now distribute https://27223554.ngrok.io as the link for testing your site. It will work as you keep ngrok running and connected to the Internet. Of course, you can use the link yourself as well.

How can I make Service Worker work in local network?

You cannot make it work without https. Having your site served over HTTPS is a requirement to enable service workers (apart from http://localhost and http://127.x.X.X).

You definitely need a valid, trusted SSL certificate if you want it to run on all platforms on production. On windows, I think there are some Chrome options to bypass that, but this would still be only for testing

Edit

You can add certificates in IIS. It might not be a trusted one, but you can manually install and trust that certificate on your devices. This is a manual process valid only for development.

As pointed by @Benjamin if all your users are on your same company network, then you can deploy that certificate on all machines (and phones) and it should work.

Which type of event listeners are available for service workers

You may see the full list of supported events in the spec: https://www.w3.org/TR/service-workers/#execution-context-events

They mostly deal with network and different sorts of messsages. As I see it, the only ones dealing with direct user interaction are the notification click/close events.



Related Topics



Leave a reply



Submit