最終更新:2024-01-12 (金) 13:17:46 (108d)  

ServiceWorkerContainer.ready
Top / ServiceWorkerContainer.ready

所与の scriptURL の ServiceWorkerRegistration? を作成または更新

navigator.serviceWorker.ready?

https://developer.mozilla.org/ja/docs/Web/API/ServiceWorkerContainer/register

return

  • ServiceWorkerRegistration?オブジェクトで解決するPromise

  • if ("serviceWorker" in navigator) {
      // 既定のスコープを使用して、
      // サイトのルートでホストされるサービスワーカーを登録します。
      navigator.serviceWorker.register("/sw.js").then(
        (registration) => {
          console.log("サービスワーカー登録成功:", registration);
        },
        /*catch*/ (error) => {
          console.error(`サービスワーカー登録失敗: ${error}`);
        },
      );
    } else {
      console.error("サービスワーカーに対応していません。");
    }