start_url does not respond with a 200 when offline

Viewed 42

I've seen other topics about like this one but I couldn't manage to figure out how to fix it in my case.

My offline page works fine, but Lighthouse keeps on throwing the error:

start_url does not respond with a 200 when offlineThe start_url did respond, but not via a service worker.

Here's the part I believe is the critical one:

self.addEventListener('fetch', function (event) {
        console.log("fethcing...");
        var request = event.request;

        // Always fetch non-GET requests from the network
        if (request.method !== 'GET') {
            console.log("is not GET");
            event.respondWith(
                fetch(request)
                    .catch(function () {
                        return caches.match('views/layouts/offline.html');
                    })
            );
            return;
        }

        // For HTML requests, try the network first, fall back to the cache, finally the offline page
        // if (request.headers.get('Accept').indexOf('text/html') !== -1) {

        // Fix for Chrome bug: https://code.google.com/p/chromium/issues/detail?id=573937
        if (request.mode != 'navigate') {
            request = new Request(request.url, {
                method: 'GET',
                headers: request.headers,
                mode: request.mode,
                credentials: request.credentials,
                redirect: request.redirect
            });
        }
        event.respondWith(
            fetch(request)
                .then(function (response) {
                    // Stash a copy of this page in the cache
                    var copy = response.clone();
                    console.log("fetching..." + (version + staticCacheName));
                    caches.open(version + staticCacheName)
                        .then(function (cache) {
                            cache.put(request, copy);
                        });
                    return response;
                })
                .catch(function () {
                    return caches.match(request)
                        .then(function (response) {
                            return response || caches.match('views/layouts/offline.html');
                        })
                })
        );
        return;
    });

And here's the full service worker code.

0 Answers
Related