Failed to fetch is a browser-level failure. You need to inspect the Network tab and server headers before changing application state code.
Symptoms
- Console shows TypeError: Failed to fetch.
- The request is blocked before your code receives a JSON response.
- The same endpoint works with curl but fails in the browser.
Likely causes
- CORS headers are missing or do not allow the origin.
- HTTPS page calls an HTTP endpoint and is blocked as mixed content.
- DNS, TLS, ad blocker or service worker behavior prevents the request.
Fix steps
- Open DevTools Network and inspect the failed request.
- Check CORS, protocol, status, preflight OPTIONS and response headers.
- Reproduce with curl only after confirming the browser request details.
Verify the fix
- Reload with cache disabled.
- Test in an incognito window without extensions.
- Confirm fetch returns a response and error handling reads status safely.
FAQ
Why does curl work but fetch fails?
Browsers enforce CORS and mixed-content rules that curl does not.
Can JavaScript fix missing CORS headers?
No. CORS must be fixed on the responding server or proxy.
Related tools and guides
Last updated: May 18, 2026