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

PushMessageData 接口在 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);
  }
});
					

规范

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

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
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

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

元数据

  • 最后修改:
  1. Push API
  2. PushMessageData
  3. 方法
    1. arrayBuffer()
    2. blob()
    3. json()
    4. text()
  4. Related pages for Push API
    1. PushEvent
    2. PushManager
    3. PushSubscription
    4. ServiceWorkerGlobalScope.onpush
    5. ServiceWorkerGlobalScope.onpushsubscriptionchange
    6. ServiceWorkerRegistration.pushManager

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1