Skip to content

Commit c6620ab

Browse files
committed
chore: register service worker manually, also catch errors
1 parent c2f2029 commit c6620ab

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

frontend/src/ts/ready.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,21 @@ $(async (): Promise<void> => {
5252
void registration.unregister();
5353
}
5454
});
55+
} else {
56+
if ("serviceWorker" in navigator) {
57+
window.addEventListener("load", () => {
58+
navigator.serviceWorker
59+
.register("/sw.js", { scope: "/" })
60+
.then((registration) => {
61+
console.log(
62+
"ServiceWorker registration successful with scope: ",
63+
registration.scope
64+
);
65+
})
66+
.catch((error: unknown) => {
67+
console.error("ServiceWorker registration failed: ", error);
68+
});
69+
});
70+
}
5571
}
5672
});

frontend/vite.config.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default {
9090
ViteMinifyPlugin({}),
9191
VitePWA({
9292
// injectRegister: "networkfirst",
93-
injectRegister: "script-defer",
93+
injectRegister: null,
9494
registerType: "autoUpdate",
9595
manifest: {
9696
short_name: "Monkeytype",

0 commit comments

Comments
 (0)