only throw if navigator.serviceWorker is undefined
This commit is contained in:
parent
f1ff584176
commit
efeae66746
1 changed files with 8 additions and 7 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
const stockSW = "/uv/sw.js";
|
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"];
|
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
|
* Used in 404.html and index.html
|
||||||
*/
|
*/
|
||||||
async function registerSW() {
|
async function registerSW() {
|
||||||
if (
|
if (!navigator.serviceWorker) {
|
||||||
location.protocol !== "https:" &&
|
if (
|
||||||
!swAllowedHostnames.includes(location.hostname)
|
location.protocol !== "https:" &&
|
||||||
)
|
!swAllowedHostnames.includes(location.hostname)
|
||||||
throw new Error("Service workers cannot be registered without https.");
|
)
|
||||||
|
throw new Error("Service workers cannot be registered without https.");
|
||||||
|
|
||||||
if (!navigator.serviceWorker)
|
|
||||||
throw new Error("Your browser doesn't support service workers.");
|
throw new Error("Your browser doesn't support service workers.");
|
||||||
|
}
|
||||||
|
|
||||||
// Ultraviolet has a stock `sw.js` script.
|
// Ultraviolet has a stock `sw.js` script.
|
||||||
await navigator.serviceWorker.register(stockSW, {
|
await navigator.serviceWorker.register(stockSW, {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue