diff --git a/public/register-sw.js b/public/register-sw.js index a0f6df1..37c8ea2 100644 --- a/public/register-sw.js +++ b/public/register-sw.js @@ -5,7 +5,7 @@ const stockSW = "/uv/sw.js"; /** - * List of hostnames that are allowed to run serviceworkers on http: + * List of hostnames that are allowed to run serviceworkers on http:// */ const swAllowedHostnames = ["localhost", "127.0.0.1"]; @@ -14,14 +14,15 @@ const swAllowedHostnames = ["localhost", "127.0.0.1"]; * 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) { + 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."); + } // Ultraviolet has a stock `sw.js` script. await navigator.serviceWorker.register(stockSW, {