The Wayback Machine - https://web.archive.org/web/20150905074952/https://developer.mozilla.org/en-US/docs/Web/API/PushMessageData

PushMessageData

by 3 contributors:

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

The PushMessageData interface of the Push API provides access to push data sent by a server, and methods to manipulate the data.

Properties

None

Methods

PushMessageData.arrayBuffer()
Extracts the data as an ArrayBuffer object.
PushMessageData.blob()
Extracts the data as a Blob object.
PushMessageData.json()
Extracts the data as a JSON object.
PushMessageData.text()
Extracts the data as a plain text string.

Examples

self.addEventListener('push', function(event) {
  if (!(self.Notification && self.notification.permission === 'granted')) {
    return;
  }

  var data = {};
  if (event.data) {
    data = event.data.json();
  }
  var title = data.title || "Something Has Happened";
  var message = data.message || "Here's something you might want to check out.";
  var icon = "images/new-notification.png";

  var notification = new Notification(title, {
    body: message,
    tag: 'simple-push-demo-notification',
    icon: icon
  });

  notification.addEventListener('click', function() {
    if (clients.openWindow) {
      clients.openWindow('https://example.blog.com/2015/03/04/something-new.html');
    }
  };
});

Specifications

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

Browser Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support Not supported Not supported Not supported Not supported Not supported
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support Not supported Not supported Not supported Not supported Not supported Not supported Not supported Not supported

See also

Document Tags and Contributors

Contributors to this page: chrisdavidmills, jpmedley, nyrosmith
Last updated by: chrisdavidmills,