https://github.com/web-platform-tests/wpt
Raw File
Tip revision: dc95d6e03b834edb8aef5b1c9f63187625197117 authored by Dong-hee Na on 10 October 2018, 08:14:18 UTC
Convert blocks.dat to html5lib_blocks.html
Tip revision: dc95d6e
register-and-activate-service-worker.js
async function registerAndActiveServiceWorker(script, scope, callback) {
  const registration = await navigator.serviceWorker.register(script, {scope});
  const serviceWorker =
    registration.installing || registration.waiting || registration.active;
  if (serviceWorker) {
    waitForServiceWorkerActivation(scope, callback);
    return;
  }

  registration.addEventListener('updatefound', event => {
    waitForServiceWorkerActivation(scope, callback);
  });
}

async function waitForServiceWorkerActivation(scope, callback) {
  const registration = await navigator.serviceWorker.getRegistration(scope);
  if (registration.active) {
    callback(registration);
    return;
  }

  const serviceWorker = registration.installing || registration.waiting;
  serviceWorker.addEventListener('statechange', event => {
    if (event.target.state == 'activated') {
      callback(registration);
    }
  });
}
back to top