MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / supportsNativeFetch

Function supportsNativeFetch

packages/core/src/utils/supports.ts:106–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104 * @returns true if `window.fetch` is natively implemented, false otherwise
105 */
106export function supportsNativeFetch(): boolean {
107 if (typeof EdgeRuntime === 'string') {
108 return true;
109 }
110
111 if (!_isFetchSupported()) {
112 return false;
113 }
114
115 // Fast path to avoid DOM I/O
116 // eslint-disable-next-line @typescript-eslint/unbound-method
117 if (isNativeFunction(WINDOW.fetch)) {
118 return true;
119 }
120
121 // window.fetch is implemented, but is polyfilled or already wrapped (e.g: by a chrome extension)
122 // so create a "pure" iframe to see if that has native fetch
123 let result = false;
124 const doc = WINDOW.document;
125 // eslint-disable-next-line typescript/no-deprecated
126 if (doc && typeof (doc.createElement as unknown) === 'function') {
127 try {
128 const sandbox = doc.createElement('iframe');
129 sandbox.hidden = true;
130 doc.head.appendChild(sandbox);
131 if (sandbox.contentWindow?.fetch) {
132 // eslint-disable-next-line @typescript-eslint/unbound-method
133 result = isNativeFunction(sandbox.contentWindow.fetch);
134 }
135 doc.head.removeChild(sandbox);
136 } catch (err) {
137 DEBUG_BUILD && debug.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
138 }
139 }
140
141 return result;
142}
143
144/**
145 * Tells whether current environment supports ReportingObserver API

Callers 2

instrumentFetchFunction · 0.90
_wrapFetchFunction · 0.85

Calls 3

_isFetchSupportedFunction · 0.85
isNativeFunctionFunction · 0.85
warnMethod · 0.65

Tested by

no test coverage detected