diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-11-25 13:22:29 -0600 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-11-25 13:22:29 -0600 |
commit | 57125f48cebea05922bb6dc2a999c861dd0e7700 (patch) | |
tree | c01ba4b46933c68acd322ceba9f5d3d17496081b /platform/web | |
parent | 81733e66224ea113cf32b69ea93a6c1342d9c6e7 (diff) | |
parent | 05b266bd8950330935c51938e0ebe159d87316c8 (diff) | |
download | redot-engine-57125f48cebea05922bb6dc2a999c861dd0e7700.tar.gz |
Merge pull request #98069 from thedinosoar/fix/service-worker-sandbox-error-98068
[Web] Fix PWA callback assignment causing crash in sandboxed iframes
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; |