{{APIRef("Push API")}}{{SeeCompatTable()}}
The PushMessageData
interface of the Push API provides access to push data sent by a server, and methods to manipulate the data.
Unlike the similar methods in the Fetch API, which only allow the method to be invoked once, these methods can be called multiple times.
Properties
None
Methods
- {{domxref("PushMessageData.arrayBuffer()")}}
- Extracts the data as an {{domxref("ArrayBuffer")}} object.
- {{domxref("PushMessageData.blob()")}}
- Extracts the data as a {{domxref("Blob")}} object.
- {{domxref("PushMessageData.json()")}}
- Extracts the data as a JSON object.
- {{domxref("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 |
---|---|---|
{{SpecName('Push API', '#pushmessagedata-interface', 'PushMessageData')}} | {{Spec2('Push API')}} | Initial definition. |
Browser Compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
See also
- Using the Push API
- Push Notifications on the Open Web, Matt Gaunt