This repository has been archived by the owner on Oct 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3da14be
commit 9e28fba
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"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 ( | ||
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, { | ||
scope: __uv$config.prefix, | ||
}); | ||
} |