Search code examples
google-chrome-devtoolscache-controlfetch-api

Cache-control directive (only-if-cached) changed by dev-tools?


We are working on a Progessive Web App, for which the service worker intercepts the network traffic (via the fetch event handler). We have noticed, that sometimes a certain request fails here, because Request.cache is only-if-cached and Request.mode is no-cors, but not same-origin.

So it is similar to this problem.

Then I've noticed, that this happens only when the Chrome (v 65) DevTools are not opened. Does anybody notice the same phenomenon and does anybody have an idea, why this happens this way?

Parts of the request:

bodyUsed: false,
cache: "only-if-cached",
credentials: "include",
destination: "unknown",
headers: Headers {},
integrity: "",
method: "GET",
mode: "no-cors",
redirect: "follow",
referrer: "",
referrerPolicy: "no-referrer-when-downgrade",
url: "https://example.com/path/to/app-name/#!

We are handling this problem like this, but I'm afraid, that this is not appropriate.

serviceWorkerGlobal.addEventListener('fetch', function(event)
{
    if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
        var oStrangeRequest = event.request.clone();
        console.log('Fetch. Request cache has only-if-cached, but not same-origin.',
            oStrangeRequest.cache, oStrangeRequest.mode,
            'request redirect:',
            oStrangeRequest.redirect, oStrangeRequest.url, oStrangeRequest);
        return;
    }
    // ...
});

Solution

  • This is a bug. You can check the progress of the fix here: https://bugs.chromium.org/p/chromium/issues/detail?id=823392