Here's a minimal code of a service worker:
if (event.request.mode === 'navigate' || (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
event.respondWith(
fetch(event.request).catch(function (error) {
console.error(error);
})
);
return;
}
When there's a network issue, the error variable basically just says:
TypeError: Failed to fetch
We print this to the user in the "offline page", but it really never helps understanding what the problem is.
Is it possible to get something more meaningful?
Even if we could catch the Google Chrome code, like net::ERR_INTERNET_DISCONNECTED or net::ERR_CONNECTION_RESET, etc...