The Big Picture of How It Works: What You Should Know Before Implementing Web Push

The Big Picture of How It Works: What You Should Know Before Implementing Web Push

Explains how Web Push works before you implement it: endpoint-based targeting, VAPID signing, payload encryption, and the flow from subscription to notification, plus what goes where in a React SPA and Web API.
2026.11.09

This page has been translated by machine translation. View original

When you try to add notifications to a web app and start looking into Web Push, terms like Service Worker, endpoint, VAPID, and p256dh all show up at once. If you follow a library's sample, it will work, but you tend to proceed without really understanding what each of them is for and what you need to implement where.

This article is for engineers who have experience developing web apps but are new to Web Push. It summarizes the overall picture of the mechanism that is worth knowing before you start implementing. Starting with the players and the rough flow, it goes through signing and encryption, then the subscription and sending flows in order, and then applies them to a React SPA plus Web API setup to sort out what to write where. The target is conventional Web Push that uses a Service Worker.

The specifications and official documents were researched as of November 9, 2026. I have written only what I could confirm, and I state explicitly where something could not be confirmed.

1. The Big Picture

What Is Web Push?

Web Push is a mechanism in which a website sends a message from the server side to the user's browser, and the browser displays it as an OS notification. On a Mac it is a banner that appears at the top right of the screen as in the image below, and on an iPhone it appears on the lock screen or in Notification Center, looking the same as a notification from a native app.

A Web Push notification displayed in Chrome on Mac

Since it is the browser or OS that displays it, not the page, it appears even when the site's tab is not open.

Why Does It Reach the Intended Browser?

You can probably imagine that your server, a push delivery service, and the user's browser cooperate to deliver a notification. What is hard to grasp is the next part: out of all the browsers in the world, how does the delivery service target and deliver to one specific browser?

The answer lies in the endpoint, which the browser receives as a result of first "subscribing" to the delivery service.

  1. When the user allows notifications, the browser makes an arrangement with the delivery service: "receive notifications for this site." This is called a subscription
  2. The delivery service issues an endpoint, a URL dedicated to this subscription, and returns it to the browser. The delivery service remembers internally which browser this endpoint belongs to
  3. The browser hands the endpoint to your server. Your server stores the endpoint linked to the user who was logged in at the time. The endpoint itself contains no user information, so this linking is your server's job
  4. When you want to send a notification, your server retrieves the target user's endpoint and sends the notification to that URL over HTTP
  5. The delivery service identifies the corresponding browser from the endpoint and delivers it over the connection it maintains with that browser

In other words, "which browser it reaches" is determined by which endpoint your server sends to, and "which browser an endpoint is" is known by the delivery service. Your server holds the "user → endpoint" mapping, and the delivery service holds the "endpoint → browser" mapping.

The connection between the browser and the delivery service is maintained independently of the page, so step ⑤ arrives even when the page is closed. Polling and WebSocket are communication "between your server and the page," so the difference is that they end when the page is closed.

Also, in step ③ the browser hands over, together with the endpoint, the keys used to encrypt the body. The keys are covered in Chapter 3.

This mechanism is defined by two specifications. The API the browser provides to the page (subscribe() in ①–③ and the shape of the subscription information) is the W3C Push API, and the HTTP your server sends to the delivery service (how to send in ④) is IETF RFC 8030. The delivery from the delivery service to the browser (⑤) uses a proprietary route that differs by browser vendor. The following chapters look at this flow in more detail, step by step.

2. Opening Up the Browser

The "user's browser" in the figure in Chapter 1 is actually divided into three parts: the push reception mechanism owned by the browser itself, the JavaScript running in that site's page, and the Service Worker. Keeping the same layout as in Chapter 1, let's open the browser box and redraw it.

The three colored items are the code you write as your web app. Everything else is the browser itself and the browser vendor's services, which you don't touch yourself.

  • JavaScript in the page: Triggered by a user action, it calls the browser's subscribe() to start a subscription. It is also this code that sends the returned endpoint to your server. It is not involved in communication between the browser and the delivery service
  • Push reception mechanism (the browser itself): This is the part that actually communicates with the delivery service. It creates the subscription, maintains the connection with the delivery service, decrypts incoming messages, and passes them to the Service Worker. It keeps running even when the page is closed
  • Service Worker: It receives incoming messages and displays notifications, and decides which page to open when a notification is tapped. It is started by the browser when a message arrives or a notification is tapped
  • Your server: It stores endpoints linked to users, and issues HTTP requests to the delivery service when sending notifications
  • Push delivery service: It issues endpoints and delivers messages that arrive from your server to the browser corresponding to the endpoint

I wrote "Push reception mechanism" as the browser itself, but depending on the environment the OS takes over this role. In Chrome on Mac, Chrome itself connects to the delivery service. On iPhone, the OS maintains the same APNs connection as native apps, and Safari maps it to the Web Push subscription. Notes on using it on iPhone are covered in Chapter 7.

Supplement: What Is a Service Worker?

A Service Worker is JavaScript that the browser runs separately from the page. Ordinary JavaScript ends when the tab is closed, but a Service Worker is registered against a site (origin), and even when no tab is open, it is started when the browser hands it an event, does its processing, and then stops again. It cannot touch the DOM and communicates with pages by messages. It was originally created for offline support and cache control, and Web Push borrows that property of "being able to run code even without a page."

The reason it is needed for Web Push is simple: when a notification arrives while the page is closed, some code has to run somewhere to display the notification and decide the URL to open on tap. When the push reception mechanism receives a message from the delivery service, it starts that site's Service Worker and passes it a push event. The Service Worker displays the notification there, and when the user taps the notification, it is called with a notificationclick event and decides which page to open.

3. Notifications Are Signed and Encrypted

Before looking at subscription and sending in detail, let's cover the mechanisms that apply to the whole thing. The figure in Chapter 1 showed only your server sending a notification to the delivery service and the delivery service delivering it to the browser. That alone causes two problems.

  • Anyone who knows the endpoint can send a notification to that browser
  • The delivery service can read the entire body of the notification

Web Push prevents the former with a signing mechanism called VAPID, and the latter with an encryption mechanism called Message Encryption. They are defined in separate RFCs and use separate keys.

Mechanism What it prevents Who creates the key What the key does
VAPID (RFC 8292) Anyone other than you sending notifications You (one pair shared by all users) Your server signs, and the delivery service verifies
Message Encryption (RFC 8291) The delivery service reading the body The browser (per subscription) Your server encrypts, and the browser decrypts

In both mechanisms, the exchange of keys is done at subscription time, and the keys are used at sending time. After looking at how each key travels in Sections 3.1 and 3.2, Section 3.3 checks where in the actual HTTP request the signature and encryption apply.

3.1 VAPID: Verifying Who Sent It

Before deploying, you create one VAPID key pair. The private key is kept only on your server, and the public key is written into the page's JavaScript.

  1. At subscription time. The page's JavaScript passes the public key to subscribe(), and the browser delivers it to the delivery service. The delivery service remembers the issued endpoint tied to this public key
  2. At sending time. Your server sends to the endpoint with a signature made with the private key and the public key attached. The delivery service checks whether the public key is the same as the one registered at subscription time and whether the signature is correct

Anyone can know the public key, but only your server, which holds the private key, can create the signature. Therefore, even if the endpoint leaks, others cannot send notifications to it.

However, what VAPID guarantees is only that "the sender is your server." Whether that endpoint really belongs to the user you want to notify is something the delivery service cannot know, and depends on whether the "user → endpoint" mapping your server stores is correct.

3.2 Message Encryption: Making the Body Readable Only by the Destination Browser

Here it is the browser that creates the keys, which is the opposite direction from VAPID. At subscription time, the browser gives your server "the right to encrypt and write messages addressed to it," while keeping the right to read them.

  1. At subscription time. The browser creates a key pair for each subscription and hands the public key (p256dh), together with auth, which acts as a shared secret, to your server. The private key never leaves the browser
  2. At sending time. Your server encrypts the body with p256dh and auth and sends it. The delivery service carries it without being able to read the contents
  3. At receiving time. The browser decrypts it with its own private key and auth

auth is a value known only to the browser and your server, and is mixed in when generating the encryption key. Since the public key is a value that is assumed to be fine to make public, it is enough to think of it as a separate value kept secret in addition.

Note that encryption hides only the body. "Which server sent to which browser and when" is visible to the delivery service.

3.3 What's in the Request You Send

VAPID in Section 3.1 and Message Encryption in Section 3.2 apply to different places within the single HTTP POST that your server sends to the endpoint. Let's look at the request that goes out at sending time and check what we've covered so far.

endpointに送るHTTP POSTの中身(値は例)
POST /fcm/send/dU5-cS8TRNY:APA91b... HTTP/1.1
Host: fcm.googleapis.com

# ── VAPID (RFC 8292): verified by the delivery service. Rejected if tampered with ──
Authorization: vapid t=<JWT:aud・exp・sub をVAPID秘密鍵で署名>, k=<VAPID公開鍵>

# ── Delivery instructions (RFC 8030): read by the delivery service ──
TTL: 86400
Content-Encoding: aes128gcm

# ── Message Encryption (RFC 8291): the delivery service cannot read it. Only the destination browser can decrypt it ──
<p256dhとauthで暗号化された本文>
  • Authorization header: What is signed by VAPID is a JWT containing the destination (aud), the expiration (exp), and the contact (sub). The delivery service verifies this to confirm the sender. The body of the notification is not covered by this signature
  • body: The notification body is encrypted and placed here. The delivery service cannot read the contents, and only the destination browser can decrypt it. If it has been tampered with along the way, decryption on the browser side fails

Signing and encryption are different operations applied to different places, so the delivery service never decrypts the body using the VAPID key. If you use a library such as web-push for Node.js, the library assembles this request.

4. Subscription in Detail

This looks in detail at steps ①–③ of Chapter 1: from the user pressing a button until the subscription information is saved on your server. The key exchanges seen in Chapter 3 all happen within this.

The route is as shown in the figure. The following three points are worth keeping in mind for implementation.

  • Complete the Service Worker registration first. It is the Service Worker that receives messages after the page is closed, so the subscription is created tied to the Service Worker registration
  • Start the subscription from a user action. A subscription requires notification permission. Safari requires that the subscription request be made within a user action such as a button click
  • You pass two things to subscribe(). userVisibleOnly: true is a promise that "a notification will always be displayed when a message is received," and it is required in Chrome. applicationServerKey is the VAPID public key from Section 3.1; the specification allows omitting it, but it is effectively required in Chrome

The contents of the subscription information (PushSubscription) returned from the browser are as follows.

Value Contents What it is used for
endpoint The destination URL issued by the delivery service The destination your server POSTs notifications to
expirationTime The subscription's expiration. null in Chrome If there is an expiration, re-subscribe before then
keys.p256dh The public key of the key pair created by the browser Encrypting the body. Appears in Section 3.2
keys.auth A 16-byte shared secret created by the browser Same as above

What matters here is that the subscription information contains no information about who the user is. It contains only the destination and encryption information. The Push API specifies that no one other than the delivery service should be able to extract user information from an endpoint. That is why linking the subscription to the user identified by the login session, and storing it, is your server's job.

4.1 endpoint: A Destination Issued per Subscription

An endpoint is not a destination shared by all browsers. It is a URL that the subscribing browser's delivery service issues for each individual subscription. When you subscribe in Chrome, it looks like this.

https://fcm.googleapis.com/fcm/send/dU5-cS8TRNY:APA91bFPsN-cAs8L...(長いランダム文字列)

The host part is determined by which delivery service issued it. For Chrome it is fcm.googleapis.com, and for iPhone it is under *.push.apple.com. The long random string that follows acts as a token that the delivery service uses to tell "which subscription this is addressed to." Your server does not need to interpret its contents; if you POST to the stored URL as is, the delivery service that issued the URL delivers it to the corresponding browser.

Because it is a token, the endpoint is a different value for each subscription.

  • Even for the same user, subscribing in Chrome on Mac and on iPhone creates two separate endpoints
  • Even in the same browser, re-subscribing changes it to a new endpoint

For that reason, your server should store endpoints so that one user can have multiple of them, and update to the new endpoint when the user re-subscribes.

5. Sending Through Display in Detail

This covers steps ④ and ⑤ of Chapter 1: from the moment your server thinks "I want to send a notification to this user" until the user taps the notification.

The route is as shown in the figure. The following four points are worth keeping in mind for implementation.

  • 201 means "we have accepted it," not "we have delivered it." You specify the maximum time the delivery service holds the message with the TTL header. If the browser is offline, it holds the message during that time and delivers it when the browser reconnects
  • Neither delivery nor prompt delivery is guaranteed. The route from the delivery service to the browser is vendor-specific: FCM for Chrome and APNs for Safari
  • Subscriptions can expire. Sending to an expired subscription returns 404 or 410, so your server deletes that subscription
  • Always display a notification in the push event. This is because you subscribed with userVisibleOnly: true. Safari revokes notification permission for sites that do not display a notification immediately after receiving a push

event.data contains the plaintext after the browser has decrypted it. You do not need to write decryption code in the Service Worker.

5.1 How Tapping a Notification Opens the Relevant Page

A common behavior is that when you tap a notification from a website, the page corresponding to that notification opens. It is the Service Worker's job to decide what happens when the notification is tapped.

If you want to open the page for a notification, the work is divided between the server and the Service Worker as follows.

  • Server: Include the path of the page to open in the notification body and send it. The server knows what happened, so the server also decides where to open. There is no fixed format for the body, so you decide it yourself, such as { "title": "新着コメントがあります", "url": "/posts/123" }
  • Service Worker: When displaying the notification in the push event, store the received path in the data of showNotification(). In the notificationclick event, extract that path and open it with clients.openWindow()

In the opened page, check the login state and viewing permissions as usual before displaying the content.

6. Applying This to a React SPA and Web API

Let's apply the mechanism so far to a common setup. As an example, consider a setup with a React SPA and a separately running Web API.

Where What to write Related chapter
React component Register the Service Worker in advance, and on a button click pass the VAPID public key and call subscribe(). Send the returned subscription information to the API Chapter 4
public/sw.js Display the notification in the push event, and open the page at the URL in the payload in the notificationclick event Chapter 5, Section 5.1
POST /api/push-subscriptions Save the logged-in user and the subscription information in the table Chapter 4
Notification sending process Call it from the process you want to notify about, such as "a comment was posted." Retrieve the target user's subscription information from the table, put the path of the page to open on tap into the body, encrypt and sign, and POST to the endpoint. Delete rows that return 404 or 410 Chapter 3, Chapter 5, Section 5.1
Configuration Put the VAPID public key in the frontend's environment variables and the private key in the Web API's secrets Section 3.1

There are three points about the structure.

  • Do not include the Service Worker in the React bundle; make it a separate file. A Service Worker is a script that runs separately from the page, and its scope is determined by the location of the registered file. If you place it at public/sw.js and serve it from the site root, the whole site is covered
  • Make the table able to hold multiple rows per user. As in Section 4.1, the endpoint changes for each browser and each re-subscription
  • Leave encryption and signing in the sending process to a library. In Node.js, something like web-push handles it. For Chrome on Mac, as long as you use VAPID, there is no work to create an account or project on Google's side

If you design it so that the notification body carries only minimal information such as "there is something new," and the page opened from the notification fetches the details from the API, you won't have to worry about how to handle the body. On the page side, you can check the login state and viewing permissions as usual.

7. Notes on Using It on iPhone

The mechanism so far follows the same standards on iPhone. The delivery service is Apple's (the endpoint is under *.push.apple.com), but what it accepts is the same Web Push standard, so your server's code does not change. However, you need to be careful about the conditions before you can start using it.

It can be used only in web apps added to the Home Screen. On iPhone, Web Push can be used only in web apps that have been "Added to Home Screen" from Safari, and iOS 16.4 or later is required. Notification permission is also requested starting from a user action, such as a button click, within that app. You cannot subscribe in a regular Safari tab, so for iPhone you need to provide guidance asking users to add the app to the Home Screen.

HTTPS is required to test it. Browsers on Mac treat http://localhost as a secure origin as an exception, so during development you can test Service Workers and Push over plain HTTP. On the other hand, connecting from an iPhone to the Mac with a LAN IP address such as http://192.168.x.x:3000 is not localhost, so it does not count as a secure origin. To test on an iPhone, you need to either make it trust a self-signed certificate or prepare HTTPS with a proper certificate, for example through a tunnel service.

Supplement: Differences from APNs for Native Apps

APNs is also used when sending notifications to native iPhone apps, but that is a completely different method, using authentication keys issued by Apple and sending to APNs's own API. Web Push also uses Apple's APNs mechanism for delivery to the device, but the entry point visible from your server is an endpoint that follows the Web Push standard. Because the names are the same, they are easy to confuse, but when implementing Web Push you do not need to read the APNs documentation for native apps.

Supplement: Declarative Web Push

The Service Worker in the conventional method is boilerplate code that just displays a notification in the push event and opens a URL on tap. Even so, you have to place it in your own origin and write it yourself. As an answer to this state of "it's boilerplate, yet you write it yourself every time," WebKit introduced Declarative Web Push, which allows subscribing and displaying notifications without a Service Worker, in iOS 18.4 and iPadOS 18.4, and made it available on macOS as well from Safari 18.5. If you make the payload a specified JSON format, the browser displays the notification directly. WebKit explains that messages in this format are processed with the conventional Service Worker method in browsers that do not support it. Since this article targets the conventional method, I'll just add the note that it cannot be said that "every Web Push requires a Service Worker."

Summary

  • The reason notifications arrive even when the page is closed is that the browser itself (the OS on iPhone) maintains the connection with the delivery service, and starts the Service Worker with the incoming message to show the notification
  • When a notification is tapped, too, the browser merely tells the Service Worker that it was tapped. The page for the notification opens because the Service Worker opens the URL that the server sent
  • Notifications are covered by VAPID signing and Message Encryption. Even if the endpoint leaks, others cannot send, and the delivery service cannot read the body. Both keys are exchanged at subscription time
  • An endpoint is a destination URL that the delivery service issues for each subscription, and it changes for each browser and each re-subscription. The only thing linking users and subscriptions is your server
  • What you write yourself is three things: the frontend that creates the subscription, the Service Worker that shows notifications, and the API that stores subscriptions and sends. The sending code is common regardless of the delivery service, and on iPhone a web app added to the Home Screen is a prerequisite

Conclusion

When I followed Web Push along its specifications, the boundary between the range defined by the Web Push standards and the range that browser vendors build on their own became clear. Sending from your server to the delivery service, signing, and encryption are unified by the standards, while delivery from the delivery service to the browser is a vendor-specific implementation. Once you can see this boundary, you can design by separating how far your code is responsible and where you leave things to the browser and delivery service.

I hope this blog is useful to someone.

References

Share this article