PushMessageData

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

PushMessageData interface of the Push API provides methods which let you retrieve the push data sent by a server in various formats.

Unlike the similar methods in the 抓取 API , which only allow the method to be invoked once, these methods can be called multiple times.

Messages received through the Push API are sent encrypted by push services and then automatically decrypted by browsers before they are made accessible through the methods of the PushMessageData 接口。

特性

None.

方法

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

范例

self.addEventListener('push', function(event) {
  var obj = event.data.json();
  if(obj.action === 'subscribe' || obj.action === 'unsubscribe') {
    fireNotification(obj, event);
    port.postMessage(obj);
  } else if(obj.action === 'init' || obj.action === 'chatMsg') {
    port.postMessage(obj);
  }
});
					

规范

规范 状态 Comment
Push API
The definition of 'PushMessageData' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
PushMessageData
Chrome 50 Edge ≤79 Firefox 44
注意事项
44
注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera 37 Safari 不支持 No WebView Android 不支持 No Chrome Android 50 Firefox Android 48 Opera Android 37 Safari iOS 不支持 No Samsung Internet Android 5.0
arrayBuffer
Chrome 50 Edge ≤79 Firefox 44
注意事项
44
注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera 37 Safari 不支持 No WebView Android 不支持 No Chrome Android 50 Firefox Android 48 Opera Android 37 Safari iOS 不支持 No Samsung Internet Android 5.0
blob
Chrome 50 Edge ≤79 Firefox 44
注意事项
44
注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera 37 Safari 不支持 No WebView Android 不支持 No Chrome Android 50 Firefox Android 48 Opera Android 37 Safari iOS 不支持 No Samsung Internet Android 5.0
json
Chrome 50 Edge ≤79 Firefox 44
注意事项
44
注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera 37 Safari 不支持 No WebView Android 不支持 No Chrome Android 50 Firefox Android 48 Opera Android 37 Safari iOS 不支持 No Samsung Internet Android 5.0
text
Chrome 50 Edge ≤79 Firefox 44
注意事项
44
注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera 37 Safari 不支持 No WebView Android 不支持 No Chrome Android 50 Firefox Android 48 Opera Android 37 Safari iOS 不支持 No Samsung Internet Android 5.0

图例

完整支持
完整支持
不支持
不支持
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
见实现注意事项。