Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ultraviolet-App
Path: blob/main/public/register-sw.js
120 views
1
"use strict";
2
/**
3
* Distributed with Ultraviolet and compatible with most configurations.
4
*/
5
const stockSW = "/uv/sw.js";
6
7
/**
8
* List of hostnames that are allowed to run serviceworkers on http://
9
*/
10
const swAllowedHostnames = ["localhost", "127.0.0.1"];
11
12
/**
13
* Global util
14
* Used in 404.html and index.html
15
*/
16
async function registerSW() {
17
if (!navigator.serviceWorker) {
18
if (
19
location.protocol !== "https:" &&
20
!swAllowedHostnames.includes(location.hostname)
21
)
22
throw new Error("Service workers cannot be registered without https.");
23
24
throw new Error("Your browser doesn't support service workers.");
25
}
26
27
await navigator.serviceWorker.register(stockSW);
28
}
29
30