CD to the root folder of the project and run yarn to install all Node packages.
Then run yarn start to start the project and automatically launch a browser.
Click Subscribe Web Push and copy a subscription JSON object in a text box.
Use subscription object on a server side to send push notification.
This project requires Node.js version >= 14.
Send push notification from a server
Set a push subscription object that we get after a user's subscribed web push in PushMessageFromServer.js
Then execute the following command:
$ node PushMessageFromServer.js
Trouble shooting
Notification does not always show as banner on Windows.
Try to turn off focus assist.
No push notification message at all
You may need to manually update service worker. Open Chrome developer tool with ctrl+shift+i keys and then go to application tab.
Then click Service Workers node > Skip waiting service worker.
Key concept
Generate publish and private key public and private keys with the following code