Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL error when using https FCM

Tags:

ssl

I have implemented FCM for web using fcm documentation. Everything'll be fine if I set url like : 'http://xxx' I have no error. But when I set url : 'https://xxx..', I get error:

"Failed to register a ServiceWorker: An SSL certificate error occurred when fetching the script." code: "messaging/failed-serviceworker-registration" "Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: An SSL certificate error occurred when fetching the script. (messaging/failed-serviceworker-registration)."

Can anyone show me how to fix this error?

like image 606
firework Avatar asked Feb 09 '17 09:02

firework


1 Answers

This is a general problem when wanting to test service workers in a local development environment without proper SSL certificates. It is not specific to Firebase Messaging but pertains to Service Workers in general.

Here is the solution I found when using Google Chrome: Testing Service workers locally with self-signed certificates

Unfortunately, I don't know yet how to circument the issue with other browsers, but probably there must be similar ways.

For Chrome, you need to start a new instance of Chrome, with some flags telling it to ignore SSL certificate errors for your local origin:

In Linux (and maybe Mac):

google-chrome --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://127.0.0.1 --user-data-dir=/tmp/foo

The https://127.0.0.1 here is the location where your app (and service worker) is hosted locally. You might need to adjust this to use the appropriate port, if serving on a different port than the standard HTTPS port 443, e.g. https://127.0.0.1:3000, when serving your app over HTTPS on port 3000. The --user-data-dir=/tmp/foo is necessary to start a new instance, with a new user profile, if another instance of Chrome is already running.

In Windows (might vary, depending on where your chrome.exe is):

C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://localhost:1123

Again, you might have to adjust the port.

like image 80
trollkotze Avatar answered Nov 03 '22 19:11

trollkotze