Trying Out Web Push Notifications

Trying Out Web Push

Notifications matter for web services. Beyond in-app notices or email, web push is another channel worth exploring. Here is a lightweight implementation flow.

Flow

  1. Load serviceWorker.js.
  2. In the service worker, register a handler for the push event.
  3. User visits the page.
  4. Browser prompts for permission; the user grants it.
  5. Use the public key to subscribe.
  6. On success you receive an endpoint and token.
  7. Send the endpoint/token to your server.
  8. When you need to notify the user, have the server POST to the endpoint with the token (encrypt the payload).
  9. If the service worker is active, it catches the push event and displays the notification.

Sample code

https://github.com/hirotoyoshidome/exp-web-push

Notes

Closing

Setting up push required more steps than I expected, but adding another notification channel can be worthwhile.