ServiceWorkerContainer: getRegistration() method
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 insecure contexts (HTTPS), in some or allsupporting browsers.
Note: This feature is available inWeb Workers.
ThegetRegistration() method of theServiceWorkerContainer interface gets aServiceWorkerRegistration object whose scope URL matches the providedclient URL. The method returns aPromise that resolves toaServiceWorkerRegistration orundefined.
In this article
Syntax
getRegistration()getRegistration(clientURL)Parameters
clientURLOptionalThe registration whose scope matches this URL will be returned. Relative URLs are resolved with the current client as the base. If this parameter is not provided, the current client's URL will be used by default.
Return value
APromise that resolves to aServiceWorkerRegistrationobject orundefined.
Examples
navigator.serviceWorker.getRegistration("/app").then((registration) => { if (registration) { document.querySelector("#status").textContent = "ServiceWorkerRegistration found."; }});Specifications
| Specification |
|---|
| Service Workers Nightly> # navigator-service-worker-getRegistration> |