From 06ca9ca8f352091c64e4ab77dc5aadfeea4ee686 Mon Sep 17 00:00:00 2001 From: edram Date: Thu, 25 Apr 2024 16:47:14 +0800 Subject: [PATCH] Fix unsupported BodyInit type (#581) --- source/core/constants.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/source/core/constants.ts b/source/core/constants.ts index 27309629..207ac613 100644 --- a/source/core/constants.ts +++ b/source/core/constants.ts @@ -9,15 +9,19 @@ export const supportsRequestStreams = (() => { const supportsRequest = typeof globalThis.Request === 'function'; if (supportsReadableStream && supportsRequest) { - hasContentType = new globalThis.Request('https://empty.invalid', { - body: new globalThis.ReadableStream(), - method: 'POST', - // @ts-expect-error - Types are outdated. - get duplex() { - duplexAccessed = true; - return 'half'; - }, - }).headers.has('Content-Type'); + try { + hasContentType = new globalThis.Request('https://empty.invalid', { + body: new globalThis.ReadableStream(), + method: 'POST', + // @ts-expect-error - Types are outdated. + get duplex() { + duplexAccessed = true; + return 'half'; + }, + }).headers.has('Content-Type'); + } catch { + // IOS QQBrowser throw "unsupported BodyInit type" Error (see issue #581) + } } return duplexAccessed && !hasContentType;