data
只读特性在
ExtendableMessageEvent
interface returns the event's data. It can be any data type.
var myData = extendableMessageEvent.data;
Any data type.
When the following code is used inside a service worker to respond to a push messages by sending the data received via
PushMessageData
to the main context via a
channel message
, the event object of
onmessage
将是
ExtendableMessageEvent
.
var port;
self.addEventListener('push', function(e) {
var obj = e.data.json();
if(obj.action === 'subscribe' || obj.action === 'unsubscribe') {
port.postMessage(obj);
} else if(obj.action === 'init' || obj.action === 'chatMsg') {
port.postMessage(obj);
}
});
self.onmessage = function(e) {
console.log(e.data);
port = e.ports[0];
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'ExtendableMessageEvent.data' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
data
|
Chrome 51 | Edge ≤79 |
Firefox
45
注意事项
|
IE 不支持 No | Opera ? | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 51 | Firefox Android 45 | Opera Android ? | Safari iOS 不支持 No | Samsung Internet Android 5.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
ExtendableMessageEvent
data
lastEventId
origin
ports
source
缓存
CacheStorage
Client
Clients
ExtendableEvent
FetchEvent
InstallEvent
Navigator.serviceWorker
NotificationEvent
PeriodicSyncEvent
PeriodicSyncManager
PeriodicSyncRegistration
ServiceWorker
ServiceWorkerContainer
ServiceWorkerGlobalScope
ServiceWorkerRegistration
SyncEvent
SyncManager
SyncRegistration
WindowClient