ServiceWorkerRegistration: sự kiện updatefound

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Sự kiện updatefound của giao diện ServiceWorkerRegistration được kích hoạt bất cứ khi nào thuộc tính ServiceWorkerRegistration.installing có được một service worker mới.

Cú pháp

Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt một thuộc tính trình xử lý sự kiện.

js
addEventListener("updatefound", (event) => { })

onupdatefound = (event) => { }

Kiểu sự kiện

Một Event tổng quát.

Ví dụ

js
const registration = await navigator.serviceWorker.getRegistration();
if (registration) {
  registration.addEventListener("updatefound", () => {
    console.log("Đã tìm thấy bản cập nhật Service Worker!");
  });
}

Đặc tả kỹ thuật

Specification
Service Workers Nightly
# dom-serviceworkerregistration-onupdatefound

Tương thích trình duyệt

Xem thêm