Web Push Notifications
Web apps can send real notifications to phones and desktops without an app store. Here is how the pieces fit, what iPhone requires, and how not to get muted on day one.

Key takeaways
- Web push needs four parts: a service worker, a VAPID key pair (private key in Secrets), a table of subscriptions, and a server function that sends.
- On iPhone and iPad, web push works only after the user adds your web app to the home screen, on iOS 16.4 or later.
- Ask for permission after a meaningful action, never on page load, and delete subscriptions the push service reports as gone.
Web push notifications let a website send notifications to a user's device even when the site is closed. They work through three browser standards: a service worker that runs in the background, the Push API that gives each browser a unique subscription, and the Notifications API that shows the message. Your server signs each message with a VAPID key pair and sends it to the browser vendor's push service, which delivers it. Chrome, Edge and Firefox on desktop and Android support this, as does Safari on Mac. On iPhone and iPad, web push works only for web apps the user has added to their home screen, on iOS and iPadOS 16.4 or later.
What you will build
A "Notify me" setting in your web app that, once allowed, delivers useful pings: "Your order is out for delivery", "Practice moved to 6 pm", "It is your turn" in a turn-based game, "3 new replies to your post". Tapping a notification opens the right page in your app. Users can turn categories on and off, and you stop sending to devices that have gone away.
This guide is about web apps. Expo mobile apps use native push notifications, which is a separate setup with its own credentials.
What you need
- A published site on HTTPS. Service workers only run on secure origins. Published Startbase sites are HTTPS on startbase.app or your own domain.
- A web app manifest with your app's name, icons and display set to standalone. iPhone needs it for the home-screen install that unlocks push, and it makes the install look like a real app everywhere.
- A VAPID key pair. Generate it once with a Web Push library. The public key goes in your frontend code (it is meant to be public). The private key goes in your backend Secrets, for example as VAPID_PRIVATE_KEY, along with a contact address the push services can reach.
- A backend to store subscriptions and send messages: a table plus an edge function.
- Optionally, a hosted push service (OneSignal and similar) if you would rather not run sending yourself. That means an account with them and their keys in Secrets, in exchange for dashboards and segmentation.
The data flow
- 01Register. Your app registers a service worker file (for example /sw.js) when it loads.
- 02Ask, at the right moment. After the user does something that makes notifications obviously useful (places an order, joins a team, starts a game), show your own small explainer: "Get a ping when your order ships?" Only if they tap Yes do you call the browser's permission request. On iPhone the request must come from a tap.
- 03Subscribe. With permission granted, the service worker's push manager subscribes using your VAPID public key and returns a subscription: an endpoint URL plus two keys (p256dh and auth).
- 04Store. Save it in a push_subscriptions table: user_id, endpoint (unique), p256dh, auth, user agent, created_at, last_success_at. One user can have several rows: a phone, a laptop, a work browser.
- 05Send. When something happens, your server function loads the user's subscriptions, signs a small JSON payload (title, body, url, tag) with the private key, and posts it to each endpoint. Keep payloads small: push services cap them at roughly 4 KB.
- 06Show. The service worker receives the push event and calls showNotification. Its notificationclick handler focuses an open tab or opens the url from the payload.
- 07Clean up. If a push service answers 404 or 410, that subscription is dead (the user revoked permission, cleared data or uninstalled). Delete the row.
The iPhone rules, plainly
- Home screen first. In Safari on iPhone, a regular tab cannot subscribe. The user must open the Share menu, choose Add to Home Screen, then open your app from that icon. Only there can you ask for notification permission.
- Version. iOS and iPadOS 16.4 or later. Older devices simply will not offer it, so detect support (the PushManager object exists, and the page is running standalone) before showing your Notify me button.
- Teach the install. Most people do not know Add to Home Screen exists. Show iPhone users a short illustrated hint when they reach for notifications, rather than a button that silently does nothing.
Browser behavior changes between releases, so test on a current iPhone before you promise anything in your marketing. The tradeoffs of home-screen web apps in general are covered in PWA vs native app.
A brief you can paste
Add web push notifications to the club app. Add a web app manifest (standalone, our icons) and a service worker that shows notifications and opens the url in the payload on click, focusing an existing tab if one is open. In Settings, add a Notifications section with toggles for Schedule changes and New messages. When a user turns one on, first show our own one-line explainer, then request permission from that tap; subscribe with our VAPID public key and save the subscription in a push_subscriptions table (unique endpoint, user id, keys, created_at). On iPhone, if the app is not running from the home screen, show a short illustrated guide to Add to Home Screen instead. Create an edge function send-push that takes a user id, title, body, url and tag, signs with the VAPID private key from Secrets, sends to all that user's subscriptions, and deletes any that return 404 or 410. Call it when an admin changes a practice time.
Pitfalls
- Asking on page load. Browsers increasingly hide or auto-block prompts that appear before any interaction, and users who click Block are nearly impossible to win back. The two-step ask (your explainer, then the browser prompt) is the fix.
- Sending everything. Each notification spends trust. Start with the two or three events users genuinely want, let them choose categories, and add quiet hours. A sensible default: no more than a few per day per user.
- Never cleaning subscriptions. Dead endpoints pile up, slow sends and inflate your "reach". Delete on 404 or 410 and consider pruning rows with no success in 60 days.
- Leaking the private key. If VAPID_PRIVATE_KEY ends up in frontend code, anyone can push to your users. It stays in Secrets, read only by the sending function. Our API keys and secrets guide explains why.
- Relying on push for critical messages. Delivery is best-effort: devices are off, notifications are muted, focus modes hide them. Anything that must arrive (a booking change, a receipt) should also go by email.
- Scheduled reminders without a schedule. "Remind me an hour before" needs something running on the server at the right time. A database job that checks every few minutes for due reminders and calls your send function covers it.
Frequently asked questions
Do web push notifications work on iPhone?
Yes, on iOS and iPadOS 16.4 or later, but only for web apps the user has added to the home screen and opened from there. A regular Safari tab cannot subscribe, and the permission request must come from a tap.
What are VAPID keys?
A public and private key pair that identifies your server to browser push services. The public key goes in your web app to create subscriptions; the private key signs each message and must stay on the server.
Do I need a service like OneSignal for web push?
No. A service worker, a VAPID key pair, a subscriptions table and a server function that sends are enough. Hosted services add dashboards and targeting if you want them, in exchange for an account and their keys.
Why did my web push notifications stop arriving?
Common causes: the user revoked permission or cleared site data, the subscription expired, or the private key changed. Push services answer 404 or 410 for dead subscriptions; delete those and ask the user to re-enable.

