Esta traducción está incompleta. Por favor, ayuda a traducir este artículo del inglés.

Esta es una tecnología experimental
Comprueba la Tabla de compabilidad de navegadores cuidadosamente antes de usarla en producción.

La API Push otorga a las aplicaciones web la habilidad de recibir mensajes enviados a ellas desde un servidor, sin importar si la aplicación está o no en primer plano o cargada. Esto permite a los desarrolladores enviar notificaciones asíncronas y actualizaciones para los usuarios que las aceptan.

Nota: Esta documentación cubre la especificación del API Push de W3C; si estás buscando la documentación para el mecanismo push propio de Firefox OS, ve Simple Push.

Push conceptos y uso

Para que una aplicación recibá mensajes push, esta debe tener un service worker. Cuando el service worker esta activo, se puede suscribir usando PushManager.subscribe().

El resultado de PushSubscription incluye toda la información que la aplicación necesita para enviar un mensaje push: un endpoint y la llave de cifrado necesaria para enviar los datos.

El service worker se iniciará cuando sea necesario manejar mensajes push entrantes, que se entregan al manejador de eventos. Esto permite a las aplicaciones reaccionar a los mensajes push recibidos, por ejemplo para mostrar una notiificación suando ServiceWorkerRegistration.showNotification().

Cada suscripción es unica para un service worker. El endpoint para la subscripción es una unica capability URL: el conocimiento del endpoint es todo lo se necesita para enviar un mensaje a yu aplicación. La URL del endpoint  por lo tanto necesita ser mantenida secreta, o otras aplicaciones podrian ser capases de enviar mensajes push a tu aplicación.

Activating a service worker to deliver a push message can result in increased resource usage, particularly of the battery. Different browsers have different schemes for handling this — there is currently no standard mechanism. Firefox allows a limited number of push messages to be sent to an application.  This limit is refreshed each time that the site is visited. In comparison, Chrome applies no limit but requires that applications show a notification each time that a push message is received, which allows the user to confirm that they still want to receive notifications and ensures user visibility.

Note: Chrome currently requires you to set up a project on Google Cloud Messaging to send push messages, and use the associated project number and API key when sending push notifications. It also requires an app manifest with some special parameters to use this service. This restriction will hopefully be removed in the future.

Interfaces

PushEvent
Represents a push action sent to the global scope of a ServiceWorker. It contains information sent from an application to a PushSubscription.
PushManager
Provides a way to receive notifications from third-party servers as well as request URLs for push notifications. This interface has replaced functionality offered by the obsolete PushRegistrationManager interface.
PushMessageData
Provides access to push data sent by a server, and includes methods to manipulate the received data.
PushSubscription
Provides a subcription's URL endpoint and allows unsubscription from a push service.

Service worker additions

The following additions to the Service Worker API have been specified in the Push API spec, to provide an entry point for using Push messages, and  to monitor and respond to push and subscription change events.

ServiceWorkerRegistration.pushManager Read only
Returns a reference to the PushManager interface for managing push subscriptions including subscribing, getting an active subscription, and accessing push permission status. This is the entry point into using Push messaging.
ServiceWorkerGlobalScope.onpush
An event handler fired whenever a push event occurs; that is, whenever a server push message is received.
ServiceWorkerGlobalScope.onpushsubscriptionchange
An event handler fired whenever a pushsubscriptionchange event occurs; for example, when a push subscription has been invalidated, or is about to be invalidated (e.g. when a push service sets an expiration time.)

Specifications

Specification Status Comment
Push API Working Draft Initial definition

Browser Compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 42.0 44.0 (44.0)[1] ?[2] ? ?
PushEvent.data,
PushMessageData
Sin soporte 44.0 (44.0) Sin soporte Sin soporte Sin soporte
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support Sin soporte Sin soporte Sin soporte Sin soporte ?[2] ? ? 42.0
PushEvent.data,
PushMessageData
Sin soporte Sin soporte Sin soporte Sin soporte Sin soporte Sin soporte Sin soporte Sin soporte

[1] Currently available only on desktop versions of Firefox; also, push messages are only delivered when Firefox is running.

[2]: Microsoft Edge status: Under Consideration; Roadmap Priority: Low

See also

Etiquetas y colaboradores del documento

 Colaboradores en esta página: FMRonin, YulianD, mautematico
 Última actualización por: FMRonin,