ExtendableCookieChangeEvent

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

「Cookie Store API」ExtendableCookieChangeEvent インターフェイスは、Cookie が何か変更された時 ServiceWorkerRegistration.oncookiechange() に渡されるイベント型です。Cookie の変更イベントは、Cookie と種類 ("changed" または "deleted") からなります。

ExtendableCookieChangeEvent を発生させる Cookie の変更は、以下のものがあります。

  • Cookie が新規作成され、すぐには削除されません。この場合の type"changed" です。
  • Cookie が新規作成され、すぐに削除されます。この場合の type"deleted" です。
  • Cookie が削除されます。この場合の type"deleted" です。

メモ: 同じ名前・ドメイン・パスの他の Cookie が挿入されることにより置き換えられる Cookie は無視され、変更イベントを発生させません。

Event ExtendableEvent ExtendableCookieChangeEvent

コンストラクター

ExtendableCookieChangeEvent()

新しい ExtendableCookieChangeEvent を生成します。

インスタンスプロパティ

このインターフェイスは、ExtendableEvent からもプロパティを継承します。

ExtendableCookieChangeEvent.changed 読取専用

変更された Cookie が格納された配列を返します。

ExtendableCookieChangeEvent.deleted 読取専用

削除された Cookie が格納された配列を返します。

以下の例では、CookieStoreManager.getSubscriptions() を用いて現在ある購読のリストを取得します。(サービスワーカーでは、イベントを監視するには購読が必要です) CookieStoreManager.unsubscribe() を用いて既存の購読を解除し、CookieStoreManager.subscribe() を用いて名前が 'COOKIE_NAME' である Cookie を購読します。この Cookie が変更されると、イベントリスナーがイベントをコンソールに記録します。これは、変化が起きた Cookie が格納された changed プロパティまたは deleted プロパティを持つ ExtendableCookieChangeEvent オブジェクトです。

js
self.addEventListener("activate", (event) => {
  event.waitUntil(async () => {
    const subscriptions = await self.registration.cookies.getSubscriptions();
    await self.registration.cookies.unsubscribe(subscriptions);

    await self.registration.cookies.subscribe([
      {
        name: "COOKIE_NAME",
      },
    ]);
  });
});

self.addEventListener("cookiechange", (event) => {
  console.log(event);
});

仕様書

Specification
Cookie Store API
# ExtendableCookieChangeEvent

ブラウザーの互換性

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
ExtendableCookieChangeEvent
ExtendableCookieChangeEvent() constructor
changed
partitioned property
Experimental
deleted
partitioned property
Experimental

Legend

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

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.