title: Service Worker - Wait for clients.openWindow to complete before postMessage
body: <p>I am using service worker to handle background notifications. When I receive a message, I'm creating a new <code>Notification</code> using <code>self.registration.showNotification(title, { icon, body })</code>. I'm watching for the click event on the notification using <code>self.addEventListener('notificationclick', ()=&gt;{})</code>. On click I'm checking to see if any <code>WindowClient</code> is open, if it is, I'm getting one of those window clients and calling <code>postMessage</code> on it to send the data from the notification to the app to allow the app to process the notification. Incase there is no open window I'm calling <code>openWindow</code> and once that completes I'm sending the data to that window using <code>postMessage</code>.</p>
  
  <pre><code>event.waitUntil(
      clients.matchAll({ type: 'window' }).then((windows) =&gt; {
          if (windows.length &gt; 0) {
              const window = windows[0];
              window.postMessage(_data);
              window.focus();
              return;
          }
          return clients.openWindow(this.origin).then((window) =&gt; {
              window.postMessage(_data);
              return;
          });
      })
  );
  </code></pre>
  
  <p>The issue I am facing is that the <code>postMessage</code> call inside the <code>openWindow</code> is never delivered. I'm guessing this is because the <code>postMessage</code> call on the <code>WindowClient</code> happens before the page has finished loading, so the eventListener is not registered to listen for that message yet? Is that right?</p>
  
  <p>How do I open a new window from the service worker and postMessage to that new window.</p>