Merge pull request #4038 from sdissegna-maystreet/main
[#4013] backported https://github.com/microsoft/vscode/pull/131408
This commit is contained in:
commit
15b39e6811
|
@ -242,7 +242,28 @@ const workerReady = new Promise(async (resolve, reject) => {
|
|||
}
|
||||
};
|
||||
navigator.serviceWorker.addEventListener('message', versionHandler);
|
||||
assertIsDefined(registration.active).postMessage({ channel: 'version' });
|
||||
|
||||
const postVersionMessage = () => {
|
||||
assertIsDefined(navigator.serviceWorker.controller).postMessage({ channel: 'version' });
|
||||
};
|
||||
|
||||
// At this point, either the service worker is ready and
|
||||
// became our controller, or we need to wait for it.
|
||||
// Note that navigator.serviceWorker.controller could be a
|
||||
// controller from a previously loaded service worker.
|
||||
const currentController = navigator.serviceWorker.controller;
|
||||
if (currentController && currentController.scriptURL.endsWith(swPath)) {
|
||||
// service worker already loaded & ready to receive messages
|
||||
postVersionMessage();
|
||||
} else {
|
||||
// either there's no controlling service worker, or it's an old one:
|
||||
// wait for it to change before posting the message
|
||||
const onControllerChange = () => {
|
||||
navigator.serviceWorker.removeEventListener('controllerchange', onControllerChange);
|
||||
postVersionMessage();
|
||||
};
|
||||
navigator.serviceWorker.addEventListener('controllerchange', onControllerChange);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
reject(new Error(`Could not register service workers: ${error}.`));
|
||||
|
|
Loading…
Reference in New Issue