aboutsummaryrefslogtreecommitdiff
path: root/static/service-worker/index.js
blob: cff4b95e2bc1e09a17352c9ffbb655143087e7ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export const register = async () => {
	if (!'serviceWorker' in navigator) {
		console.warn('service worker not supported by browser');
		return;
	}

	try {
		const registration = await navigator.serviceWorker.register("/service-worker/worker.js", {
			scope: "/",
		});
		if (registration.installing) {
			console.log("Service worker installing");
		} else if (registration.waiting) {
			console.log("Service worker installed");
		} else if (registration.active) {
			console.log("Service worker active");
		}
	} catch (error) {
		console.error(`Registration failed with ${error}`);
	}
}