chromium/third_party/blink/web_tests/external/wpt/service-workers/service-worker/navigation-preload/resources/get-state-worker.js

// This worker listens for commands from the page and messages back
// the result.

function handle(message) {
  const np = self.registration.navigationPreload;
  switch (message) {
    case 'getState':
      return np.getState();
    case 'enable':
      return np.enable();
    case 'disable':
      return np.disable();
    case 'setHeaderValue':
      return np.setHeaderValue('insightful');
  }
  return Promise.reject('bad message');
}

self.addEventListener('message', e => {
    e.waitUntil(handle(e.data).then(result => e.source.postMessage(result)));
  });