From 4f79aef81b7c4644328365bfc33acf0a9ef595bc Mon Sep 17 00:00:00 2001 From: Dmitriy Mozgovoy Date: Tue, 21 May 2024 17:20:15 +0300 Subject: [PATCH] fix(fetch): enhance fetch API detection; (#6413) --- lib/adapters/fetch.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/adapters/fetch.js b/lib/adapters/fetch.js index 3abd8cf..1104553 100644 --- a/lib/adapters/fetch.js +++ b/lib/adapters/fetch.js @@ -17,11 +17,11 @@ const fetchProgressDecorator = (total, fn) => { })); } -const isFetchSupported = typeof fetch !== 'undefined'; -const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined'; +const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function'; +const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function'; // used only inside the fetch adapter -const encodeText = isFetchSupported && (typeof TextEncoder !== 'undefined' ? +const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ? ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) : async (str) => new Uint8Array(await new Response(str).arrayBuffer()) );