1

Currently I am testing my ServiceWorker in my localhost only. But the problem is, if i change 'localhost' to my machine name in the url, it does not allow ServiceWorker and serves the vanilla response.I assume it's because serviceworker is not allowed for http.

Now, if I want to send some one a testlink with my machinename , i am not able to do that.I want to know if there is any way to allow serviceworker for chrome.

biswpo
  • 771
  • 7
  • 23
  • 2
    Possible duplicate of [Options for testing service workers via HTTP](http://stackoverflow.com/questions/34160509/options-for-testing-service-workers-via-http) – Jeff Posnick Feb 26 '16 at 15:59

2 Answers2

0

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.

Salva
  • 6,507
  • 1
  • 26
  • 25
0

I wouldn't say it is duplicate because this is much more especific.

I run some tests and my advice is you should use Firefox with devtools.serviceWorkers.testing.enabled for your clients

  • If you only use ngrok that won't help you (although is an amazing tool)
  • If you want to use --unsafety-treat-insecure-origin-as-secure you should know that you can't use it for chrome, it is unsupported. Maybe canary or chronium works but i didn't checked.
corlaez
  • 1,352
  • 1
  • 15
  • 30