apparently chrome is a shit browser
This commit is contained in:
@@ -1815,9 +1815,12 @@
|
|||||||
const streamUrl = `/api/v2/export/stream?id=${streamId}&filename=${encodeURIComponent(suggestedFileName)}`;
|
const streamUrl = `/api/v2/export/stream?id=${streamId}&filename=${encodeURIComponent(suggestedFileName)}`;
|
||||||
const worker = new Worker(URL.createObjectURL(new Blob([workerCode], { type: 'application/javascript' })));
|
const worker = new Worker(URL.createObjectURL(new Blob([workerCode], { type: 'application/javascript' })));
|
||||||
|
|
||||||
// The SW must be controlling this page to intercept /api/v2/export/stream.
|
// The SW must be controlling this page or be active to intercept /api/v2/export/stream.
|
||||||
// .controller is null after hard refresh — in that case, reload once.
|
let sw = navigator.serviceWorker.controller;
|
||||||
const sw = navigator.serviceWorker.controller;
|
if (!sw) {
|
||||||
|
const reg = await navigator.serviceWorker.getRegistration('/api/v2/export/');
|
||||||
|
sw = reg ? reg.active : null;
|
||||||
|
}
|
||||||
if (!sw) {
|
if (!sw) {
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
exportStatusMsg.textContent = 'Reloading to activate Service Worker...';
|
exportStatusMsg.textContent = 'Reloading to activate Service Worker...';
|
||||||
|
|||||||
@@ -618,11 +618,34 @@
|
|||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
navigator.serviceWorker.register('/sw.js').then((registration) => {
|
navigator.serviceWorker.getRegistrations().then((registrations) => {
|
||||||
window.f0ckDebug('ServiceWorker registration successful with scope: ', registration.scope);
|
let rootFound = false;
|
||||||
}, (err) => {
|
let scopedFound = false;
|
||||||
|
|
||||||
|
for (let r of registrations) {
|
||||||
|
try {
|
||||||
|
const scopePath = new URL(r.scope).pathname;
|
||||||
|
if (scopePath === '/') {
|
||||||
|
r.unregister().then(() => {
|
||||||
|
console.log('[SW] Root ServiceWorker cleaned up.');
|
||||||
|
});
|
||||||
|
rootFound = true;
|
||||||
|
} else if (scopePath === '/api/v2/export/') {
|
||||||
|
scopedFound = true;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the scoped service worker so that exports still work on settings page
|
||||||
|
// without intercepting normal site requests.
|
||||||
|
if (!scopedFound || rootFound) {
|
||||||
|
navigator.serviceWorker.register('/sw.js', { scope: '/api/v2/export/' }).then((registration) => {
|
||||||
|
window.f0ckDebug('ServiceWorker registered with scoped path: ', registration.scope);
|
||||||
|
}).catch((err) => {
|
||||||
window.f0ckDebug('ServiceWorker registration failed: ', err);
|
window.f0ckDebug('ServiceWorker registration failed: ', err);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user