mirror of
https://github.com/outline/outline.git
synced 2026-11-26 15:43:48 +03:00
hide the service worker behind a globally registered function
This commit is contained in:
1 parent
43800acf0d
commit
bbeac9fa31
1 file changed
+29
-21
+29
-21
@@ -1,25 +1,33 @@
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616
|
||||
// In some rare (<0.1% of cases) this call can return `undefined`
|
||||
const maybePromise = navigator.serviceWorker.register("/sw.js", {
|
||||
scope: "/",
|
||||
});
|
||||
|
||||
if (maybePromise?.then) {
|
||||
maybePromise
|
||||
.then((registration) => {
|
||||
console.log("[ServiceWorker] Registered.", registration);
|
||||
})
|
||||
.catch((registrationError) => {
|
||||
console.log(
|
||||
"[ServiceWorker] Registration failed. ",
|
||||
registrationError
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
declare global {
|
||||
interface Window {
|
||||
executeServiceWorkerCode: () => void;
|
||||
}
|
||||
}
|
||||
|
||||
window.executeServiceWorkerCode = () => {
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616
|
||||
// In some rare (<0.1% of cases) this call can return `undefined`
|
||||
const maybePromise = navigator.serviceWorker.register("/sw.js", {
|
||||
scope: "/",
|
||||
});
|
||||
|
||||
if (maybePromise?.then) {
|
||||
maybePromise
|
||||
.then((registration) => {
|
||||
console.log("[ServiceWorker] Registered.", registration);
|
||||
})
|
||||
.catch((registrationError) => {
|
||||
console.log(
|
||||
"[ServiceWorker] Registration failed. ",
|
||||
registrationError
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Add an empty 'export {}' statement to make it a module.
|
||||
export default {};
|
||||
Reference in new issue
Block a user