{{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.
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', 'PushManager')}} | {{Spec2('Push API')}} | Initial definition. |
Browser Compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android | |
---|---|---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
|
See also
- Using the Push API
- Push Notifications on the Open Web, Matt Gaunt