Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug service worker with Chrome on Android mobile

Tags:

I'm developing a progressive webapp and, in order to make sure it's working on mobile device (and particularly on Chrome for Android as it's 90% of users), I'm trying to test service worker on an Android device.

Unfortunaltely, on Chrome for Android, I'm unable to register the service worker :

An SSL certificate error occurred when fetching the script.

Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID


I know service worker needs to be served over HTTPS so I have a self-signed certificate for my webapp. It is not trusted by browsers but it is still possible to proceed anyway. When using Firefox for Android, no problem I can sign to push notifications and register the service worker but with Chrome it's not working.

On Chrome for desktop, it's possible to enable service worker over non-secure origin with dev tools. I hoped to find the equivalent flag that I could use on mobile but none exists.

Is there a way to authorize service worker on Chrome Android for debug purpose?


I found an old question with no helpful answer there about the same issue and decided to open this one up for visibilty.

like image 458
Dave Smith Avatar asked Jun 18 '18 14:06

Dave Smith


2 Answers

From the other StackOverflow post you're referring to, I can see the solution is in the question.

You need to add a Certificate Authority crt to your Android trust list.


Why specifically a Certificate Authority .crt ?

Simply because Android only accepts CA certificates.


How do I get a CA certificate?

Normally, a Certificate Authority (CA) acts as a trusted third party. For debug purpose, you can act as a CA to issue self-signed certificate yourself.

  1. Create a root key: openssl genrsa -des3 -out rootCA.key 4096 (warning : anyone holding this can sign certificates on your behalf !)

  2. Create and self sign the Root Certificate: openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt

Remember that your webapp's SSL certificate needs to be generated with that same self-created CA.


Install certificate on Android device

Once you got your .crt file, copy it inside your device. Then go to Settings > Security > Install from storage. It should detect the certificate and let you add it.

To make sure it's installed correctly, go to Trusted Credentials > User.

like image 147
VictorGalisson Avatar answered Sep 28 '22 19:09

VictorGalisson


I solved this problem by portforwarding. You can find further info in my original answer here: https://stackoverflow.com/a/56146180/5048121

like image 40
kudlohlavec Avatar answered Sep 28 '22 19:09

kudlohlavec