Fix CORS errors in local development
Your frontend on http://localhost:3000 calls an API on another origin, and the console says "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present". The browser is doing its job: the API didn't say your origin may read its answers. Here are the fixes, best first.
1. Let the API allow your origin
If you control the API, have it answer with Access-Control-Allow-Origin: http://localhost:3000 (and the methods and headers you use) in development. Most frameworks have a CORS setting for this. It's the only fix that also works for everyone else on your team.
2. Proxy the API through your dev server
Make the browser think the API is on your own origin. In Vite:
// vite.config.js
export default { server: { proxy: { '/api': 'https://api.example.com' } } };
webpack's devServer.proxy, Next.js rewrites and Angular's proxy.conf.json do the same. Requests to /api are same-origin, so CORS never comes up.
3. Add the headers in the browser, for testing
When you can't change the API or the build (someone else's staging API, a quick check), a header extension can add the response headers the browser looks for. In Headerwise, the CORS: allow any origin preset adds:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Allow-Headers: *
Add an only on filter for the API (for example ||api.example.com^), so you don't change the rules for every site you visit.
- Cookies or Authorization with credentials. With
credentials: 'include'the browser rejects*. SetAccess-Control-Allow-Originto your exact origin (http://localhost:3000) and addAccess-Control-Allow-Credentials: true. - The preflight fails. For a JSON
POSTor a custom header, the browser first sendsOPTIONS. If the API answers that with 404 or 405, headers alone won't fix it: use the proxy or fix the API. - Your own test setup adds a header. A header added by the page or by Playwright's
extraHTTPHeadersmakes requests "non-simple" and triggers a preflight; a header added by the extension doesn't.
What not to do
Starting Chrome with --disable-web-security turns off the same-origin protection for everything in that browser profile. If you must, use a throwaway profile (--user-data-dir) and never browse with it.