add error for non-whitelisted http: locations

This commit is contained in:
David Reed 2022-12-03 16:13:39 -05:00
parent 32b1bd3d9d
commit f91cd415f2
No known key found for this signature in database
GPG key ID: 2211691D8A1EE72F

View file

@ -4,11 +4,22 @@
*/
const stockSW = "/uv/sw.js";
/**
* List of hostnames that are allowed to run serviceworkers on http:
*/
const swAllowedHostnames = ["localhost", "127.0.0.1"];
/**
* Global util
* Used in 404.html and index.html
*/
async function registerSW() {
if (
location.protocol !== "https:" &&
!swAllowedHostnames.includes(location.hostname)
)
throw new Error("Service workers cannot be registered without https.");
if (!navigator.serviceWorker)
throw new Error("Your browser doesn't support service workers.");