Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Service worker `fetch` fails in `install` event when trying to cache assets

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
webclientjavascriptdevelopmentsaleschrome
2 Odpowiedzi
966 Widoki
Awatar
Nyan Min Htet

Hello everyone,


  I am trying to implement offline functionality for the Odoo Sales app using a custom service worker. I am facing an issue where the

  service worker fails to fetch the list of assets to cache during its install event.


  Here's what I have done so far:


  1.    Created a custom Odoo module (pwa_sales_offline) that depends on web, sale_management, and stock.
  2.    Created a custom service worker at pwa_sales_offline/static/src/service_worker.js.
  3. Overridden the default service worker by creating a controller that inherits from odoo.addons.web.controllers.webmanifest.WebManifest and overrides the _get_service_worker_content method to serve my custom file.
  4. Created a controller to get the list of assets. This controller calls request.env['ir.qweb']._get_asset_nodes('web.assets_backend', True, True, False, False, request.env.context) and returns the list of asset URLs as a JSON response.
  5. The service worker's install event fetches this list of assets and tries to cache them using cache.addAll().


  The Problem:


  ​The fetch call within the service worker's install event fails with the error: Uncaught (in promise) TypeError: Failed to fetch.


  What I have tried:


   * I have verified that the controller that returns the list of assets is working correctly by opening its URL (/pwa_sales_offline/assets)

     directly in the browser. It successfully returns a JSON array of asset URLs.

   * I have tried changing the auth of the controller to public.

   * I have tried changing the type of the controller to both http and json.

   * I have added a check in the service worker's fetch event to prevent it from intercepting its own requests to the assets endpoint.


  The Code:


  Here is the relevant code:


import logging

import json

from odoo import http

from odoo.http import request

from odoo.tools import file_open

from odoo.addons.web.controllers.webmanifest import WebManifest


_logger = logging.getLogger(__name__)


class PwaSalesOfflineWebManifest(WebManifest):

def _get_service_worker_content(self):

_logger.info("Serving custom service worker")

with file_open('pwa_sales_offline/static/src/service_worker.js') as f:

return f.read()


@http.route('/pwa_sales_offline/assets', type='http', auth='public', methods=['GET'], csrf=False)

def get_assets(self):

_logger.info("Getting assets for PWA")

qweb = request.env['ir.qweb']

nodes = qweb._get_asset_nodes('web.assets_backend', True, True, False, False, request.env.context)

files = []

for node in nodes:

if len(node) == 2:

tag, attrs = node

if 'href' in attrs:

files.append(attrs['href'])

elif 'src' in attrs:

files.append(attrs['src'])

elif len(node) == 3:

tag, attrs, content = node

if 'href' in attrs:

files.append(attrs['href'])

elif 'src' in attrs:

files.append(attrs['src'])

_logger.info("Found %d assets", len(files))

return request.make_json_response(files)

const STATIC_CACHE_NAME = 'odoo-sales-offline-static-cache';


self.addEventListener('install', (event) => {

console.log('Custom Service Worker: Installed!');

event.waitUntil(

fetch('/pwa_sales_offline/assets').then((response) => {

return response.json();

}).then((files) => {

return caches.open(STATIC_CACHE_NAME).then((cache) => {

return cache.addAll(files);

});

})

);

});


self.addEventListener('fetch', (event) => {

console.log('Custom Service Worker: Fetching', event.request.url);

const url = new URL(event.request.url);


if (url.pathname === '/pwa_sales_offline/assets') {

return;

}


// Serve static assets from cache

if (url.origin === location.origin) {

event.respondWith(

caches.match(event.request).then((response) => {

return response || fetch(event.request);

})

);

return;

}


// Cache data

const DATA_CACHE_NAME = 'odoo-sales-offline-data-cache';

if (url.pathname === '/web/dataset/search_read') {

event.respondWith(

fetch(event.request.clone()).then((response) => {

if (response.status === 200) {

event.request.clone().json().then((payload) => {

if (payload.params && (payload.params.model === 'res.partner' || payload.params.model === 'product.product')) {

const cacheRequest = event.request.clone();

const cacheResponse = response.clone();

caches.open(DATA_CACHE_NAME).then((cache) => {

cache.put(cacheRequest, cacheResponse);

});

}

});

}

return response;

}).catch(() => {

return caches.match(event.request);

})

);

}

});

  


  ​I would appreciate any help or suggestions on how to solve this issue. Is there a better way to get the asset list from within the

  service worker? Or is there something I'm missing about how fetch works in this context?


  Thank you

0
Awatar
Odrzuć
Awatar
Nyan Min Htet
Autor Najlepsza odpowiedź

Thank You for your suggestion. I will try to approach with other point 

0
Awatar
Odrzuć
Awatar
Cybrosys Techno Solutions Pvt.Ltd
Najlepsza odpowiedź

Hi,


The root cause of your issue is that during the service worker’s install event, cache.addAll() fails if any asset URL isn’t publicly accessible. Some Odoo assets (like /web/content/...) require a logged-in session and return redirects or errors, so the fetch fails and breaks the whole install.


The solution is to avoid pre-caching restricted assets. Instead, pre-cache only public resources (like /web/assets/debug bundles, manifest, icons) and use runtime caching in the fetch event to store backend assets and API calls as they’re requested. This hybrid approach ensures the service worker installs cleanly while still giving offline support.


Hope it helps

0
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Remove/Disable "My Orders" button from mobile menu page for POS
webclient development sales shop
Awatar
Awatar
1
lip 25
1124
Custom Cards Payment Module: POS Payment Summary Not Updating with Installments
javascript development sales project
Awatar
Awatar
2
lut 25
2178
Help with Subscription Webhooks
webclient javascript development accounting debug
Awatar
Awatar
1
paź 25
768
how to resolve (500 (INTERNAL SERVER ERROR) on login screen
javascript development configuration debug chrome
Awatar
Awatar
Awatar
3
wrz 25
1766
How can we unit test javascript components in web addons?
webclient javascript development v6.1 v7
Awatar
Awatar
1
mar 15
8202
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now