diff --git a/services/web/frontend/js/ide.js b/services/web/frontend/js/ide.js index c4ca347a82..7fcf911bd3 100644 --- a/services/web/frontend/js/ide.js +++ b/services/web/frontend/js/ide.js @@ -369,7 +369,7 @@ If the project has been renamed please look in your project list for a new proje if (getMeta('ol-resetServiceWorker')) { unregisterServiceWorker() } else if (getMeta('ol-enablePdfCaching')) { - loadServiceWorker() + loadServiceWorker({ timeout: 5000 }) } export default angular.bootstrap(document.body, ['SharelatexApp']) diff --git a/services/web/frontend/js/ide/pdfng/directives/serviceWorkerManager.js b/services/web/frontend/js/ide/pdfng/directives/serviceWorkerManager.js index 5ac9eaa65d..7d0fe6ac95 100644 --- a/services/web/frontend/js/ide/pdfng/directives/serviceWorkerManager.js +++ b/services/web/frontend/js/ide/pdfng/directives/serviceWorkerManager.js @@ -11,9 +11,9 @@ export function waitForServiceWorker() { return pendingWorkerSetup } -export function loadServiceWorker() { +export function loadServiceWorker(options) { if (supportsServiceWorker()) { - pendingWorkerSetup = navigator.serviceWorker + const workerSetup = navigator.serviceWorker .register('/serviceWorker.js', { scope: '/project/', }) @@ -38,6 +38,14 @@ export function loadServiceWorker() { .catch(error => captureException(OError.tag(error, 'Cannot register serviceWorker')) ) + if (options && options.timeout > 0) { + const workerTimeout = new Promise(resolve => { + setTimeout(resolve, options.timeout) + }) + pendingWorkerSetup = Promise.race([workerSetup, workerTimeout]) + } else { + pendingWorkerSetup = workerSetup + } } }