This section describes the status of this
document at the time of its publication. A list of current
W3C
publications and the latest revision of this technical report can be found
in the
W3C
technical reports index
at
https://www.w3.org/TR/.
Publication as a Working Draft does not
imply endorsement by
W3C
and its Members.
This is a draft document and may be updated, replaced or obsoleted by other
documents at any time. It is inappropriate to cite this document as other
than work in progress.
This document was produced by a group
operating under the
W3C
Patent
Policy
.
W3C
maintains a
public list of any patent disclosures
made in connection with the deliverables of
the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains
Essential Claim(s)
must disclose the information in accordance with
section 6 of the
W3C
Patent Policy
.
This document is governed by the
03 November 2023
W3C
Process Document
.
The Push API allows a web application to communicate with a
user agent
asynchronously. This allows an
application server
to provide the
user agent
with time-sensitive information whenever that information becomes known, rather than
waiting for a user to open the web application.
As defined here,
push services
support delivery of
push messages
at any time.
In particular, a
push message
will be delivered to the web application even if that
web application is not currently active in a browser window: this relates to use cases in
which the user may close the web application, but still benefits from the web application
being able to be restarted when a
push message
is received. For example, a
push
message
might be used to inform the user of an incoming WebRTC call.
A
push message
can also be sent when the
user agent
is temporarily offline.
In support of this, the
push service
stores messages for the
user agent
until
the
user agent
becomes available. This supports use cases where a web application
learns of changes that occur while a user is offline and ensures that the
user agent
can be provided with relevant information in a timely fashion.
Push messages
are
stored by the
push service
until the
user agent
becomes reachable and the
message can be delivered.
The Push API will also ensure reliable delivery of push messages while a
user agent
is actively using a web application, for instance if a user is actively using the web
application or the web application is in active communication with an
application
server
through an active worker, frame, or background window. This is not the primary
use case for the Push API. A web application might choose to use the Push API for
infrequent messages to avoid having to maintain constant communications with the
application server
.
Push messaging is best suited to occasions where there is not already an active
communications channel established between the
user agent
and the web application.
Sending
push messages
requires considerably more resources when compared with more
direct methods of communication such as the
Fetch API
or [
WebSockets
].
Push
messages
usually have higher latency than direct communications and they can also be
subject to restrictions on use. Most
push services
limit the size and quantity of
push messages
that can be sent.
Dependencies
The
web push protocol
[
RFC8030
] describes a protocol that enables
communication between a
user agent
or
application server
and a
push
service
. Alternative protocols could be used in place of this protocol, but this
specification assumes the use of this protocol; alternative protocols are expected to
provide compatible semantics.
The
Content-Encoding
HTTP header, described in Section 3.1.2.2 of
[
RFC7231
], indicates the content coding applied to the payload of a
push message
.
Concepts
Application server
The term
application server
refers to server-side components of a web
application.
Push message
A
push message
is data sent to a web application from an
application
server
.
A
push message
is delivered to the
active worker
associated with the
push subscription
to which the message was submitted. If the
service worker is not currently running, the worker is started to enable delivery.
Push subscription
A
push subscription
is a message delivery context established between the
user agent
and the
push service
on behalf of a web application. Each
push subscription
is associated with a
service worker registration
and a
service worker registration
has at most one
push subscription
.
A
push subscription
has an associated
push endpoint
. It
MUST
be the
absolute URL exposed by the
push service
where the
application server
can
send
push messages
to. A
push endpoint
MUST
uniquely identify the
push
subscription
.
A
push subscription
MAY
have an associated
subscription expiration
time
. When set, it
MUST
be the time, in milliseconds since 00:00:00 UTC on 1
January 1970, at which the subscription will be
deactivated
. The
user agent
SHOULD
attempt to
refresh
the push subscription before the subscription expires.
A
push subscription
has internal slots for a P-256
ECDH
key pair and an
authentication secret in accordance with [
RFC8291
]. These slots
MUST
be populated when
creating the
push subscription
.
If the
user agent
has to change the keys for any reason, it
MUST
fire the
"
pushsubscriptionchange
" event
with the
service worker registration
associated with the
push subscription
as
registration
, a
PushSubscription
instance representing the
push subscription
having the old keys as
oldSubscription
and a
PushSubscription
instance representing the
push
subscription
having the new keys as
newSubscription
.
To
create a push subscription
, given an
PushSubscriptionOptionsInit
optionsDictionary
:
Let
options
be a newly created
PushSubscriptionOptions
object, initializing its attributes with the corresponding members and values of
optionsDictionary
.
Set
subscription
's
options
attribute to
options
.
Generate a new P-256
ECDH
key pair [
ANSI-X9-62
]. Store the private key in an
internal slot on
subscription
; this value
MUST NOT
be made available to applications.
The public key is also stored in an internal slot and can be retrieved by calling the
getKey
()
method of the
PushSubscription
with an argument of
"
p256dh
".
Generate a new authentication secret, which is a sequence of octets as defined in
[
RFC8291
]. Store the authentication secret in an internal slot on
subscription
. This
key can be retrieved by calling the
getKey
()
method of the
PushSubscription
with an argument of "
auth
".
WebIDLdictionary PushPermissionDescriptor : PermissionDescriptor {booleanuserVisibleOnly = false;
The userVisibleOnly has the same semantics as
userVisibleOnly.
{name: "push", userVisibleOnly: false} is stronger than{name: "push", userVisibleOnly: true}.
Security and privacy considerations
The contents of a push message are encrypted [RFC8291]. However, the push
service is still exposed to the metadata of messages sent by an application
server to a user agent over a push subscription. This includes the
timing, frequency and size of messages. Other than changing push services, which
user agents may disallow, the only known mitigation is to increase the apparent message
size by padding.
There is no guarantee that a push message was sent by an application server
having the same origin as the web application. The application server is able to
share the details necessary to use a push subscription with a third party at its own
discretion.
The following requirements are intended to protect the privacy and security of the user as
far as possible, and subject to meeting that goal, to protect the integrity of the
application server's communication with the user.
User agentsMUST NOT provide Push API access to web applications without the
express permission of the user. User agentsMUST acquire consent for
permission through a user interface for each call to the subscribe() method, unless a
previous permission grant has been persisted, or a prearranged trust relationship applies.
Permissions that are preserved beyond the current browsing session MUST be revocable.
The Push API may have to wake up the Service Worker associated with the service worker
registration in order to run the developer-provided event handlers. This can cause
resource usage, such as network traffic, that the user agentSHOULD attribute to the
web application that created the push subscription.
The user agentMAY consider the PushSubscriptionOptions when acquiring
permission or determining the permission status.
When a permission is revoked, the user agentMAYfire the
"pushsubscriptionchange" event for subscriptions created with that permission, with
the service worker registration associated with the push subscription as
registration, a PushSubscription instance representing the push subscription
as oldSubscription, and null as newSubscription. The user agentMUSTdeactivate the affected subscriptions in parallel.
When a service worker registration is unregistered, any associated push
subscriptionMUST be deactivated.
The push endpointMUST NOT expose information about the user to be derived by actors
other than the push service, such as the user's device, identity or location. See
the Privacy Considerations in [RFC8030] for the exact requirements.
The push endpoint of a deactivatedpush subscriptionMUST NOT be
reused for a new push subscription. This prevents the creation of a persistent
identifier that the user cannot remove. This also prevents reuse of the details of one
push subscription to send push messages to another push subscription.
User agentsMUST implement the Push API to only be available in a secure context. This provides better protection for the user against man-in-the-middle attacks
intended to obtain push subscription data. Browsers may ignore this rule for development
purposes only.
Push Framework
the
user agent
identifies the intended
Service Worker
and activates it as
necessary, and delivers the
push message
to the
Service Worker
.
This overall framework allows
application servers
to activate a
Service
Worker
in response to events at the
application server
. Information about those
events can be included in the
push message
, which allows the web application to
react appropriately to those events, potentially without needing to initiate network
requests.
The following code and diagram illustrate a hypothetical use of the push API.
Example
// https://example.com/serviceworker.jsthis.onpush = event => {
console.log(event.data);
// From here we can write the data to IndexedDB, send it to any open// windows, display a notification, etc.// https://example.com/webapp.js// inside an async function...try {
const serviceWorkerRegistration = await navigator.serviceWorker.register(
"serviceworker.js"const pushSubscription = await serviceWorkerRegistration.pushManager.subscribe();
// The push subscription details needed by the application// server are now available, and can be sent to it using,// for example, an XMLHttpRequest.console.log(pushSubscription.endpoint);
console.log(pushSubscription.getKey("p256dh"));
console.log(pushSubscription.getKey("auth"));
} catch (err) {
// In a production environment it might make sense to// also report information about errors back to the// application server.console.log(error);
Sequence diagram
The getKey() method on a PushSubscription is used to
retrieve keying material used to encrypt and authenticate push messages. Each
invocation of the function returns a new ArrayBuffer that contains the value of the
corresponding key, or null if the identified key doesn't exist. Passing a value of
"p256dh" retrieves a elliptic curve
Diffie-Hellman (ECDH) public key associated with the push subscription. Passing a
value of auth returns an authentication secret that an application server uses in
authentication of its messages. These keys are used by the application server to
encrypt and authenticate messages for the push subscription, as described in
[RFC8291].
The Service Worker specification defines a ServiceWorkerRegistration interface
[SERVICE-WORKERS], which this specification extends.