问题
I was trying to debug a service worker served from my dev machine and running inside chrome android on the smartphone.
I was using the usb connection and remotely debugging from my dev machine. The service worker works only in https and I can live with that, both chrome and firefox where refusing to register the SW.
Then I used a self signed certificate on my dev machine, which obviously was not trusted by the mobile browsers. They warned the certificate was not good but gave the option to proceed with that certificate. I clicked yes and, while firefox from that point was able to register the SW chrome was still compaining that the certificate was not good and refused to register the SW.
I tried to include the self signed CA in the smartphone trust list but didn't find a way to do that. In the end I had to serve the app from a production server with a regular certificate, which I didn't like at all, but I could not waste a whole day on this issue.
How is it possible to remote debug a service worker on android served from a dev machine in a LAN? localhost cannot be used because they are 2 separate devices. I found a setting to ignore the https waring for chrome but desktop version, I am using android chrome, how can I disable this boring blocking error?
Thanks
回答1:
I was also facing same issue. I have written service worker for push notification for my personal use. It was running perfectly on my desktop browser as I was running it on localhost. But I wanted notification on mobile so I tried many options to accomplish same, Running remote IP as localhost on mobile, USB debugging, adding ssl certificates and many other hacks but nothing worked for me. But then "Kick Web Server" app for android mobile came to my rescue, It took only few minute to run my application on mobile browser with localhost and register service worker. So no need of SSL and USB debugging any more.
Steps
- Goto playstore and search for "Kick Web Server" app (Note: after serching results will show "Web Server PHPMyAdmin/MySql" with icon like this).
- Do not afraid you do not need PHP or Mysql with this app, you can run your web site with ease written in any technology stack.
- Open app it will ask you for permission to access storage, you have to grant permission to it.
- Get back to app and click on stopped button to start web server.
- It will create directory/folder named htdocs in your mobile storage.
- Delete existing content(two existing files) from htdocs directory.
- Copy content of your build with index.html in htdocs directory.
- Visit http://localhost:8080 in your mobile browser and you will see your site is up and running with service worker registered.
来源:https://stackoverflow.com/questions/40331932/remotely-debugging-service-worker-on-chrome-android-with-self-signed-certificate