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.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

メモ: この機能はウェブワーカー内で利用可能です。

PushSubscriptionプッシュ API のインターフェイスで、サブスクリプションの URL エンドポイントを提供し、ここからプッシュサービスの登録を脱退できます。

このインターフェイスのインスタンスはシリアライズできます。

インスタンスプロパティ

PushSubscription.endpoint 読取専用

文字列で、このプッシュサブスクリプションに関連づけられたエンドポイントが入ります。

PushSubscription.expirationTime 読取専用

DOMHighResTimeStamp で、存在すれば、プッシュサブスクリプションに関連付いたサブスクリプションの期限です。存在しない場合は null です。

PushSubscription.options 読取専用

サブスクリプションを作成するために用いられるオプションを含むオブジェクト。

PushSubscription.subscriptionId 非推奨; 読取専用 非標準

文字列で、このプッシュサブスクリプションに関連したサブスクリプション ID が入ります。

インスタンスメソッド

PushSubscription.getKey()

サーバーに送信されてプッシュメッセージの暗号化に使用される、クライアントの公開鍵を含む ArrayBuffer を返します。

PushSubscription.toJSON()

標準シリアライザーです。サブスクリプションプロパティの JSON 記法を返します。

PushSubscription.unsubscribe()

プッシュサービスのサブスクリプションを脱退する非同期プロセスを開始します。現在のサブスクリプションが成功裏に脱退できた場合、論理値で解決される Promise を返します。

js
navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.getSubscription().then((subscription) => {
    subscription
      .unsubscribe()
      .then((successful) => {
        // 成功裏に脱退。
      })
      .catch((e) => {
        // 脱退に失敗。
      });
  });
});

仕様書

Specification
Push API
# pushsubscription-interface

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
PushSubscription
endpoint
expirationTime
getKey()
options
subscriptionId
DeprecatedNon-standard
toJSON()
unsubscribe()

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.

関連項目