UNPKG

1.78 kBTypeScriptView Raw
1export declare type FetchImpl = typeof fetch;
2/**
3 * A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
4 * Whenever someone wraps the Fetch API and returns the wrong promise chain,
5 * this chain becomes orphaned and there is no possible way to capture it's rejections
6 * other than allowing it bubble up to this very handler. eg.
7 *
8 * const f = window.fetch;
9 * window.fetch = function () {
10 * const p = f.apply(this, arguments);
11 *
12 * p.then(function() {
13 * console.log('hi.');
14 * });
15 *
16 * return p;
17 * }
18 *
19 * `p.then(function () { ... })` is producing a completely separate promise chain,
20 * however, what's returned is `p` - the result of original `fetch` call.
21 *
22 * This mean, that whenever we use the Fetch API to send our own requests, _and_
23 * some ad-blocker blocks it, this orphaned chain will _always_ reject,
24 * effectively causing another event to be captured.
25 * This makes a whole process become an infinite loop, which we need to somehow
26 * deal with, and break it in one way or another.
27 *
28 * To deal with this issue, we are making sure that we _always_ use the real
29 * browser Fetch API, instead of relying on what `window.fetch` exposes.
30 * The only downside to this would be missing our own requests as breadcrumbs,
31 * but because we are already not doing this, it should be just fine.
32 *
33 * Possible failed fetch error messages per-browser:
34 *
35 * Chrome: Failed to fetch
36 * Edge: Failed to Fetch
37 * Firefox: NetworkError when attempting to fetch resource
38 * Safari: resource blocked by content blocker
39 */
40export declare function getNativeFetchImplementation(): FetchImpl;
41/** Clears cached fetch impl */
42export declare function clearCachedFetchImplementation(): void;
43//# sourceMappingURL=utils.d.ts.map
\No newline at end of file