4

I'm not using localhost to test the serviceworker. The server have self-signed cert and it is working.

While trying to get push token from FCM it shows: ServiceWorker registration failed: DOMException: Failed to register a ServiceWorker: An SSL certificate error occurred when fetching the script.

Can FCM service worker work with server self-signed cert?

it is a staging server therefore we wont be buying ssl cert for the server.

Kimberlee Ho
  • 447
  • 1
  • 6
  • 23

2 Answers2

2

Looks like you can't use service workers with self signed certs.

Run Chrome with custom flags to white list your domain for testing purposes:

/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ --user-data-dir=/tmp/foo --unsafely-treat-insecure-origin-as-secure=http://www.your.site

Make sure you use the correct path where Chrome is installed.

See https://stackoverflow.com/a/43484456/545726 And https://deanhume.com/home/blogpost/testing-service-workers-locally-with-self-signed-certificates/10155

aiham
  • 3,614
  • 28
  • 32
1

To add to aiham's answer for this question

I tested the following latest browsers to work as well with these arguments:

open -a Opera.app --args --user-data-dir=/tmp/foo --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://localhost:8111

open -a Brave\ Browser.app --args --user-data-dir=/tmp/foo --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://localhost:8111

open -a Google\ Chrome.app --args --user-data-dir=/tmp/foo --ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://localhost:8111

Chromium browser did not start with these settings to allow to overcome this specific DomException for using SSL with service worker locally.

This person provided some insights as a story as well for this matter: https://deanhume.com/testing-service-workers-locally-with-self-signed-certificates/

Oleksii Kyslytsyn
  • 2,458
  • 2
  • 27
  • 43
  • Is there a method for a cordova or nativescript application too? I need push notification for a private app and I don't really want to renew a let's encrypt cert each month. Not to mention that I would use a cloud service, so for example I would have a heroku subdomain or in the worst case a dynamic dns subdomain. I want to solve this completely free... – inf3rno Nov 21 '20 at 01:30
  • I did not use certbot for long because there are other CA options, previously as I have read, Let's Encrypt certificates are valid for 90 days and issues certificates valid for 90 days. https://letsencrypt.org/docs/client-options/ It matters whether the application private or not private, and whether the service is with cloud base or not, and whether the subdomain is with heroku subdomain or not, or whether subdomain is with dynamic dns or not in that case. – Oleksii Kyslytsyn Nov 22 '20 at 10:53
  • I do not know however whether HTML or JavaScript via some API sends push notification to mobile device or not and if not why is that, because as I have read previously those frameworks(Apache Cordova and Telerik by Progress NativeScript) are extending the functionality of browsers by giving access via JavaScript and else to functionality of mobile devices' API, for example. So whether some HTML or JavaScript API can send request to send notification(no idea where you need to push it) probably to web browser or through web browser to operational system, that is what I do not know. – Oleksii Kyslytsyn Nov 22 '20 at 11:03
  • I do not know that probable blocking reason except a suggestion for a fair play actual parameter or the fair play formal argument since 2013 when I imagine a collection of probable applications in HTML and JavaScript, a collection of probable Apache Cordova applications, a collection of probable NativeScript applications, the collections of probable native applications for the plaforms in question and few other probable collections of applications. – Oleksii Kyslytsyn Nov 22 '20 at 11:24