1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24

content / test / data / back_forward_cache / service_worker_post_message.js [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

let clientList = [];

self.addEventListener('message', async e => {
  switch (e.data.command) {
    case 'StoreClients':
      e.waitUntil(new Promise(resolve => {
        done = resolve;
      }));
      clientList = await clients.matchAll({
        includeUncontrolled: true, type: 'window'});
      e.ports[0].postMessage('DONE');
      break;
    case 'PostMessageToStoredClients':
      for (const client of clientList)
        client.postMessage('hello!');
      e.ports[0].postMessage('DONE');
      done();
      break;
  }
});