What you'll learn: By the end of this lesson you will be able to say what makes a web app installable, write a web app manifest and link it, explain what each browser family does with it, build a custom install button around
beforeinstallprompt, describe the path a push message takes from your server to a notification, request permission and subscribe at the right moment, name the secrets and limits in Web Push (endpoint, VAPID, TTL), and design the notification so a late or lost message does no harm.
Think of a shop. Installing is the shop putting its own sign on your street: the same shop, with its own door and icon, found without typing an address. Push is its delivery van: it reaches you when you are not in the shop, but only if you gave your address, and a courier you do not control carries the parcel. The manifest is the sign. The service worker is the person at the door who is woken when the van arrives.
The running example is the order tracking page of a grocery marketplace (the front end of the ShopStream marketplace used in this course): a shopper installs the app and asks to be told when an order ships.
This lesson follows the lessons on service workers and their lifecycle and updates (named here in plain text) and builds on Service Worker Caching Strategies. It has no lab and no browser was used for it. Install prompts, permission prompts and push delivery need a real browser, a push service and a server, so every code sample is an example you do not run here, and each is labelled that way.
The core idea
- Installable means "has a manifest and meets the browser's criteria". The manifest is a JSON file that describes the app. A service worker is not required for installation, although most installable apps have one.
- Push is three parties. Your server, a push service run by the browser vendor, and the browser with your service worker. The service worker is started when a message arrives, even if no page is open.
- Permission is the gate, and the user holds it. A site can only notify people who opted in, so the moment and the wording of the request matter as much as the code.
Figure 1. The path of a push message
How to read this: the grey box is outside your control. Your server never talks to the device directly: it posts to a URL (the subscription endpoint) at the push service, which holds the message until the device can receive it.
Part 1: the manifest and installation
MDN defines a web application manifest as a JSON text file with information about a web application, whose most common use is to give the browser what it needs to install a progressive web app, such as the app's name and icon. A manifest contains one JSON object whose top-level keys are called members. You deploy it with a link in the document head:
<link rel="manifest" href="/app.webmanifest" />
If fetching the manifest needs credentials, MDN says the crossorigin attribute must be set to use-credentials, even for the same origin.
Illustration 1: the minimal example
A manifest for the order tracker. It is shown, not run: installation is done by a browser, and this lesson uses none.
{
"name": "ShopStream Orders",
"short_name": "Orders",
"start_url": "/orders",
"display": "standalone",
"theme_color": "#1a1a1a",
"background_color": "#ffffff",
"icons": [
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png" }
]
}
The name, background_color and icons members also define the splash screen, which MDN says is generated automatically.
What makes it installable
MDN's installability guide says that Chromium-based browsers (Chrome, Samsung Internet, Edge) require the manifest to include:
| Member | Requirement |
|---|---|
name or short_name |
One of them |
icons |
Must contain a 192px and a 512px icon |
start_url |
Present |
display and/or display_override |
Present |
prefer_related_applications |
false or absent |
The page must also be served over HTTPS (or from localhost or 127.0.0.1). A service worker is not a requirement for installation. This list is for Chromium; other browsers differ.
Figure 2. What each browser family does
without a manifest"] B -->|"Firefox"| F["No install from a manifest"] B -->|"Android"| A["WebAPK in Chrome (with GMS)
and Samsung Internet;
others: a browser shortcut"] B -->|"iOS 16.4+"| I["Share menu in Safari, Chrome,
Edge, Firefox, Orion"]
How to read this: "installable" depends on the page and the browser together. Treat installation as an enhancement: the app must still work in a tab.
Display modes and the install prompt
display chooses the window chrome. MDN lists fullscreen, standalone (looks like a standalone app, no URL bar), minimal-ui and browser (a conventional tab); the default is browser, and an unsupported mode follows the chain fullscreen, standalone, minimal-ui, browser.
Browsers promote installation themselves, but you can offer your own button. The pattern MDN describes: listen for beforeinstallprompt (fired on window once the browser decides the app is installable), cancel its default with preventDefault(), keep the event, and call its prompt() method from your own button. MDN adds that this is not supported on iOS. Shown, not run:
let installEvent;
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
installEvent = event;
installButton.hidden = false;
});
installButton.addEventListener("click", async () => {
installButton.hidden = true;
await installEvent.prompt();
});
Part 2: Web Push
MDN's Push API page says it lets a web app receive messages pushed from a server "whether or not the web app is in the foreground, or even currently loaded", and that for this the app needs an active service worker. The service worker is started as needed and receives a push event.
Figure 3. Subscribing and receiving
How to read this: permission and subscription happen once, on a user action. Everything after "send subscription" can happen with the page closed.
Permission and subscribing
Notification.requestPermission() resolves to granted, denied or default; MDN says default means the decision is unknown and the app acts as if permission was denied, and that the request should be made in response to user interaction. subscribe() calls should likewise follow a user gesture such as a click. MDN's example skips the request when permission is already denied: "if the user has denied notifications, and you want to be respectful there is no need to bother them anymore."
PushManager.subscribe() takes userVisibleOnly (the subscription is only used for messages whose effect is visible to the user) and applicationServerKey (an ECDSA P-256 public key the push service uses to authenticate your server). MDN notes that Chrome and Edge reject the promise if userVisibleOnly is not true.
Figure 4. The permission states
How to read this: only the first row needs your code to ask. The denied state is a result you design for, with another way to reach the user, such as email.
Illustration 2: the realistic example
The page side and the service worker side for "tell me when my order ships". Shown, not run: it needs a browser, a push service and a server holding the private key.
// Page: runs from a click on "Notify me when it ships".
notifyButton.addEventListener("click", async () => {
const permission = await Notification.requestPermission();
if (permission !== "granted") return;
const registration = await navigator.serviceWorker.ready;
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: SERVER_PUBLIC_KEY, // the ECDSA P-256 public key of your server
});
await fetch("/api/push/subscriptions", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(subscription), // JSON.stringify calls toJSON() on a PushSubscription
});
});
// Service worker: runs when a push message arrives, even with no page open.
self.addEventListener("push", (event) => {
const data = event.data?.json() ?? {};
event.waitUntil(
self.registration.showNotification(data.title ?? "Order update", {
body: data.body ?? "Open the app to see your order.",
data: { orderId: data.orderId },
}),
);
});
event.waitUntil() keeps the worker alive until the notification is shown. PushEvent.data gives a PushMessageData object; MDN's example reads it with json(). The showNotification() call is available only in secure contexts, and MDN's example calls it after requestPermission() returned granted.
What protects the message
- The endpoint is a capability. MDN's Push API page says the endpoint is a unique capability URL and that knowledge of it is all that is needed to send a message to your application, so it must be kept secret. RFC 8030 says capability URLs "act as bearer tokens". Store subscriptions on the server like credentials and never log them.
- Your server identifies itself with VAPID. RFC 8292 lets an application server voluntarily identify itself to a push service with a signed JWT in an
Authorizationheader (schemevapid). The token'saudclaim is the origin of the push resource,expis required and must not be more than 24 hours from the request, andsubshould carry a contact URI. The public key is theapplicationServerKeythe page passed tosubscribe(); if it is set, MDN says all messages must use VAPID. - The payload is encrypted end to end. RFC 8291 describes a scheme giving confidentiality and integrity from the application server to the user agent, so the push service cannot inspect or forge it.
- Delivery is not confirmed. RFC 8030 says a 201 response means the push message was accepted, and "does not indicate that the message was delivered to the user agent".
- Messages have a lifetime. The
TTLheader "suggests how long a push message is retained by the push service", and an optionalUrgencyheader can be sent with a delivery request.
If a subscription changes outside your control, the service worker gets a pushsubscriptionchange event, which MDN says may be a browser refresh but also a revoked or lost subscription. MDN's example resubscribes and sends the new subscription to the server, and warns that a fetch() there will not work offline. MDN marks the event as not Baseline, so the server must also cope with endpoints that stop working.
iOS and iPadOS
WebKit's announcement for iOS and iPadOS 16.4 says push permission applies to web apps added to the Home Screen, and that the permission request must come from direct user interaction, such as a button your app provides. It describes the feature as the standard Push API, Notifications API and Service Workers working together. So on iOS, installing is a prerequisite of push, not a separate feature.
The failure case: the message that arrives late
Illustration 3: a stale notification
A shopper's phone is off for three hours. The server sends "your order is out for delivery" and gets a 201 from the push service, which accepted the message. The phone reconnects, and the notification appears after the order was delivered. Nothing broke: the message was sent with a long TTL, so the push service was allowed to retain it, and a 201 says only that the message was accepted.
Two design rules follow, both from the protocol:
- Set
TTLto the useful life of the message. A "starts in ten minutes" notice is worthless after ten minutes. RFC 8030 describesTTLas the suggestion of how long the push service retains a message. - Do not make the notification the source of truth. Put an order id in the notification data, and when the shopper opens it, load the current status from the API. The page is the truth; the notification only says there is something to look at.
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| Ship a manifest | Installable on browsers that support it | Icons and metadata to keep current; behaviour differs per browser |
| Custom install button | Controlled timing and wording | Not supported on iOS; a code path to maintain |
| Ask for push on page load | More prompts shown | An unprompted request; a denial closes the channel |
| Ask on a click, with a reason | Opt-ins with a reason | Fewer prompts shown |
Short TTL |
No stale alerts | A message may never be delivered |
Long TTL |
Delivered even after a long offline period | Late, possibly wrong, notices |
Build it
This lesson has no lab (lab type none). Installation, the permission prompt and push delivery need a real browser, a push service and a server holding keys, and the lesson uses no browser automation. The manifest and the three code samples above are examples you do not run here. The lesson captured no output and makes no claim about how any browser behaved.
In practice: order notifications
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
Shoppers want to know when an order ships and when it is out for delivery, without keeping a tab open. Email is read late, so the team wants an installable tracker with push.
Starting architecture
Figure 5. Asking on load, sending everything
How to read this: the warning boxes mark the choices to revisit: a permission prompt before the shopper has a reason to accept, and messages with a long lifetime for events that expire.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Email only | No permission, works everywhere | Read late | Missed time-sensitive updates |
| Push, asked on a click | Reaches closed apps, opt-in with a reason | Subscription storage, VAPID keys | Denied or unsupported browsers |
| Push plus email fallback | Covers denied and unsupported cases | Two channels to keep consistent | Duplicate alerts |
The decision
| Field | Decision record |
|---|---|
| Context | Time-sensitive order updates; many shoppers on mobile; some browsers cannot install or receive push. |
| Decision | Ship a manifest for the tracker. Offer "Notify me when it ships" as a button; on click request permission and subscribe with userVisibleOnly. Send only "shipped" and "out for delivery", with a TTL matched to each, and open the order page from the notification. Keep email for everyone who is denied or unsupported. |
| Consequences, good | A reason to opt in, less noise, no stale notice taken as truth. |
| Consequences, bad | Subscriptions to store and prune; two channels; differing browser behaviour. |
| Revisit when | Notification volume grows, or a new browser changes the install or permission rules. |
Rollout and verification
- Test the manifest against the member list for each browser family you support.
- Check on real devices that the prompt appears only after the click and a denial leaves the page working.
- Send a test message with a short
TTLto a device that is offline and confirm it does not appear late. - Verify the click path: the notification opens the order page, which reads the current status.
The 2 a.m. failure
After an outage, the sender job replays a queue of old "out for delivery" messages with a long TTL. Shoppers receive notices for orders delivered hours earlier and open support tickets.
First three checks: (1) look at the TTL the sender sets; (2) check whether replayed events carry their original time; (3) see whether the notification text claims a current state. Mitigation: drop replayed events older than their useful life before sending. Follow-up: set the TTL per message type and make the notification say "check your order" rather than state a status.
Architect's notes
- Installation and push are separate decisions. Push needs a service worker and a granted permission, not a manifest as such (on iOS, installation too).
- Earn the permission. Ask on a click, explain the benefit and keep a fallback channel.
- Treat the endpoint like a credential and prune dead subscriptions.
- A push is a hint, not a record. The page holds the truth.
Common mistakes
- Requesting permission on page load.
- Assuming a 201 means the message arrived.
- A
TTLlonger than the message is useful. - Logging subscription endpoints.
- Forgetting
waitUntil()in thepushhandler. - No fallback for a denied or unsupported browser.
Key takeaways
- Installable means a manifest plus the browser's criteria; Chromium wants name, 192 and 512 icons,
start_urlanddisplay, over HTTPS. No service worker is needed to install, but one is needed to receive push. - Push goes application server, push service, service worker, notification, and works with no page open.
- Permission and
subscribe()belong behind a user gesture;deniedis a state to design for. - The endpoint is a secret; VAPID identifies your server; the payload is encrypted; a 201 is not delivery.
- Set a
TTLthat matches the message's useful life.
Practice exercises
Exercise 1: Starter (30 min). Write a manifest for a site you know and check each Chromium requirement from the table against it.
Exercise 2: Intermediate (2 hours). For three notification types in a shop (shipped, delivered, price drop), choose a TTL and say what the shopper should see if it arrives after that time.
Exercise 3: Advanced (half day). Design the server's subscription table: what you store, and how you prune expired or revoked subscriptions.
Related reading
In this course:
- Service Worker Caching Strategies: what the worker can do with requests.
- Caching Across the Stack: the caches around the worker.
- Browser Storage Options: where an installed app keeps data.
- Threat Modeling for Front Ends: the endpoint and the permission as assets.
- Client Retries and Backoff: the retry logic for the subscription request.
Next in this module, in plain text: offline-first sync and conflict resolution, and offline queues and background sync.
Official documentation
- MDN: Making PWAs installable: criteria, browser differences,
beforeinstallprompt. - MDN: Web app manifest: members and how to link a manifest.
- MDN: Push API and PushManager.subscribe(): subscriptions,
userVisibleOnlyand the server key. - RFC 8030: Generic Event Delivery Using HTTP Push: the push protocol,
TTLand capability URLs. - RFC 8292: VAPID and RFC 8291: Message Encryption for Web Push: identifying the server and protecting the payload.
- WebKit: Web Push for Web Apps on iOS and iPadOS: push on Home Screen web apps.