ServiceWorkerRegistration: updatefound イベント
updatefound は ServiceWorkerRegistration インターフェイスのイベントで、 ServiceWorkerRegistration.installing プロパティが新しいサービスワーカーが取得するたびに呼び出されます。
構文
このイベント名を addEventListener() のようなメソッドで使用したり、イベントハンドラープロパティに設定したりしてください。
js
addEventListener("updatefound", (event) => {});
onupdatefound = (event) => {};
イベント型
一般的な Event です。
例
js
const registration = await navigator.serviceWorker.getRegistration();
if (registration) {
registration.addEventListener("updatefound", () => {
console.log('サービスワーカーの更新版が見つかりました。');
});
}
仕様書
| Specification |
|---|
| Service Workers # dom-serviceworkerregistration-onupdatefound |
ブラウザーの互換性
BCD tables only load in the browser