BackgroundFetchRegistration: progress イベント

Limited availability

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

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

BackgroundFetchRegistration インターフェイスの progress イベントは、関連するバックグラウンドフェッチに進捗があった際に投げられます。

実際には、このイベントは下記プロパティのいずれかが更新されるときに発火します。

構文

addEventListener() 等のメソッドでイベント名を使用するか、関連する BackgroundFetchRegistration オブジェクトに onprogress というイベントプロパティを設定します。

js
addEventListener("progress", (event) => { })
onprogress = (event) => { }

イベント型

追加のプロパティを持たない汎用 Event

以下の例は、ダウンロードの進捗をログ出力する方法を示しています。このコードでは、バックグラウンドフェッチが登録された際に、まず downloadTotal が設定されていることを確認します。これは downloaded プロパティに基づいてダウンロードの進捗を計算するために使用されます。

js
bgFetch.addEventListener("progress", () => {
  if (!bgFetch.downloadTotal) return;
  const percent = Math.round(
    (bgFetch.downloaded / bgFetch.downloadTotal) * 100,
  );
  console.log(`ダウンロードの進捗: ${percent}%`);
});

仕様書

Specification
Background Fetch
# background-fetch-registration-events

ブラウザーの互換性

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
progress event
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.