Ensure service workers are supported before use

Fixes #909.
This commit is contained in:
Asher 2019-08-15 15:13:22 -05:00
parent 72fe124e30
commit d1662d7658
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A

View File

@ -757,14 +757,18 @@ index 622bb7889b..66dd4b0bbc 100644
self.addEventListener('message', event => {
diff --git a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts
index dfda6a1cfb..44a01fb0fb 100644
index dfda6a1cfb..9bd1aa3e64 100644
--- a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts
+++ b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts
@@ -24,7 +24,7 @@ const _serviceWorker = new class ServiceWorkerStarter {
@@ -24,7 +24,11 @@ const _serviceWorker = new class ServiceWorkerStarter {
private _messageHandler?: (event: ExtendableMessageEvent) => void;
constructor() {
- navigator.serviceWorker.register(ServiceWorkerStarter._url, { scope: '/' }).then(reg => {
+ if (!navigator.serviceWorker) {
+ console.warn('Service workers are not enabled.');
+ return;
+ }
+ navigator.serviceWorker.register(ServiceWorkerStarter._url, { scope: window.location.pathname.replace(/\/+$/, '') }).then(reg => {
// console.debug('SW#reg', reg);
return reg.update();