title: What can cause a Promise rejected with 'InvalidStateError' here?
body: <p>What can cause a Promise rejected with <code>'InvalidStateError'</code> here ?</p>
  
  <pre><code>const SERVICE_WORKER_VERSION = "3.0.0"; // is updated in the build when things change
  const CACHE_VERSION = SERVICE_WORKER_VERSION;
  
  const fillServiceWorkerCache = function () {
      /* save in cache some static ressources 
      this happens before activation */
      return caches.open(CACHE_VERSION).then(function(cache) {
          return cache.addAll(ressourcesToSaveInCache);
      });
  };
  
  self.addEventListener("install", function (event) {
      /*event.waitUntil takes a promise that should resolves successfully*/
      event.waitUntil(fillServiceWorkerCache().then(function() {
          return self.skipWaiting();
      }));
  });
  </code></pre>
  
  <p>On Firefox version 52 the following error occurs: <code>Service worker event waitUntil() was passed a promise that rejected with 'InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable'.</code> The service worker is killed and removed after that. It works fine with Chrome. <code>ressourcesToSaveInCache</code> is an array of relative URLs.</p>
  
  <p>Edit changing it to</p>
  
  <pre><code>event.waitUntil(
      fillServiceWorkerCache()
      .then(skipWaiting)
      .catch(skipWaiting)
  );
  </code></pre>
  
  <p>and the service worker registers ! However <code>fillServiceWorkerCache</code> rejected , which is a big deal (no offline cache). Now the question is why does <code>fillServiceWorkerCache</code> reject, and what is the error message trying to tell ?</p>
  
  <p>Edit inspired by Hosar's answer: </p>
  
  <pre><code>const fillServiceWorkerCache2 = function () {
      return caches.open(CACHE_VERSION).then(function (cache) {
          return Promise.all(
              ressourcesToSaveInCache.map(function (url) {
                  return cache.add(url).catch(function (reason) {
                      return console.log(url + "failed: " + String(reason));
                  })
              })
          );
      });
  };
  </code></pre>
  
  <p>This version propagates a promise in the return chain, making the <code>waitUntil()</code> actually wait for it. It will not cache and also not reject for individual ressources that failed to be added in the cache.</p>
  
  <p>Edit 2: After fixing invalid relative URLs in ressourcesToSaveInCache, the error was gone</p>