I am trying to implement push messaging using firebase. For this, I have followed google doc as well as script that google shared on github. You can find the same on below URL:
Firebase Push Messaging Source Code
And also followed below tutorials:
How to Setup Push Messaging on Localhost
Below is my folder structure:
root
|--push-demo
| |
| |--index.html
| |--index.js
|
|--firebase-messaging-sw.js
I have followed everything that describes in all the above links. As per requirement, I have also done following things:
- Enable SSL on localhost
- Put firebase-messaging-sw.js in root folder
- Path for all the included JS files are correct. I mean when I open them in browser, browser is showing me JS content.
- Generated VAPID key from firebase console and used the same.
- Also enable allow-insecure-localhost in chrome
After doing everything correctly, I am getting below error:
FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('https://localhost/firebase-cloud-messaging-push-scope') with script ('https://localhost/firebase-messaging-sw.js'): An SSL certificate error occurred when fetching the script. (messaging/failed-service-worker-registration).
Can someone please guide me about what is wrong at my side? I have looked many solutions on forums, and everyone is saying about either enable SSL on localhost or put your service file in root folder. But still I am getting error.
Thanks in advance.