diff options
author | Keegan McGonigle <31631874+thedinosoar@users.noreply.github.com> | 2024-10-10 11:21:50 -0700 |
---|---|---|
committer | Keegan McGonigle <31631874+thedinosoar@users.noreply.github.com> | 2024-10-22 10:28:21 -0700 |
commit | 05b266bd8950330935c51938e0ebe159d87316c8 (patch) | |
tree | 77d482d5193b84d4defec716ade75dd2adc38f3a /misc/dist | |
parent | b3bcb2dc14691f7729984128dca26a844f662fa1 (diff) | |
download | redot-engine-05b266bd8950330935c51938e0ebe159d87316c8.tar.gz |
Fix PWA callback assignment and error handling
Diffstat (limited to 'misc/dist')
-rw-r--r-- | misc/dist/html/editor.html | 34 | ||||
-rw-r--r-- | misc/dist/html/full-size.html | 8 |
2 files changed, 26 insertions, 16 deletions
diff --git a/misc/dist/html/editor.html b/misc/dist/html/editor.html index 3a22055546..4f2a3bc053 100644 --- a/misc/dist/html/editor.html +++ b/misc/dist/html/editor.html @@ -363,24 +363,28 @@ window.addEventListener('load', () => { btn.style.display = ''; } if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('service.worker.js').then(function (reg) { - if (reg.waiting) { - notifyUpdate(reg.waiting); - } - reg.addEventListener('updatefound', function () { - const update = reg.installing; - update.addEventListener('statechange', function () { - if (update.state === 'installed') { - // It's a new install, claim and perform aggressive caching. - if (!reg.active) { - update.postMessage('claim'); - } else { - notifyUpdate(update); + try { + navigator.serviceWorker.register('service.worker.js').then(function (reg) { + if (reg.waiting) { + notifyUpdate(reg.waiting); + } + reg.addEventListener('updatefound', function () { + const update = reg.installing; + update.addEventListener('statechange', function () { + if (update.state === 'installed') { + // It's a new install, claim and perform aggressive caching. + if (!reg.active) { + update.postMessage('claim'); + } else { + notifyUpdate(update); + } } - } + }); }); }); - }); + } catch (e) { + console.error('Error while registering service worker:', e); + } } const missing = Engine.getMissingFeatures({ diff --git a/misc/dist/html/full-size.html b/misc/dist/html/full-size.html index 352046df30..4998863cb8 100644 --- a/misc/dist/html/full-size.html +++ b/misc/dist/html/full-size.html @@ -152,9 +152,15 @@ const engine = new Engine(GODOT_CONFIG); if (missing.length !== 0) { if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) { + let serviceWorkerRegistrationPromise; + try { + serviceWorkerRegistrationPromise = navigator.serviceWorker.getRegistration(); + } catch (err) { + serviceWorkerRegistrationPromise = Promise.reject(new Error('Service worker registration failed.')); + } // There's a chance that installing the service worker would fix the issue Promise.race([ - navigator.serviceWorker.getRegistration().then((registration) => { + serviceWorkerRegistrationPromise.then((registration) => { if (registration != null) { return Promise.reject(new Error('Service worker already exists.')); } |