https://github.com/web-platform-tests/wpt
Revision 4091ab0f7cbcb304cdd5b1d1c30264b052359b38 authored by Florian Rivoal on 29 March 2018, 16:46:52 UTC, committed by L. David Baron on 29 March 2018, 16:46:52 UTC
Corresponding to the spec changes decided in https://github.com/w3c/csswg-drafts/issues/2000
1 parent afcd47b
Raw File
Tip revision: 4091ab0f7cbcb304cdd5b1d1c30264b052359b38 authored by Florian Rivoal on 29 March 2018, 16:46:52 UTC
[css-overflow-3] test the flow-relative overflow properties (#10233)
Tip revision: 4091ab0
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