{"record":{"id":"94ce940277f664be","repo":"dotnet/runtime","slug":"this-browser-doesn-t-support-fetch-api-please-use","errorCode":null,"errorMessage":"This browser doesn't support fetch API. Please use a modern browser. See also https://learn.microsoft.com/aspnet/core/blazor/supported-platforms","messagePattern":"This browser doesn't support fetch API\\. Please use a modern browser\\. See also https://learn\\.microsoft\\.com/aspnet/core/blazor/supported-platforms","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/http.ts","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT license.\n\nimport BuildConfiguration from \"consts:configuration\";\n\nimport { wrap_as_cancelable_promise } from \"./cancelable-promise\";\nimport { ENVIRONMENT_IS_NODE, loaderHelpers, mono_assert } from \"./globals\";\nimport { assert_js_interop } from \"./invoke-js\";\nimport { MemoryViewType, Span } from \"./marshal\";\nimport type { VoidPtr } from \"./types/emscripten\";\nimport { ControllablePromise } from \"./types/internal\";\nimport { mono_log_debug } from \"./logging\";\n\n\nfunction verifyEnvironment () {\n    if (typeof globalThis.fetch !== \"function\" || typeof globalThis.AbortController !== \"function\") {\n        const message = ENVIRONMENT_IS_NODE\n            ? \"Please install `node-fetch` and `node-abort-controller` npm packages to enable HTTP client support.\"\n            : \"This browser doesn't support fetch API. Please use a modern browser. See also https://learn.microsoft.com/aspnet/core/blazor/supported-platforms\";\n        throw new Error(message);\n    }\n}\n\nfunction commonAsserts (controller: HttpController) {\n    assert_js_interop();\n    mono_assert(controller, \"expected controller\");\n}\n\nexport function http_wasm_supports_streaming_request (): boolean {\n    // Detecting streaming request support works like this:\n    // If the browser doesn't support a particular body type, it calls toString() on the object and uses the result as the body.\n    // So, if the browser doesn't support request streams, the request body becomes the string \"[object ReadableStream]\".\n    // When a string is used as a body, it conveniently sets the Content-Type header to text/plain;charset=UTF-8.\n    // So, if that header is set, then we know the browser doesn't support streams in request objects, and we can exit early.\n    // Safari does support streams in request objects, but doesn't allow them to be used with fetch, so the duplex option is tested, which Safari doesn't currently support.\n    // See https://developer.chrome.com/articles/fetch-streaming-requests/\n    if (typeof Request !== \"undefined\" && \"body\" in Request.prototype && typeof ReadableStream === \"function\" && typeof TransformStream === \"function\") {\n        let duplexAccessed = false;","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/http.ts#L2-L38","documentation":"Thrown by verifyEnvironment() in http.ts when NOT on Node (i.e. a browser/shell) and globalThis.fetch or globalThis.AbortController is missing. It indicates the host browser is too old to support the Fetch API, which the .NET WASM HttpClient depends on.","triggerScenarios":"Produced when http_wasm_create_controller or http_wasm_fetch runs in a non-Node environment that lacks fetch or AbortController.","commonSituations":"Targeting very old browsers (old Safari, legacy Edge, embedded WebViews) that predate fetch support; running in a shell host (e.g. a JS engine without Web APIs) that the runtime nonetheless detects as non-Node.","solutions":["Target a modern, supported browser (see the linked Blazor supported-platforms doc).","Update the embedded WebView/Shell to a version with fetch and AbortController.","If you must support an old browser, provide a fetch polyfill (e.g. whatwg-fetch) and an AbortController polyfill on globalThis before booting the runtime."],"exampleFix":"// before: booting in an old WebView\n// createDotnetRuntime(opts) // throws on HttpClient use\n\n// after: polyfill fetch/AbortController in legacy WebView before boot\nimport 'whatwg-fetch';\nimport 'abortcontroller-polyfill/dist/polyfill-patch-fetch';\nawait createDotnetRuntime(opts);","handlingStrategy":"validation","validationCode":"function browserHttpReady() {\n  return typeof globalThis.fetch === 'function' && typeof globalThis.AbortController === 'function';\n}\nif (!browserHttpReady()) {\n  // polyfill or block the feature\n}","typeGuard":"function supportsFetch(): boolean {\n  return typeof globalThis.fetch === 'function' && typeof globalThis.AbortController === 'function';\n}","tryCatchPattern":null,"preventionTips":["Declare a modern browserslist / supported-platforms policy.","Feature-detect fetch before using HttpClient and show a graceful message on legacy browsers.","Polyfill fetch and AbortController early in legacy WebView hosts."],"tags":["network","browser","fetch","http","environment"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}