0

I am writing an unhandled Promise rejection handler. Within the handler, I want to be able to tell if the rejection is caused by the client blocking a fetch request, via adblock or etc.

With adblock enabled, if you try to fetch "https://ad.doubleclick.net", it shows net::ERR_BLOCKED_BY_CLIENT in the console:

screenshot of Chrome DevTools console showing GET https://ad.doubleclick.net/ net::ERR_BLOCKED_BY_CLIENT

But when that bubbles out to window.onunhandledrejection, there's no way to tell that that's why the Promise was rejected; the error message says "TypeError: failed to fetch", but that's pretty vague.

screenshot of Chrome DevTools showing the properties on a PromiseRejectionEvent

Is there a way to detect that the error is due to adblock?

Suchipi
  • 732
  • 1
  • 6
  • 23

0 Answers0