// @odoo-module ignore /* eslint-disable no-restricted-globals */ /* eslint-disable no-undef */ const cacheName = "odoo-pos-cache"; const fetchCacheRespond = async (event) => { const cache = await caches.open(cacheName); try { const response = await fetch(event.request); cache.put(event.request, response.clone()); return response; } catch { return await cache.match(event.request); } }; const cacheResources = async (event) => { const url = event.request.url; try { const cache = await caches.open(cacheName); await cache.add(url); } catch (error) { console.info("Failed to cache resource", url, error); } }; self.addEventListener("fetch", (event) => { const url = event.request.url; // Ignore Chrome extensions and dataset. Dataset will be cached in indexedDB. if ( url.includes("extension") || url.includes("web/dataset") || url.includes("hw_proxy/hello") || event.request.method !== "GET" ) { return; } event.respondWith(fetchCacheRespond(event)); }); // Handle notification self.addEventListener("message", (event) => { const data = event.data; if (data.urlsToCache && navigator.onLine) { for (const url of data.urlsToCache) { cacheResources({ request: { url } }); } } });