import { getNativeFetchImplementation } from "https://deno.land/x/sentry_deno@v0.2.2/packages/browser/src/transports/utils.ts";
A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers. Whenever someone wraps the Fetch API and returns the wrong promise chain, this chain becomes orphaned and there is no possible way to capture it's rejections other than allowing it bubble up to this very handler. eg.
const f = window.fetch; window.fetch = function () { const p = f.apply(this, arguments);
p.then(function() { console.log('hi.'); });
return p; }
p.then(function () { ... })
is producing a completely separate promise chain,
however, what's returned is p
- the result of original fetch
call.
This mean, that whenever we use the Fetch API to send our own requests, and some ad-blocker blocks it, this orphaned chain will always reject, effectively causing another event to be captured. This makes a whole process become an infinite loop, which we need to somehow deal with, and break it in one way or another.
To deal with this issue, we are making sure that we always use the real
browser Fetch API, instead of relying on what window.fetch
exposes.
The only downside to this would be missing our own requests as breadcrumbs,
but because we are already not doing this, it should be just fine.
Possible failed fetch error messages per-browser:
Chrome: Failed to fetch Edge: Failed to Fetch Firefox: NetworkError when attempting to fetch resource Safari: resource blocked by content blocker