diff --git a/www/js/app.js b/www/js/app.js index b6233869..a10b5e51 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1435,22 +1435,28 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett function setContentInjectionMode(value) { params.contentInjectionMode = value; if (value === 'jquery') { - if (isServiceWorkerReady()) { - // We need to disable the ServiceWorker - // Unregistering it does not seem to work as expected : the ServiceWorker - // is indeed unregistered but still active... - // So we have to disable it manually (even if it's still registered and active) - navigator.serviceWorker.controller.postMessage({ - 'action': 'disable' - }); - messageChannel = null; - // If we're in electron or nwjs, completely remove the SW (but we need to keep it active if we're in a PWA) - if (typeof window.fs !== 'undefined') { - navigator.serviceWorker.getRegistrations().then(function (registrations) { - registrations.forEach(function (registration) { - registration.unregister(); - }); + // Because the "outer" Service Worker still runs in a PWA app, we don't actually disable the SW in this context, but it will no longer + // be intercepting requests + if ('serviceWorker' in navigator && /\/\/(localhost|kiwix.github.io)\//i.test(window.location.href)) { + serviceWorkerRegistration = null; + } else { + if (isServiceWorkerReady()) { + // We need to disable the ServiceWorker + // Unregistering it does not seem to work as expected : the ServiceWorker + // is indeed unregistered but still active... + // So we have to disable it manually (even if it's still registered and active) + navigator.serviceWorker.controller.postMessage({ + 'action': 'disable' }); + messageChannel = null; + // If we're in electron, completely remove the SW (but we need to keep it active if we're in a PWA) + if (typeof window.fs !== 'undefined') { + navigator.serviceWorker.getRegistrations().then(function (registrations) { + registrations.forEach(function (registration) { + registration.unregister(); + }); + }); + } } } refreshAPIStatus();