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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
push event | Chrome Full support 40 | Edge Full support ≤79 | Firefox
Full support
44
| IE No support No | Opera Full support 24 | Safari Full support 11.1 | WebView Android Full support 40 | Chrome Android Full support 40 | Firefox Android Full support 44 | Opera Android Full support 24 | Safari iOS Full support 11.3 | Samsung Internet Android Full support 4.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.
See also
- Using the Push API
onpushevent handler propertypushsubscriptionchangeevent
