--- title: ServiceWorkerRegistration.pushManager slug: Web/API/ServiceWorkerRegistration/pushManager translation_of: Web/API/ServiceWorkerRegistration/pushManager ---
{{domxref("ServiceWorkerRegistration")}} 接口的 pushManager
属性返回用于管理推送订阅的 {{domxref("PushManager")}} 接口的引用。包括支持订阅,获取活动订阅和访问推送权限状态。
myPushManager = ServiceWorker.pushManager
一个 {{domxref("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); } ); });
Specification | Status | Comment |
---|---|---|
{{SpecName('Push API', '#pushmanager-interface', 'PushManager')}} | {{Spec2('Push API')}} | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatChrome(42.0)}} | {{ CompatGeckoDesktop("44.0") }}[1] | {{CompatNo}} | {{CompatUnknown}} | {{CompatNo}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatChrome(42.0)}} |
[1] Service workers (and Push) have been disabled in the Firefox 45 and 52 Extended Support Releases (ESR.)