From 7a5cabe88998a958994a957998f2e7463cb6c85b Mon Sep 17 00:00:00 2001 From: Pierre Paridans Date: Mon, 11 Dec 2023 11:33:26 +0100 Subject: [PATCH] [FIX] website_event_track: crash in SW's fetch listener on Safari 17.0+ Before this commit, when browsing the "Events" part of website on Safari (both macOS and iOS/ipadOS), the page could be loaded only once and returns a "FetchEvent.respondWith received an error: NotSupportedError: The operation is not supported." error message on afterward, completely blocking access to everything under the `/event` path. This error is actually thrown from the ServiceWorker's `fetch` event's listener, and more specifically, from the storage availablity check. Since Safari 17.0, the Storage API - and in this case its `estimate()` function - has been enabled in WebKit's builds for Apple platforms (see WebKit PR [1]). But even if this feature should be available in Web Workers (cf. MDN [2] and the spec [3]), it returns a NotSupportedError error when called from the ServiceWorker on Safari 17.0+ (but works fine in the global scope). This commit works around that issue by wrapping this call in a try/catch, acting as if not supported when an error happens. Steps to reproduce (on Safari iOS): - Install website_event_track module - Navigate to the `/event` page - Reload the page => Browser level error page "FetchEvent.respondWith received an error..." Note: due to the browser's engine restriction on iOS/ipadOS, this issue also affects all browsers on these platforms. [1]: https://github.com/WebKit/WebKit/pull/10973 [2]: https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/estimate [3]: https://storage.spec.whatwg.org/#ref-for-dom-storagemanager-estimate opw-3553880 opw-3570730 opw-3610167 opw-3629039 opw-3547759 closes odoo/odoo#146190 X-original-commit: 45020635a81ce53ee0769ca54ac733528e4110b1 Signed-off-by: Romeo Fragomeli (rfr) --- .../website_event_track/static/src/js/service_worker.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/website_event_track/static/src/js/service_worker.js b/addons/website_event_track/static/src/js/service_worker.js index b8c04cb4452..2c3654b60a1 100644 --- a/addons/website_event_track/static/src/js/service_worker.js +++ b/addons/website_event_track/static/src/js/service_worker.js @@ -61,8 +61,13 @@ const isCacheFull = async () => { if (!("storage" in navigator && "estimate" in navigator.storage)) { return false; } - const { usage, quota } = await navigator.storage.estimate(); - return usage / quota > MAX_CACHE_QUOTA || usage > MAX_CACHE_SIZE; + try { + const { usage, quota } = await navigator.storage.estimate(); + return usage / quota > MAX_CACHE_QUOTA || usage > MAX_CACHE_SIZE; + } catch (error) { + console.error(`call to storage.estimate failed`, error); + return false; + } }; /**