Files
Philip WaltonandJeffrey Posnick e917d617a3 Run background-sync tests in a SW environment (#1965)
* Run background-sync tests in a SW environment

* Address review feedback
2019-03-19 13:45:45 -04:00

27 lines
735 B
Plaintext

/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
// {{ version }}
addEventListener('install', (event) => event.waitUntil(skipWaiting()));
addEventListener('activate', (event) => event.waitUntil(clients.claim()));
addEventListener('message', async (event) => {
// Assert the type and meta are correct.
if (event.data.type === 'WINDOW_READY' &&
event.data.meta === 'workbox-window') {
const windows = await clients.matchAll({
type: 'window',
includeUncontrolled: true,
});
for (const win of windows) {
win.postMessage({type: 'sw:message:ready'});
}
}
});