-
Notifications
You must be signed in to change notification settings - Fork 10
/
chemical.sw.js
46 lines (41 loc) · 1.08 KB
/
chemical.sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const rammerheadEnabled = false;
const scramjetEnabled = false;
const uvEnabled = true;
if (uvEnabled) {
importScripts("/uv/uv.bundle.js");
importScripts("/uv/uv.config.js");
importScripts(__uv$config.sw || "/uv/uv.sw.js");
}
if (scramjetEnabled) {
importScripts("/scramjet/scramjet.wasm.js");
importScripts("/scramjet/scramjet.shared.js");
importScripts("/scramjet/scramjet.worker.js");
}
if (navigator.userAgent.includes("Firefox")) {
Object.defineProperty(globalThis, "crossOriginIsolated", {
value: true,
writable: false,
});
}
let uv, scramjet;
if (uvEnabled) {
uv = new UVServiceWorker();
}
if (scramjetEnabled) {
scramjet = new ScramjetServiceWorker();
}
self.addEventListener("fetch", (event) => {
event.respondWith(
(async () => {
if (scramjetEnabled) {
await scramjet.loadConfig();
}
if (uvEnabled && uv.route(event)) {
return await uv.fetch(event);
} else if (scramjetEnabled && scramjet.route(event)) {
return await scramjet.fetch(event);
}
return await fetch(event.request);
})()
);
});