Angular PWA with Firebase - Page does not work offline

Viewed 162

Recently, my PWA gives a warning in Chrome, that it cannot be installed:

Chrome Warning

The given Link states, that in the future, the ServiceWorker needs 3 things:

Updated offline detection logic The updated offline detection logic checks:

  • That there is a service worker installed for the page.
  • That the installed service worker has a fetch event.
  • That the installed service worker fetch event returns an HTTP 200 status code (indicating a successful fetch) in simulated offline mode.

The last paragraph is the new one.

Using the code from the page the google links

self.addEventListener('fetch', (event) => {
  if (event.request.method === 'GET') {
    event.respondWith(
      (async () => {
        try {
          // First, try to use the navigation preload response if it's supported.
          const preloadResponse = await event.preloadResponse;
          if (preloadResponse) {
            return preloadResponse;
          }

          // Always try the network first.
          const networkResponse = await fetch(event.request);
          return networkResponse;
        } catch (error) {
          // catch is only triggered if an exception is thrown, which is likely
          // due to a network error.
          // If fetch() returns a valid HTTP response with a response code in
          // the 4xx or 5xx range, the catch() will NOT be called.
          console.log("Fetch failed; returning offline page instead.", error);

          const cache = await caches.open(CACHE_NAME);
          const cachedResponse = await cache.match(OFFLINE_URL);
          return cachedResponse;
        }
      })()
    );
  }
});

Unfortunately, this leads to:

Chrome Error 2

What needs to be done, to comply with the new specs?

0 Answers
Related