pushManager
特性为
ServiceWorkerRegistration
interface returns a reference to the
PushManager
interface for managing push subscriptions; this includes support for subscribing, getting an active subscription, and accessing push permission status.
var pushManager = serviceWorkerRegistration.pushManager;
A
PushManager
对象。
this.onpush = function(event) {
console.log(event.data);
// From here we can write the data to IndexedDB, send it to any open
// windows, display a notification, etc.
}
navigator.serviceWorker.register('serviceworker.js').then(
function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe().then(
function(pushSubscription) {
console.log(pushSubscription.subscriptionId);
console.log(pushSubscription.endpoint);
// The push subscription details needed by the application
// server are now available, and can be sent to it using,
// for example, an XMLHttpRequest.
}, function(error) {
// During development it often helps to log errors to the
// console. In a production environment it might make sense to
// also report information about errors back to the
// application server.
console.log(error);
}
);
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Push API
The definition of 'PushManager' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
pushManager
|
Chrome 40 |
Edge
17
|
Firefox
44
|
IE No | Opera 27 | Safari 11.1 | WebView Android No | Chrome Android 40 | Firefox Android 44 | Opera Android 27 | Safari iOS 11.3 | Samsung Internet Android 4.0 |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。
ServiceWorkerRegistration
active
installing
navigationPreload
onupdatefound
periodicSync
pushManager
scope
sync
waiting