ServiceWorkerRegistration:updatefound 事件
注意:此功能在 Web Workers 中可用。
updatefound 事件是 ServiceWorkerRegistration 介面的事件,當 ServiceWorkerRegistration.installing 屬性獲取到一個新的 service worker 時,就會觸發此事件。
語法
在諸如 addEventListener() 之類的方法中使用事件名稱,或設定事件處理程式屬性。
js
addEventListener("updatefound", (event) => { })
onupdatefound = (event) => { }
事件型別
一個通用的 Event。
示例
js
const registration = await navigator.serviceWorker.getRegistration();
if (registration) {
registration.addEventListener("updatefound", () => {
console.log("Service Worker update found!");
});
}
規範
| 規範 |
|---|
| Service Workers # dom-serviceworkerregistration-onupdatefound |
瀏覽器相容性
載入中…