Movatterモバイル変換


[0]ホーム

URL:


W3C

Push API

W3C Working Draft

More details about this document
This version:
https://www.w3.org/TR/2024/WD-push-api-20240903/
Latest published version:
https://www.w3.org/TR/push-api/
Latest editor's draft:
https://w3c.github.io/push-api/
History:
https://www.w3.org/standards/history/push-api/
Commit history
Editors:
Peter Beverloo (Google)
Martin Thomson (Mozilla Foundation)
Marcos Caceres (Apple Inc.)
Former editors:
Bryan Sullivan (AT&T) - Until
Eduardo Fullea (Telefonica) - Until
Michaël van Ouwerkerk (Google) - Until
Feedback:
GitHub w3c/push-api (pull requests,new issue,open issues)

Copyright © 2024World Wide Web Consortium.W3C®liability,trademark andpermissive document license rules apply.


Abstract

ThePush API enables sending of apush message to a web application via apush service. Anapplication server can send apush message at any time, even when a web application oruser agent is inactive. Thepush service ensures reliable and efficient delivery to theuser agent.Push messages are delivered to aService Worker that runs in the origin of the web application, which can use the information in the message to update local state or display a notification to the user.

This specification is designed for use with theweb push protocol, which describes how anapplication server oruser agent interacts with apush service.

Status of This Document

This section describes the status of this document at the time of its publication. A list of currentW3C publications and the latest revision of this technical report can be found in theW3C technical reports index at https://www.w3.org/TR/.

This document was published by theWeb Applications Working Group as a Working Draft using theRecommendation track.

Publication as a Working Draft does not imply endorsement byW3C 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 theW3C Patent Policy.W3C maintains apublic 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 containsEssential Claim(s) must disclose the information in accordance withsection 6 of theW3C Patent Policy.

This document is governed by the03 November 2023W3C Process Document.

1. Introduction

This section is non-normative.

The Push API allows a web application to communicate with auser agent asynchronously. This allows anapplication server to provide theuser 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 ofpush messages at any time.

In particular, apush 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 apush message is received. For example, apush message might be used to inform the user of an incoming WebRTC call.

Apush message can also be sent when theuser agent is temporarily offline. In support of this, thepush service stores messages for theuser agent until theuser agent becomes available. This supports use cases where a web application learns of changes that occur while a user is offline and ensures that theuser agent can be provided with relevant information in a timely fashion.Push messages are stored by thepush service until theuser agent becomes reachable and the message can be delivered.

The Push API will also ensure reliable delivery of push messages while auser 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 anapplication 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 theapplication server.

Push messaging is best suited to occasions where there is not already an active communications channel established between theuser agent and the web application. Sendingpush messages requires considerably more resources when compared with more direct methods of communication such as theFetch API or [WebSockets].Push messages usually have higher latency than direct communications and they can also be subject to restrictions on use. Mostpush services limit the size and quantity ofpush messages that can be sent.

2. Dependencies

Theweb push protocol [RFC8030] describes a protocol that enables communication between auser agent orapplication server and apush 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.

TheContent-Encoding HTTP header, described in Section 3.1.2.2 of [RFC7231], indicates the content coding applied to the payload of apush message.

3. Concepts

3.1 Application server

The termapplication server refers to server-side components of a web application.

3.2 Push message

Apush message is data sent to a web application from anapplication server.

Apush message is delivered to theactive worker associated with thepush subscription to which the message was submitted. If the service worker is not currently running, the worker is started to enable delivery.

3.3 Push subscription

Apush subscription is a message delivery context established between theuser agent and thepush service on behalf of a web application. Eachpush subscription is associated with aservice worker registration and aservice worker registration has at most onepush subscription.

Apush subscription has an associatedpush endpoint. ItMUST be the absolute URL exposed by thepush service where theapplication server can sendpush messages to. Apush endpointMUST uniquely identify thepush subscription.

Apush subscriptionMAY have an associatedsubscription expiration time. When set, itMUST be the time, in milliseconds since 00:00:00 UTC on 1 January 1970, at which the subscription will bedeactivated. Theuser agentSHOULD attempt torefresh the push subscription before the subscription expires.

Apush subscription has internal slots for a P-256ECDH key pair and an authentication secret in accordance with [RFC8291]. These slotsMUST be populated when creating thepush subscription.

If theuser agent has to change the keys for any reason, itMUSTfire the "pushsubscriptionchange" event with theservice worker registration associated with thepush subscription asregistration, aPushSubscription instance representing thepush subscription having the old keys asoldSubscription and aPushSubscription instance representing thepush subscription having the new keys asnewSubscription.

Tocreate a push subscription, given anPushSubscriptionOptionsInitoptionsDictionary:

  1. Letsubscription be a newPushSubscription.
  2. Letoptions be a newly createdPushSubscriptionOptions object, initializing its attributes with the corresponding members and values ofoptionsDictionary.
  3. Setsubscription'soptions attribute tooptions.
  4. Generate a new P-256ECDH key pair [ANSI-X9-62]. Store the private key in an internal slot onsubscription; this valueMUST NOT be made available to applications. The public key is also stored in an internal slot and can be retrieved by calling thegetKey() method of thePushSubscription with an argument of "p256dh".
  5. Generate a new authentication secret, which is a sequence of octets as defined in [RFC8291]. Store the authentication secret in an internal slot onsubscription. This key can be retrieved by calling thegetKey() method of thePushSubscription with an argument of "auth".
  6. Request a newpush subscription. Include theapplicationServerKey attribute ofoptions when it has been set. Rethrow anyexceptions.
  7. When thepush subscription request has completed successfully:
    1. Setsubscription'sendpoint attribute to thepush subscription'spush endpoint.
    2. If provided by thepush subscription, setsubscription'sexpirationTime.
  8. Returnsubscription.

3.3.1 Subscription Refreshes

Auser agent orpush serviceMAY choose torefresh apush subscription at any time, for example because it has reached a certain age.

When this happens, theuser agentMUST run the steps tocreate a push subscription given thePushSubscriptionOptions that were provided for creating the currentpush subscription. The newpush subscriptionMUST have a key pair that's different from the original subscription.

When successful,user agent thenMUSTfire the "pushsubscriptionchange" event with theservice worker registration associated with thepush subscription asregistration, aPushSubscription instance representing the initialpush subscription asoldSubscription and aPushSubscription instance representing the newpush subscription asnewSubscription.

To allow for time to propagate changes toapplication servers, auser agentMAY continue to accept messages for an oldpush subscription for a brief time after a refresh. Once messages have been received for a refreshedpush subscription, any oldpush subscriptionsMUST bedeactivated.

If theuser agent is not able to refresh thepush subscription, itSHOULD periodically retry the refresh. When thepush subscription can no longer be used, for example because it has expired, theuser agentMUSTfire the "pushsubscriptionchange" event with theservice worker registration associated with thepush subscription asregistration, aPushSubscription instance representing the deactivatingpush subscription asoldSubscription andnull as thenewSubscription.

3.3.2 Subscription Deactivation

When apush subscription isdeactivated, both theuser agent and thepush serviceMUST delete any stored copies of its details. Subsequentpush messages for thispush subscriptionMUST NOT be delivered.

Apush subscription isdeactivated when its associatedservice worker registration is unregistered, though apush subscriptionMAY bedeactivated earlier.

Note

Apush subscription is removed whenservice worker registration is cleared.

3.4 Push service

The termpush service refers to a system that allowsapplication servers to sendpush messages to a web application. A push service serves thepush endpoint orendpoints for thepush subscriptions it serves.

Theuser agent connects to thepush service used to createpush subscriptions.User agentsMAY limit the choice ofpush services available. Reasons for doing so include performance-related concerns such as service availability (including whether services are blocked by firewalls in specific countries, or networks at workplaces and the like), reliability, impact on battery lifetime, and agreements to steer metadata to, or away from, specificpush services.

3.5 Permission

The Push API is apowerful feature identified by thename"push".

For integration with thePermissions specification, this specification defines thePushPermissionDescriptorpermission descriptor type.

WebIDLdictionaryPushPermissionDescriptor :PermissionDescriptor {booleanuserVisibleOnly = false;};

TheuserVisibleOnly has the same semantics asuserVisibleOnly.

{name: "push", userVisibleOnly: false} isstronger than{name: "push", userVisibleOnly: true}.

4. Security and privacy considerations

The contents of apush message are encrypted [RFC8291]. However, thepush service is still exposed to the metadata of messages sent by anapplication server to auser agent over apush subscription. This includes the timing, frequency and size of messages. Other than changingpush services, which user agents may disallow, the only known mitigation is to increase the apparent message size by padding.

There is no guarantee that apush message was sent by anapplication server having the same origin as the web application. Theapplication server is able to share the details necessary to use apush 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 theapplication server's communication with the user.

User agentsMUST NOT provide Push API access to web applications without theexpress permission of the user.User agentsMUST acquire consent for permission through a user interface for each call to thesubscribe() method, unless a previous permission grant has been persisted, or a prearranged trust relationship applies. Permissions that are preserved beyond the current browsing sessionMUST be revocable.

The Push API may have to wake up the Service Worker associated with theservice worker registration in order to run the developer-provided event handlers. This can cause resource usage, such as network traffic, that theuser agentSHOULD attribute to the web application that created thepush subscription.

Theuser agentMAY consider thePushSubscriptionOptions when acquiring permission or determining the permission status.

When a permission is revoked, theuser agentMAYfire the "pushsubscriptionchange" event for subscriptions created with that permission, with theservice worker registration associated with thepush subscription asregistration, aPushSubscription instance representing thepush subscription asoldSubscription, andnull asnewSubscription. Theuser agentMUSTdeactivate the affected subscriptions in parallel.

When aservice worker registration is unregistered, any associatedpush subscriptionMUST bedeactivated.

Thepush endpointMUST NOT expose information about the user to be derived by actors other than thepush service, such as the user's device, identity or location. See the Privacy Considerations in [RFC8030] for the exact requirements.

Thepush endpoint of adeactivatedpush subscriptionMUST NOT be reused for a newpush subscription. This prevents the creation of a persistent identifier that the user cannot remove. This also prevents reuse of the details of onepush subscription to sendpush messages to anotherpush subscription.

User agentsMUST implement the Push API to only be available in asecure 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.

5. Push Framework

This section is non-normative.

Apush message is sent from anapplication server to a web application as follows:

This overall framework allowsapplication servers to activate aService Worker in response to events at theapplication server. Information about those events can be included in thepush 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.

5.1 Example

This section is non-normative.

Example 1
// 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);}

5.2 Sequence diagram

This section is non-normative.

Example flow of events for subscription, push message delivery, and unsubscription
Figure1 Example flow of events for subscription, push message delivery, and unsubscription

5.3 Push service use

The fields included in thePushSubscription is all the information needed for anapplication server to send apush message. Push services that are compatible with the Push API provide apush endpoint that conforms to theweb push protocol. These parameters and attributes include:

6. Extensions to theServiceWorkerRegistration Interface

The Service Worker specification defines aServiceWorkerRegistration interface [SERVICE-WORKERS], which this specification extends.

WebIDL[SecureContext]partial interfaceServiceWorkerRegistration {  readonly attributePushManagerpushManager;};

ThepushManager attribute exposes aPushManager, which has an associatedservice worker registration represented by theServiceWorkerRegistration on which the attribute is exposed.

7.PushManager interface

ThePushManager interface defines the operations to accesspush services.

WebIDL[Exposed=(Window,Worker),SecureContext]interfacePushManager {  [SameObject] static readonly attributeFrozenArray<DOMString>supportedContentEncodings;Promise<PushSubscription>subscribe(optionalPushSubscriptionOptionsInitoptions = {});Promise<PushSubscription?>getSubscription();Promise<PermissionState>permissionState(optionalPushSubscriptionOptionsInitoptions = {});};

ThesupportedContentEncodings attribute exposes the sequence of supported content codings that can be used to encrypt the payload of apush message. A content coding is indicated using theContent-Encoding header field when requesting the sending of apush message from thepush service.

User agentsMUST support theaes128gcm content coding defined in [RFC8291], andMAY support content codings defined in previous versions of the draft for compatibility reasons.

7.1subscribe() method

Thesubscribe() method when invokedMUST run the following steps:

  1. Letpromise bea new promise.
  2. Letglobal bethis'relevant global object.
  3. Returnpromise and continuein parallel.
    Note: Validation order can vary across user agents

    Because of implementation-specific reasons, user agents are known to do some of the following checks in different order (e.g., some check ifuserVisibleOnly is allowed after validating theapplicationServerKey, and vice versa). However, we don't believe this affects interoperability of implementations or web applications.

  4. If theoptions argument has auserVisibleOnly value set tofalse and the user agent requires it to betrue,queue a global task on thenetworking task source usingglobal torejectpromise "NotAllowedError"DOMException
  5. If theoptions argument does not include a non-null value for theapplicationServerKey member, and thepush service requires one to be given,queue a global task on thenetworking task source usingglobal torejectpromise with a "NotSupportedError"DOMException.
  6. If theoptions argument includes a non-null value for theapplicationServerKey attribute, run the following sub-steps:
    1. Ifoptions'sapplicationServerKey is aDOMString, set its value to anArrayBuffer containing the sequence of octets that result from decodingoptions'sapplicationServerKey using the base64url encoding [RFC7515].
    2. If decoding fails,queue a global task on thenetworking task source usingglobal torejectpromise with an "InvalidCharacterError"DOMException and terminate these steps.
    3. Ensure thatoptions'sapplicationServerKey describes a valid point on the P-256 curve. If its value is invalid,queue a global task on thenetworking task source usingglobal torejectpromise with an "InvalidAccessError"DOMException and terminate these steps.
  7. Letregistration bethis's associatedservice worker registration.
  8. Ifregistration'sactive worker is null,queue a global task on thenetworking task source usingglobal torejectpromise with an "InvalidStateError"DOMException and terminate these steps.
  9. Letpermission berequest permission to use "push".
  10. Ifpermission is "denied",queue a global task on theuser interaction task source usingglobal torejectpromise with a "NotAllowedError"DOMException and terminate these steps.
  11. Ifregistration has apush subscription:
    1. Letsubscription be the result of obtainingregistration'spush subscription. If there is an error,queue a global task on thenetworking task source usingglobal torejectpromise with an "AbortError"DOMException and terminate these steps.
    2. Compare theoptions argument with theoptions attribute ofsubscription. The contents ofBufferSource values are compared for equality rather thanreference.
    3. If any attribute onoptions contains a different value to that stored forsubscription, thenqueue a global task on thenetworking task source usingglobal torejectpromise with an "InvalidStateError"DOMException and terminate these steps.
    4. When the request has been completed,queue a global task on thenetworking task source usingglobal toresolvepromise withsubscription and terminate these steps.
  12. Letsubscription be the result of trying tocreate a push subscription withoptions. If creating the subscriptionthrows anexception,queue a global task on thenetworking task source usingglobal torejectpromise with a thatexception and terminate these these steps.
  13. Otherwise,queue a global task on thenetworking task source usingglobal toresolvepromise with aPushSubscription providing the details of the newsubscription.

ThegetSubscription method when invokedMUST run the following steps:

  1. Letpromise bea new promise.
  2. Returnpromise and continue the following steps asynchronously.
  3. If theService Worker is not subscribed, resolvepromise with null.
  4. Retrieve thepush subscription associated with theService Worker.
  5. If there is an error, rejectpromise with aDOMException whose name is "AbortError" and terminate these steps.
  6. When the request has been completed, resolvepromise with aPushSubscription providing the details of the retrievedpush subscription.

ThepermissionState() method when invokedMUST run the following steps:

  1. Letpromise bea new promise.
  2. Returnpromise and continue the following steps asynchronously.
  3. Letdescriptor be a newPermissionDescriptor with thename initialized to "push".
  4. letstate be thepermission state ofdescriptor and the result.
  5. Resolvepromise withstate.

Permission to use the push service can be persistent, that is, it does not need to be reconfirmed for subsequent subscriptions if a valid permission exists.

If there is a need to ask for permission, it needs to be done by invoking thesubscribe() method.

7.2PushSubscriptionOptions Interface

WebIDL[Exposed=(Window,Worker),SecureContext]interfacePushSubscriptionOptions {  readonly attributebooleanuserVisibleOnly;  [SameObject] readonly attributeArrayBuffer?applicationServerKey;};

TheuserVisibleOnly attribute, when getting, returns the value it was initialized with.

TheapplicationServerKey attribute, when getting, returns the value it was initialized with.

If present, the value ofapplicationServerKeyMUST include a point on the P-256 elliptic curve [DSS], encoded in the uncompressed form described in [ANSI-X9-62] Annex A (that is, 65 octets, starting with an 0x04 octet). When provided as aDOMString, the valueMUST be encoded using the base64url encoding [RFC7515].

User agentsMAY reject a subscription attempt whenapplicationServerKey is not present and thepush service requires one for operational reasons.

TheapplicationServerKeyMUST be a different value to the one used for message encryption [RFC8291].

7.3PushSubscriptionOptionsInit dictionary

WebIDLdictionaryPushSubscriptionOptionsInit {booleanuserVisibleOnly = false;  (BufferSource orDOMString)?applicationServerKey = null;};

TheuserVisibleOnly member, when set totrue, indicates that thepush subscription will only be used forpush messages whose effect is made visible to the user, for example by displaying a Web Notification. [NOTIFICATIONS]

APushSubscriptionOptionsInit represents additional options associated with apush subscription. Theuser agentMAY consider these options when requestingexpress permission from the user. When an option is considered, theuser agentSHOULD enforce it on incomingpush messages.

These options are optional, anduser agentsMAY choose to support only a subset of them. Auser agentMUST NOT expose options that it does not support.

Once set, options for apush subscription cannot change. A pre-existingpush subscription can be unsubscribed, viaunsubscribe, to create apush subscription with new options.

TheapplicationServerKey member is used by theuser agent when establishing apush subscription with apush service. TheapplicationServerKey option includes an elliptic curve public key for anapplication server. This is the key that theapplication server will use to authenticate itself when sendingpush messages to thispush subscription as defined in [RFC8292]; thepush service will reject anypush message unless the corresponding private key is used to generate an authentication token.

8.PushSubscription interface

APushSubscription object represents apush subscription.

WebIDL[Exposed=(Window,Worker),SecureContext]interfacePushSubscription {  readonly attributeUSVStringendpoint;  readonly attributeEpochTimeStamp?expirationTime;  [SameObject] readonly attributePushSubscriptionOptionsoptions;ArrayBuffer?getKey(PushEncryptionKeyNamename);Promise<boolean>unsubscribe();PushSubscriptionJSONtoJSON();};dictionaryPushSubscriptionJSON {USVStringendpoint;EpochTimeStamp?expirationTime = null;record<DOMString,USVString>keys;};

Whengetting theendpoint attribute, theuser agentMUST return thepush endpoint associated with thepush subscription. Theuser agentMUST use a serialization method that does not contain input-dependent branches (that is, one that is constant time).

Whengetting theexpirationTime attribute, theuser agentMUST return thesubscription expiration time associated with thepush subscription if there is one, ornull otherwise.

When getting theoptions attribute, theuser agentMUST return aPushSubscriptionOptions object representing the options associated with thepush subscription.

ThegetKey() method retrieves keying material that can be used for encrypting and authenticating messages. WhengetKey() is invoked the following process is followed:

  1. Find the internal slot corresponding to the key named by thename argument.
  2. If a slot was not found, returnnull.
  3. Initialize a variablekey with a newly instantiatedArrayBuffer instance.
  4. If the internal slot contains an asymmetric key pair, set the contents ofkey to the serialized value of the public key from the key pair. This uses the serialization format described in the specification that defines the name. For example, [RFC8291] specifies that the "p256dh" public key is encoded using the uncompressed format defined in [ANSI-X9-62] Annex A (that is, a 65 octet sequence that starts with a 0x04 octet).
  5. Otherwise, if the internal slot contains a symmetric key, set the contents ofkey to a copy of the value from the internal slot. For example, theauth parameter contains an octet sequence used by theuser agent to authenticate messages sent by anapplication server.
  6. Returnkey.

Keys named "p256dh" and "auth"MUST be supported, and their valuesMUST correspond to those necessary for the user agent to decrypt received push messages in accordance with [RFC8291].

Theunsubscribe() method when invokedMUST run the following steps:

  1. Letpromise bea new promise.
  2. Returnpromise and continue the following steps asynchronously.
  3. If thepush subscription has already beendeactivated, resolvepromise withfalse and terminate these steps.
  4. Run the following step in parallel:
    1. Deactivate thepush subscription. Theuser agentMUST NOT deliver any furtherpush messages for thepush subscription.

      If theuser agent failed to request thepush service todeactivate thepush subscription, for example because of network failures, itSHOULD retry the request to thepush service for a reasonable amount of time.

  5. Resolvepromise withtrue.

ThetoJSON() method when invokedMUST run the following steps:

  1. Letjson be a newPushSubscriptionJSON dictionary.
  2. Setjson["endpoint"] to the result ofgetting theendpoint attribute ofthis.
  3. Setjson["expirationTime"] to the result ofgetting theexpirationTime attribute ofthis.
  4. Letkeys be a new empty instance ofrecord<DOMString, USVString> .
  5. For each identifieri corresponding to keys in internal slots on thePushSubscription, ordered by the name of the key:
    1. If the internal slot corresponds to an asymmetric key pair, letb be the encoded value of the public key corresponding to the key namei, using the encoding defined for the key name (seegetKey()).
    2. Otherwise, letb be the value as returned bygetKey.
    3. Lets be the URL-safe base64 encoding without padding [RFC4648] ofb as aUSVString. Theuser agentMUST use a serialization method that does not branch based on the value ofb.
    4. Setkeys[i] tos.
  6. Setjson["keys"] tokeys.
  7. Returnjson.

APushSubscriptionJSON dictionary represents theJSON type of aPushSubscription. In ECMAScript this can be converted into a JSON string through theJSON.stringify() function.

Thekeys record contains an entry for each of the supportedPushEncryptionKeyName entries to the URL-safe base64 encoded representation [RFC4648] of its value.

Note that the options to aPushSubscription are not serialized.

8.1PushEncryptionKeyName enumeration

Encryption keys used forpush message encryption are provided to a web application through thegetKey() method or the serializer ofPushSubscription. Each key is named using a value from thePushEncryptionKeyName enumeration.

WebIDLenumPushEncryptionKeyName {"p256dh","auth"};

Thep256dh value is used to retrieve the P-256ECDH Diffie-Hellman public key described in [RFC8291].

Theauth value is used to retrieve the authentication secret described in [RFC8291].

9.PushMessageData interface

WebIDL[Exposed=ServiceWorker,SecureContext]interfacePushMessageData {ArrayBufferarrayBuffer();Blobblob();Uint8Arraybytes();anyjson();USVStringtext();};

PushMessageData objects have an associatedbytes (abyte sequence), which is set on creation.

ThearrayBuffer() method steps are to return anArrayBuffer whose contents arethis'sbytes. Exceptions thrown during the creation of theArrayBuffer object are re-thrown.

Theblob() method steps are to return a newBlob object whose contents arethis'sbytes.

Thebytes() method steps are to return a newUint8Array backed by aArrayBuffer whose contents arethis'sbytes. Exceptions thrown during the creation of theArrayBuffer object are re-thrown.

Thejson() method steps are to return the result ofparsing JSON bytes to a JavaScript value giventhis'sbytes.

Thetext() method steps are to return the result of runningUTF-8 decode onthis'sbytes.

Toextract a byte sequence fromobject, run these steps:

  1. Letbytes be an empty byte sequence.
  2. Switch onobject's type:
    BufferSource
    Setbytes to a copy ofobject's contents.
    USVString
    Setbytes to the result of runningutf-8 encode onobject.
  3. Returnbytes.

10. Events

10.1 Extensions to theServiceWorkerGlobalScope interface

The Service Worker specification defines aServiceWorkerGlobalScope interface [SERVICE-WORKERS], which this specification extends.

WebIDL[Exposed=ServiceWorker,SecureContext]partial interfaceServiceWorkerGlobalScope {  attributeEventHandleronpush;  attributeEventHandleronpushsubscriptionchange;};

Theonpush attribute is anevent handler IDL attribute whose correspondingevent handler event type is "push". The "push" event indicates that apush message has been received for apush subscription.

Theonpushsubscriptionchange attribute is anevent handler IDL attribute whose correspondingevent handler event type is "pushsubscriptionchange".

10.2PushEvent Interface

WebIDL[Exposed=ServiceWorker,SecureContext]interfacePushEvent :ExtendableEvent {constructor(DOMStringtype, optionalPushEventIniteventInitDict = {});  readonly attributePushMessageData?data;};

When aconstructor of thePushEvent interface, or of an interface that inherits from thePushEvent interface, is invoked, the usualevent constructing steps are extended to include the following steps:

  1. IfeventInitDict'sdata member is not present, set thedata attribute of the event tonull and terminate these steps.
  2. Setb to the result ofextracting a byte sequence from the "data" member ofeventInitDict.
  3. Set thedata attribute of the event to a newPushMessageData instance withbytes set tob.

Thedata, when getting, returns the value it was initialized with.

10.3PushEventInit dictionary

WebIDLtypedef (BufferSource orUSVString)PushMessageDataInit;dictionaryPushEventInit :ExtendableEventInit {PushMessageDataInitdata;};

Thedata member contains the data included in thepush message when included and theuser agent verified its authenticity. The value will be set tonull in all other cases.

10.4 Receiving aPush Message

When theuser agent receives apush message from thepush service, itMUST run the following steps.

  1. Letregistration be theservice worker registration corresponding to the push message.
  2. Ifregistration is not found, abort these steps.
  3. Letsubscription be the activepush subscription forregistration.
  4. Letbytes be null.
  5. If thepush message contains a payload:
    1. Decrypt thepush message payload using the private key from the key pair associated withsubscription and the process described in [RFC8291]. Setbytes to the resultingbyte sequence.
    2. If thepush message payload could not be decrypted for any reason:
      1. Acknowledge the receipt of thepush message according to [RFC8030]. Though the message was not successfully received and processed, this prevents the push service from attempting to retransmit the message; a badly encrypted message is not recoverable.
      2. Abort these steps.
      Note

      Apush event will not be fired for apush message that was not successfully decrypted using the key pair associated with thepush subscription.

  6. Fire a functional event named "push" usingPushEvent onregistration with the following properties:

    data
    A newPushMessageData object whosebytes isbytes.

    Then run the following steps in parallel, withdispatchedEvent:

    1. Wait for all of the promises in theextend lifetime promises ofdispatchedEvent to resolve.
    2. If all the promises resolve successfully, acknowledge the receipt of thepush message according to [RFC8030] and abort these steps.
    3. If the samepush message has been delivered to aservice worker registration multiple times unsuccessfully, acknowledge the receipt of thepush message according to [RFC8030].

      Acknowledging thepush message causes thepush service to stop delivering the message and to report success to theapplication server. This prevents the samepush message from being retried by thepush service indefinitely.

      Acknowledging also means that anapplication server could incorrectly receive a delivery receipt indicating successful delivery of thepush message. Therefore, multiple rejectionsSHOULD be permitted before acknowledging; allowing at least three attempts is recommended.

10.5 Thepushsubscriptionchange Event

Thepushsubscriptionchange event indicates a change in apush subscription that was triggered outside of the application's control, for example because it has been refreshed, revoked or lost.

Tofire the "pushsubscriptionchange" event given aservice worker registration ofregistration,newSubscription andoldSubscription, theuser agent mustfire a functional event named "pushsubscriptionchange" usingPushSubscriptionChangeEvent onregistration with the following properties:

newSubscription
newSubscription
oldSubscription
oldSubscription
Note

Consider using a more reliable synchronization mechanism such as [WEB-BACKGROUND-SYNC] when sending the details of the newpush subscription to yourapplication server. The user might be subject to unreliable network conditions that could cause a fetch to fail.

10.5.1PushSubscriptionChangeEvent Interface

WebIDL[Exposed=ServiceWorker,SecureContext]interfacePushSubscriptionChangeEvent :ExtendableEvent {constructor(DOMStringtype, optionalPushSubscriptionChangeEventIniteventInitDict = {});  readonly attributePushSubscription?newSubscription;  readonly attributePushSubscription?oldSubscription;};

ThenewSubscription attribute, when getting, returns the value it was initialized to.

TheoldSubscription attribute, when getting, returns the value it was initialized to.

10.5.2PushSubscriptionChangeEventInit Interface

WebIDLdictionaryPushSubscriptionChangeEventInit :ExtendableEventInit {PushSubscriptionnewSubscription = null;PushSubscriptionoldSubscription = null;};

ThenewSubscription member details thepush subscription that is valid per invocation of thepushsubscriptionchange event. The value will benull when no newpush subscription could be established, for example because the web application has lostexpress permission.

TheoldSubscription member details thepush subscription thatSHOULD NOT be used anymore. The value will benull when theuser agent is not able to provide the full set of details, for example because of partial database corruption.

11. Accessibility

ThePush API does not provide any means itself to present data it receives from apush service. Instead, thePush API relies on other APIs – primarily theNotifications API Standard – to present received information to an end user. As such, there are no accessibility requirements for thePush API itself. However, specifications such as [NOTIFICATIONS] provide guidance how to present notifications in an accessible manner.

Further, presenting an accessible interface might depend on transferring more information than a push message can convey. Push messages are best suited to carrying small amounts of content or identifiers. Any larger resources need to be fetched from servers.

12.Conformance

As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.

The key wordsMAY,MUST,MUST NOT,SHOULD, andSHOULD NOT in this document are to be interpreted as described inBCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.

This specification defines conformance criteria that apply to a single product: theuser agent that implements the interfaces that it contains.

A.IDL Index

WebIDLdictionaryPushPermissionDescriptor :PermissionDescriptor {booleanuserVisibleOnly = false;};[SecureContext]partial interfaceServiceWorkerRegistration {  readonly attributePushManagerpushManager;};[Exposed=(Window,Worker),SecureContext]interfacePushManager {  [SameObject] static readonly attributeFrozenArray<DOMString>supportedContentEncodings;Promise<PushSubscription>subscribe(optionalPushSubscriptionOptionsInitoptions = {});Promise<PushSubscription?>getSubscription();Promise<PermissionState>permissionState(optionalPushSubscriptionOptionsInitoptions = {});};[Exposed=(Window,Worker),SecureContext]interfacePushSubscriptionOptions {  readonly attributebooleanuserVisibleOnly;  [SameObject] readonly attributeArrayBuffer?applicationServerKey;};dictionaryPushSubscriptionOptionsInit {booleanuserVisibleOnly = false;  (BufferSource orDOMString)?applicationServerKey = null;};[Exposed=(Window,Worker),SecureContext]interfacePushSubscription {  readonly attributeUSVStringendpoint;  readonly attributeEpochTimeStamp?expirationTime;  [SameObject] readonly attributePushSubscriptionOptionsoptions;ArrayBuffer?getKey(PushEncryptionKeyNamename);Promise<boolean>unsubscribe();PushSubscriptionJSONtoJSON();};dictionaryPushSubscriptionJSON {USVStringendpoint;EpochTimeStamp?expirationTime = null;record<DOMString,USVString>keys;};enumPushEncryptionKeyName {"p256dh","auth"};[Exposed=ServiceWorker,SecureContext]interfacePushMessageData {ArrayBufferarrayBuffer();Blobblob();Uint8Arraybytes();anyjson();USVStringtext();};[Exposed=ServiceWorker,SecureContext]partial interfaceServiceWorkerGlobalScope {  attributeEventHandleronpush;  attributeEventHandleronpushsubscriptionchange;};[Exposed=ServiceWorker,SecureContext]interfacePushEvent :ExtendableEvent {constructor(DOMStringtype, optionalPushEventIniteventInitDict = {});  readonly attributePushMessageData?data;};typedef (BufferSource orUSVString)PushMessageDataInit;dictionaryPushEventInit :ExtendableEventInit {PushMessageDataInitdata;};[Exposed=ServiceWorker,SecureContext]interfacePushSubscriptionChangeEvent :ExtendableEvent {constructor(DOMStringtype, optionalPushSubscriptionChangeEventIniteventInitDict = {});  readonly attributePushSubscription?newSubscription;  readonly attributePushSubscription?oldSubscription;};dictionaryPushSubscriptionChangeEventInit :ExtendableEventInit {PushSubscriptionnewSubscription = null;PushSubscriptionoldSubscription = null;};

B. Acknowledgements

The editors would like to express their gratitude to the Mozilla and Telefónica Digital teams implementing the Firefox OS Push message solution, as well as to the following people who provided significant technical input to this document: Antonio Amaya, Miguel García Arribas, Ben Bangert, Kit Cambridge, José Manuel Cantera, JR Conlin, Albert Crespell, Matt Gaunt, Phil Jenvey, Guillermo López, Nikhil Marathe, John Mellor, Pınar Özlen, Fernando R. Sela, Shijun Sun and Doug Turner.

C.References

C.1Normative references

[ANSI-X9-62]
Public Key Cryptography for the Financial Services Industry, The Elliptic Curve Digital Signature Algorithm (ECDSA). ANSI. 2005. URL:https://webstore.ansi.org/RecordDetail.aspx?sku=ANSI+X9.62%3a2005
[dom]
DOM Standard. Anne van Kesteren. WHATWG. Living Standard. URL:https://dom.spec.whatwg.org/
[DSS]
FIPS PUB 186-5: Digital Signature Standard (DSS). U.S. Department of Commerce/National Institute of Standards and Technology. 3 February 2023. National Standard. URL:https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf
[ecmascript]
ECMAScript Language Specification. Ecma International. URL:https://tc39.es/ecma262/multipage/
[encoding]
Encoding Standard. Anne van Kesteren. WHATWG. Living Standard. URL:https://encoding.spec.whatwg.org/
[fileapi]
File API. Marijn Kruisselbrink. W3C. 24 May 2024. W3C Working Draft. URL:https://www.w3.org/TR/FileAPI/
[hr-time]
High Resolution Time. Yoav Weiss. W3C. 19 July 2023. W3C Working Draft. URL:https://www.w3.org/TR/hr-time-3/
[html]
HTML Standard. Anne van Kesteren; Domenic Denicola; Ian Hickson; Philip Jägenstedt; Simon Pieters. WHATWG. Living Standard. URL:https://html.spec.whatwg.org/multipage/
[infra]
Infra Standard. Anne van Kesteren; Domenic Denicola. WHATWG. Living Standard. URL:https://infra.spec.whatwg.org/
[NOTIFICATIONS]
Notifications API Standard. Anne van Kesteren. WHATWG. Living Standard. URL:https://notifications.spec.whatwg.org/
[Permissions]
Permissions. Marcos Caceres; Mike Taylor. W3C. 19 March 2024. W3C Working Draft. URL:https://www.w3.org/TR/permissions/
[RFC2119]
Key words for use in RFCs to Indicate Requirement Levels. S. Bradner. IETF. March 1997. Best Current Practice. URL:https://www.rfc-editor.org/rfc/rfc2119
[RFC4648]
The Base16, Base32, and Base64 Data Encodings. S. Josefsson. IETF. October 2006. Proposed Standard. URL:https://www.rfc-editor.org/rfc/rfc4648
[RFC7231]
Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content. R. Fielding, Ed.; J. Reschke, Ed.. IETF. June 2014. Proposed Standard. URL:https://httpwg.org/specs/rfc7231.html
[RFC7515]
JSON Web Signature (JWS). M. Jones; J. Bradley; N. Sakimura. IETF. May 2015. Proposed Standard. URL:https://www.rfc-editor.org/rfc/rfc7515
[RFC8030]
Generic Event Delivery Using HTTP Push. M. Thomson; E. Damaggio; B. Raymor, Ed.. IETF. December 2016. Proposed Standard. URL:https://www.rfc-editor.org/rfc/rfc8030
[RFC8174]
Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words. B. Leiba. IETF. May 2017. Best Current Practice. URL:https://www.rfc-editor.org/rfc/rfc8174
[RFC8291]
Message Encryption for Web Push. M. Thomson. IETF. November 2017. Proposed Standard. URL:https://www.rfc-editor.org/rfc/rfc8291
[RFC8292]
Voluntary Application Server Identification (VAPID) for Web Push. M. Thomson; P. Beverloo. IETF. November 2017. Proposed Standard. URL:https://www.rfc-editor.org/rfc/rfc8292
[SERVICE-WORKERS]
Service Workers. Jake Archibald; Marijn Kruisselbrink. W3C. 12 July 2022. W3C Candidate Recommendation. URL:https://www.w3.org/TR/service-workers/
[WEBIDL]
Web IDL Standard. Edgar Chen; Timothy Gu. WHATWG. Living Standard. URL:https://webidl.spec.whatwg.org/

C.2Informative references

[Fetch]
Fetch Standard. Anne van Kesteren. WHATWG. Living Standard. URL:https://fetch.spec.whatwg.org/
[WEB-BACKGROUND-SYNC]
Web Background Synchronization. WICG. cg-draft. URL:https://wicg.github.io/background-sync/spec/
[WebSockets]
WebSockets Standard. Adam Rice. WHATWG. Living Standard. URL:https://websockets.spec.whatwg.org/


[8]ページ先頭

©2009-2025 Movatter.jp