Thanks to visit codestin.com
Credit goes to developer.mozilla.org

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

BackgroundFetchEvent

Limited availability

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

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

Background Fetch APIBackgroundFetchEvent インターフェイスは、 service worker global scope で実行されるバックグラウンドのフェッチイベントのためのイベント型です。

これはイベント型で、onbackgroundfetchabort 、および、 onbackgroundfetchclick イベントハンドラープロパティに渡されます。

Event ExtendableEvent BackgroundFetchEvent

コンストラクター

BackgroundFetchEvent() Experimental

新規に BackgroundFetchEvent オブジェクトを作成します。通常、このコンストラクターが使用されることはありません。なぜなら、これらのオブジェクトはブラウザーによって自動で生成され、バックグラウンドのフェッチイベントのコールバックに渡されるからです。

プロパティ

祖先である Event のプロパティを継承します。

BackgroundFetchEvent.registration 読取専用 Experimental

イベントが初期化された BackgroundFetchRegistration を返します。

イベントハンドラー

なし。

メソッド

なし。

以下の例では、ユーザーがダウンロードの進捗表示のUIをクリックすると、新規にウィンドウが開きます。event.registration を呼び出して、現在の BackgroundFetchRegistration を取得しています。

js
addEventListener("backgroundfetchclick", (event) => {
  const bgFetch = event.registration;

  if (bgFetch.result === "success") {
    clients.openWindow("/latest-podcasts");
  } else {
    clients.openWindow("/download-progress");
  }
});

仕様書

Specification
Background Fetch
# background-fetch-event

ブラウザーの互換性