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 /platform/web | |
parent | b3bcb2dc14691f7729984128dca26a844f662fa1 (diff) | |
download | redot-engine-05b266bd8950330935c51938e0ebe159d87316c8.tar.gz |
Fix PWA callback assignment and error handling
Diffstat (limited to 'platform/web')
-rw-r--r-- | platform/web/js/engine/engine.js | 6 | ||||
-rw-r--r-- | platform/web/js/libs/library_godot_os.js | 25 |
2 files changed, 22 insertions, 9 deletions
diff --git a/platform/web/js/engine/engine.js b/platform/web/js/engine/engine.js index 04c4c44c5e..1aeeb62f18 100644 --- a/platform/web/js/engine/engine.js +++ b/platform/web/js/engine/engine.js @@ -241,7 +241,11 @@ const Engine = (function () { */ installServiceWorker: function () { if (this.config.serviceWorker && 'serviceWorker' in navigator) { - return navigator.serviceWorker.register(this.config.serviceWorker); + try { + return navigator.serviceWorker.register(this.config.serviceWorker); + } catch (e) { + return Promise.reject(e); + } } return Promise.resolve(); }, diff --git a/platform/web/js/libs/library_godot_os.js b/platform/web/js/libs/library_godot_os.js index 568212275b..2899d7e45f 100644 --- a/platform/web/js/libs/library_godot_os.js +++ b/platform/web/js/libs/library_godot_os.js @@ -441,8 +441,12 @@ const GodotPWA = { godot_js_pwa_cb__sig: 'vi', godot_js_pwa_cb: function (p_update_cb) { if ('serviceWorker' in navigator) { - const cb = GodotRuntime.get_func(p_update_cb); - navigator.serviceWorker.getRegistration().then(GodotPWA.updateState.bind(null, cb)); + try { + const cb = GodotRuntime.get_func(p_update_cb); + navigator.serviceWorker.getRegistration().then(GodotPWA.updateState.bind(null, cb)); + } catch (e) { + GodotRuntime.error('Failed to assign PWA callback', e); + } } }, @@ -450,12 +454,17 @@ const GodotPWA = { godot_js_pwa_update__sig: 'i', godot_js_pwa_update: function () { if ('serviceWorker' in navigator && GodotPWA.hasUpdate) { - navigator.serviceWorker.getRegistration().then(function (reg) { - if (!reg || !reg.waiting) { - return; - } - reg.waiting.postMessage('update'); - }); + try { + navigator.serviceWorker.getRegistration().then(function (reg) { + if (!reg || !reg.waiting) { + return; + } + reg.waiting.postMessage('update'); + }); + } catch (e) { + GodotRuntime.error(e); + return 1; + } return 0; } return 1; |