ServiceWorkerRegistration: pushManager プロパティ
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
pushManager
は ServiceWorkerRegistration
インターフェイスのプロパティで、プッシュサブスクリプションを管理するための PushManager
インターフェイスへの参照を返します。 これには、サブスクリプションへの参加、アクティブなサブスクリプションの取得、プッシュ通知の許可状況へのアクセスの対応が含まれます。
構文
PushManager
オブジェクトです。
例
js
this.onpush = (event) => {
console.log(event.data);
// ここから、IndexedDB にデータを書き込んだり、いずれかのウィンドウに
// それを送信したり、通知を表示したりできます。
};
navigator.serviceWorker
.register("serviceworker.js")
.then((serviceWorkerRegistration) => {
serviceWorkerRegistration.pushManager.subscribe().then(
(pushSubscription) => {
console.log(pushSubscription.subscriptionId);
console.log(pushSubscription.endpoint);
// アプリケーションサーバが必要としているプッシュサブスクリプションの
// 詳細はここから使用できます。たとえば、XMLHttpRequest を使用して
// これを送信できます。
},
(error) => {
// 開発中は、コンソールにエラーを表示するのに役立ちます。
// 本番環境では、アプリケーションサーバにエラー情報を送信
// するためにも 役立ちます。
console.error(error);
},
);
});
仕様書
Specification |
---|
Push API # dom-serviceworkerregistration-pushmanager |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
pushManager |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
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.