dom / latest / pushevent / pushevent.html /

PushEvent()

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The PushEvent() constructor creates a new PushEvent object. Note that this constructor is exposed only to a service worker context.

Syntax

new PushEvent(type, eventInitDict);

Parameters

type

A DOMString defining the type of PushEvent. This can be push or pushsubscriptionchange.

eventInitDict Optional

An options object containing any initialization data you want to populate the PushEvent object with. The options are:

  • data: The data you want the PushEvent to contain, if any. When the constructor is invoked, the PushEvent.data property of the resulting object will be set to a new PushMessageData object containing bytes extracted from the eventInitDict data member.

Examples

var dataInit = {
  data : 'Some sample text'
}

var myPushEvent = new PushEvent('push', dataInit);

myPushEvent.data.text(); // should return 'Some sample text'

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
PushEvent
42
17
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
No
37
No
No
42
48
Push enabled by default.
44
37
No
4.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PushEvent/PushEvent