PushSubscription
Baseline 2023
Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
PushSubscription
はプッシュ API のインターフェイスで、サブスクリプションの URL エンドポイントを提供し、ここからプッシュサービスの登録を脱退できます。
このインターフェイスのインスタンスはシリアライズできます。
インスタンスプロパティ
PushSubscription.endpoint
読取専用-
文字列で、このプッシュサブスクリプションに関連づけられたエンドポイントが入ります。
PushSubscription.expirationTime
読取専用-
DOMHighResTimeStamp
で、存在すれば、プッシュサブスクリプションに関連付いたサブスクリプションの期限です。存在しない場合はnull
です。 PushSubscription.options
読取専用-
サブスクリプションを作成するために用いられるオプションを含むオブジェクト。
PushSubscription.subscriptionId
非推奨 読取専用-
文字列で、このプッシュサブスクリプションに関連したサブスクリプション ID が入ります。
インスタンスメソッド
PushSubscription.getKey()
-
サーバーに送信されてプッシュメッセージの暗号化に使用される、クライアントの公開鍵を含む
ArrayBuffer
を返します。 PushSubscription.toJSON()
-
標準シリアライザーです。サブスクリプションプロパティの JSON 記法を返します。
PushSubscription.unsubscribe()
-
プッシュサービスのサブスクリプションを脱退する非同期プロセスを開始します。現在のサブスクリプションが成功裏に脱退できた場合、論理値で解決される
Promise
を返します。
例
navigator.serviceWorker.ready.then((reg) => {
reg.pushManager.getSubscription().then((subscription) => {
subscription
.unsubscribe()
.then((successful) => {
// 成功裏に脱退。
})
.catch((e) => {
// 脱退に失敗。
});
});
});
仕様書
Specification |
---|
Push API # pushsubscription-interface |
ブラウザーの互換性
BCD tables only load in the browser