Revela-Frontend/public/register-sw.js

31 lines
781 B
JavaScript

"use strict";
/**
* Distributed with Ultraviolet and compatible with most configurations.
*/
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 (!navigator.serviceWorker) {
if (
location.protocol !== "https:" &&
!swAllowedHostnames.includes(location.hostname)
)
throw new Error("Service workers cannot be registered without https.");
throw new Error("Your browser doesn't support service workers.");
}
// Ultraviolet has a stock `sw.js` script.
await navigator.serviceWorker.register(stockSW, {
scope: __uv$config.prefix,
});
}