ServiceWorkerGlobalScope: push event

The push event is sent to a service worker's global scope (represented by the ServiceWorkerGlobalScope interface) when the service worker has received a push message.

Bubbles No
Cancelable No
Interface PushEvent
Event handler property onpush

Example

This example sets up a handler for push events that takes JSON data, parses it, and dispatches the message for handling based on information contained within the message.

self.addEventListener("push", event => {
  let message = event.data.json();

  switch(message.type) {
    case "init":
      doInit();
      break;
    case "shutdown":
      doShutdown();
      break;
  }
}, false);

Specifications

Specification Status Comment
Push API
The definition of 'push' in that specification.
Working Draft Initial specification.

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
push eventChrome Full support 40Edge Full support ≤79Firefox Full support 44
Notes
Full support 44
Notes
Notes Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No support NoOpera Full support 24Safari Full support 11.1WebView Android Full support 40Chrome Android Full support 40Firefox Android Full support 44Opera Android Full support 24Safari iOS Full support 11.3Samsung Internet Android Full support 4.0

Legend

Full support
Full support
No support
No support
See implementation notes.
See implementation notes.

See also