Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Why do I get TypeError failed to fetch on every page refresh #290

Open
marcofranssen opened this issue Dec 21, 2019 · 4 comments
Open

Why do I get TypeError failed to fetch on every page refresh #290

marcofranssen opened this issue Dec 21, 2019 · 4 comments

Comments

@marcofranssen
Copy link

marcofranssen commented Dec 21, 2019

I'm struggling to resolve the following error on my webblog.

Why do I get TypeError failed to fetch on every page refresh. Only the very first time I load the page it loads without errors. Then on every refresh I get errors.

https://marcofranssen.nl

The FetchEvent for "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" resulted in a network error response: the promise was rejected.
Promise.then (async)
r @ sw.js?t=1576961691623:17
sw.js?t=1576961691623:1 Uncaught (in promise) TypeError: Failed to fetch
(index):1780 GET https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js net::ERR_FAILED
(index):1812 ServiceWorker Register Successfully.

I have been checking this for a while now, but don't have any clue how to resolve.

I hope someone is able to point me in a solution direction.

My code looks as following:

self.addEventListener('install', function () {
  return self.skipWaiting();
});
self.addEventListener('active', function () {
  return self.clients.claim();
});

var precacheUrls = [
  '/',
  '/about/',
  '/git-recipes/',
  '/signing-docker-images-using-docker-content-trust/',
  '/secure-2fa-ssh-and-pgp-using-krypton/',
  '/howto-secure-shell-easily-from-the-terminal/',
  '/manage-go-tools-via-go-modules/',
  '/install-fresh-raspbian-image-on-your-raspberry-pi-part-2/',
];

toolbox.precache(precacheUrls);
toolbox.options = {"networkTimeoutSeconds":5};

toolbox.router.any(/^https:\/\/(www\.google-analytics\.com|pagead2\.googlesyndication\.com)/, toolbox.networkOnly);
toolbox.router.any(/.*\.(js|css|jpg|jpeg|png|gif)$/, toolbox.cacheFirst);
toolbox.router.any(/content.json$/, toolbox.cacheFirst);
toolbox.router.any(/\//, toolbox.networkFirst);
@Lucent
Copy link

Lucent commented Jan 30, 2021

Did you figure this out? I have the same issue, but only with Edge Chromium. First request to ads goes through, but further that are handled by a fetch event in a service worker return that error. Is it cross-origin related?

@marcofranssen
Copy link
Author

@Lucent This is what I run now. Never tried to get ads working via service worker as I couldn't really figure it out.

self.addEventListener('install', function () { return self.skipWaiting(); });
self.addEventListener('active', function () { return self.clients.claim(); });

toolbox.precache(['/','/about/','/git-recipes/','/hello-next-js-goodbye-hexo/','/remove-files-from-git-history-using-git-filter-repo/','/nginx-1-19-supports-environment-variables-and-templates-in-docker/','/building-a-elasticsearch-cluster-using-docker-compose-and-traefik/','/use-the-acme-dns-challenge-to-get-a-tls-certificate/']);
toolbox.options = {"networkTimeoutSeconds":5};

toolbox.router.any(/www\.google-analytics\.com/, toolbox.networkOnly);
toolbox.router.any(/.*\.(js|css|jpg|jpeg|png|gif)$/, toolbox.cacheFirst);
toolbox.router.any(/content.json$/, toolbox.cacheFirst);
toolbox.router.any(/\//, toolbox.networkFirst);

@Lucent
Copy link

Lucent commented Jan 31, 2021

Did you have uBlock Origin enabled at the time and your site whitelisted? If so, I identified a problem with the extension on Edge that may have been the cause, for future visitors: uBlockOrigin/uBlock-issues#1478

@gorhill
Copy link

gorhill commented Jan 31, 2021

@Lucent The change in uBO causing the issue was caused by a relatively recent change, it did not exist back in December 2019.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants