generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 57
/
web-features.ts
25 lines (22 loc) · 925 Bytes
/
web-features.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
declare const ServiceWorkerGlobalScope: any;
export function installNetworkingFeatures(path: string): void {
const workerSelf = self as any;
try {
if (typeof ServiceWorkerGlobalScope !== 'undefined' && workerSelf instanceof ServiceWorkerGlobalScope) {
// Dynamically import service worker code only if we're in a Service Worker context
import('./service-worker.js').catch(error => {
console.error('Error loading service worker module:', error);
});
}
else if (globalThis?.navigator?.serviceWorker) {
if (path) navigator.serviceWorker.register(path).catch(error => {
console.error('DWeb networking feature installation failed: ', error);
});
}
else {
throw new Error('DWeb networking features are not available for install in this environment');
}
} catch (error) {
console.error('Error in installing networking features:', error);
}
}