title: How do I handle a rejected Promise in a Service Worker install event?
body: <p>I have a case where I need to catch a rejected promise from a Service Worker install event and display an error message.</p>
  <p>I've set up a test Service Worker called <code>testsw.js</code> which immediately throws a rejected promise, like so:</p>
  <pre><code>console.log(&quot;Hello from SW&quot;);
  self.addEventListener('install', function (evt) {
      evt.waitUntil(Promise.reject(new Error(&quot;Test&quot;)));
  })
  </code></pre>
  <p>and I'm registering the Service Worker using the following code:</p>
  <pre><code>navigator.serviceWorker.register('/testsw.js')
          .then(function (reg) {
               console.log(&quot;Service worker successfully registered.&quot;, reg);
          })
          .catch(function (err) {
              console.error(&quot;Service worker failed to register.&quot;, err);
          })
  </code></pre>
  <p>The <code>catch</code> function is never hit in this case, and registering the Service worker results in this console output:</p>
  <pre class="lang-none prettyprint-override"><code>testsw.js:1 Hello from SW
  testsw.js:3 Uncaught (in promise) Error: Test
      at testsw.js:3
  (anonymous) @ testsw.js:3
  (index):468 Service worker successfully registered. ServiceWorkerRegistration
  </code></pre>
  <p>I've already tried wrapping the rejected promise in a function and calling that in <code>evt.waitUntil()</code>, as well as throwing a plain Error, with no change. The Service Worker is still put into the redundant state, which is good, but I still need to know that the installation failed.</p>
  <p>Am I misunderstanding how rejected promises work in a Service Worker installation? Is there something misconfigured in the registration that would make it always hit the <code>then</code> block, even if the promise is rejected? Failing that, is there something in the <code>ServiceWorkerRegistration</code> class or somewhere else that would tell us that the service worker failed to install or update?</p>
  <p><sup>If it makes a difference, this was tested in Chrome 77 and Edge 83 with no success.</sup></p>