Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. ServiceWorkerContainer
  4. ready

ServiceWorkerContainer: ready property

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.

Theready read-only property of theServiceWorkerContainer interface provides a way of delaying code execution until a service worker is active.

The property returns aPromise that will never reject, and which waits indefinitely until theServiceWorkerRegistration associated with the current page has anactive worker.Once that condition is met, it resolves with theServiceWorkerRegistration.

Value

APromise that will never reject, and which may eventually resolve with aServiceWorkerRegistration when there is an active service worker.

Examples

Deferring code until there is an active service worker

js
if ("serviceWorker" in navigator) {  navigator.serviceWorker.ready.then((registration) => {    console.log(`A service worker is active: ${registration.active}`);    // At this point, you can call methods that require an active    // service worker, like registration.pushManager.subscribe()  });} else {  console.error("Service workers are not supported.");}

Specifications

Specification
Service Workers Nightly
# navigator-service-worker-ready

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp