ServiceWorkerContainer: phương thức getRegistration()
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.
Phương thức getRegistration() của giao diện ServiceWorkerContainer lấy một đối tượng ServiceWorkerRegistration có scope URL phù hợp với URL client được cung cấp. Phương thức trả về một Promise resolve thành một ServiceWorkerRegistration hoặc undefined.
Cú pháp
getRegistration()
getRegistration(clientURL)
Tham số
clientURLOptional-
Registration có scope phù hợp với URL này sẽ được trả về. Các URL tương đối được phân giải với client hiện tại làm cơ sở. Nếu không cung cấp tham số này, URL của client hiện tại sẽ được sử dụng theo mặc định.
Giá trị trả về
Một Promise resolve thành một đối tượng ServiceWorkerRegistration hoặc undefined.
Ví dụ
navigator.serviceWorker.getRegistration("/app").then((registration) => {
if (registration) {
document.querySelector("#status").textContent =
"ServiceWorkerRegistration found.";
}
});
Đặc tả kỹ thuật
| Specification |
|---|
| Service Workers Nightly> # navigator-service-worker-getRegistration> |