Fix a “blocked by CORS policy” error while testing
If your own test API is missing CORS headers, you can add them in the browser with HeaderDial, scoped to the API host. In our tests in Chrome 159 and Firefox 158, this fixed every CORS error below except one. When the server answers the OPTIONS preflight with 404 or 405, no added header helps. Then the server has to answer OPTIONS, or you call it through a dev-server proxy. Launching Chrome with --disable-web-security got past all of the errors, including the 404, because Chrome then sent no preflight at all. But it turns off these checks for every site in that window.
This page is a lookup: find the line from your console, then read its cause and fix. For the basic recipe step by step, see Add Access-Control-Allow-Origin for local testing.
Access-Control-Allow-Origin: * on everywhere, and never pair it with credentials. Give the rows an expiry (the select on each row offers 15 min, 1 hour, 8 hours or 1 day) so they switch themselves off.Find your error
The error your code catches says nothing useful. Chrome throws TypeError: Failed to fetch and logs Failed to load resource: net::ERR_FAILED. Firefox throws TypeError: NetworkError when attempting to fetch resource. The reason is in the console line just above. Chrome's line starts with Access to fetch at '…' from origin '…' has been blocked by CORS policy:. Firefox's starts with Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at …. The texts below are copied from our test runs. To match your own message to one of them, paste it into the CORS error explainer.
1. No 'Access-Control-Allow-Origin' header is present on the requested resource
Chrome: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Firefox: (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.
Cause: a simple request (a plain GET, for example) reached the server and got an answer, but the answer has no Access-Control-Allow-Origin. The server did run the request; the browser only hides the response from your code.
Fix: a response header Access-Control-Allow-Origin: *. That alone made the GET work in both browsers.
2. Response to preflight request doesn't pass access control check
Chrome: has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Firefox logs two lines: (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200. and then (Reason: CORS request did not succeed). Status code: (null).
Cause: the request needs a preflight. It sends an Authorization or custom header, a JSON Content-Type, or uses a method such as PUT. The browser asked first with OPTIONS, and that answer had no CORS headers. The real request was never sent; our server saw only the OPTIONS.
Fix: add three response headers: Access-Control-Allow-Origin: *, Access-Control-Allow-Headers and Access-Control-Allow-Methods (see 3 and 4 for values). HeaderDial's headers are added to the OPTIONS response too. Our server answered OPTIONS with an empty 200 or 204 and no CORS headers. With the three headers added, the preflight passed and the real PUT reached the server, in both browsers.
3. Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response
Chrome: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response. (with x-custom or another name in place of authorization for other headers)
Firefox: (Reason: header ‘authorization’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).
Cause: the preflight answer has Access-Control-Allow-Origin but does not allow a header your code sends.
Fix: Access-Control-Allow-Headers: Authorization, Content-Type, X-Custom, listing the headers you send. Name Authorization explicitly. * did let it through in both browsers, but Firefox logged this warning: When the `Access-Control-Allow-Headers` is `*`, the `Authorization` header is not covered. To include the `Authorization` header, it must be explicitly listed in CORS header `Access-Control-Allow-Headers`, and said the request would be blocked “soon”. Chrome logged nothing.
4. Method PUT is not allowed by Access-Control-Allow-Methods in preflight response
Chrome: Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.
Firefox: (Reason: Did not find method in CORS header ‘Access-Control-Allow-Methods’).
Fix: Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE. Without credentials, * also worked in both browsers.
5. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'
Chrome: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. If the request was preflighted, the same text comes after Response to preflight request doesn't pass access control check:.
Firefox: (Reason: Credential is not supported if the CORS header ‘Access-Control-Allow-Origin’ is ‘*’).
Cause: your code sends cookies or HTTP auth (fetch(url, { credentials: 'include' }) or xhr.withCredentials = true), and the response says *.
Fix: set the exact origin of your page and allow credentials:
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Authorization, Content-Type, X-Custom
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE
The origin is scheme, host and port, with no path or trailing slash. With credentials, list the headers and methods by name. In our test, Access-Control-Allow-Methods: * made a credentialed PUT fail with error 4 in both browsers, while the explicit list worked.
6. The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true'
Chrome: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'.
Firefox: (Reason: expected ‘true’ in CORS header ‘Access-Control-Allow-Credentials’).
Fix: you set the exact origin but not Access-Control-Allow-Credentials: true. Add it.
7. Response to preflight request doesn't pass access control check: It does not have HTTP ok status
Chrome: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Firefox: (Reason: CORS preflight response did not succeed). Status code: 404. (or 405), then (Reason: CORS request did not succeed). Status code: (null).
Cause: the server answers OPTIONS with an error status, often 404 or 405 Method Not Allowed because no route handles OPTIONS. A preflight needs a success status.
Headers cannot fix this. We added all four headers from error 5 (and the * versions) to an endpoint whose OPTIONS returned 404, and another that returned 405. The preflight still failed in both browsers, and the real request never reached the server. HeaderDial changes headers, not status codes. The real fixes:
- Make the server answer
OPTIONSwith200or204. CORS middleware for your framework usually does this once it is enabled for that route. - Or call the API through your dev server's proxy, so the browser sees a same-origin request and never sends a preflight. Vite has a
server.proxyoption for this. - Or, briefly, a throwaway Chrome profile with
--disable-web-security(next section).
Before you blame CORS, check the OPTIONS row in the DevTools Network panel. If its status is 4xx or 5xx, this is your case.
--disable-web-security or added headers?
The usual “disable CORS in Chrome” advice is to start a second Chrome like this:
chrome --disable-web-security --user-data-dir=/path/to/empty-folder
We ran it without any extension against the same server and compared it with HeaderDial.
| HeaderDial response headers | Chrome with --disable-web-security | |
|---|---|---|
| Errors 1 to 6 | fixed, with the right headers | all requests worked |
Error 7 (OPTIONS returns 404/405) | still blocked | worked: Chrome sent no OPTIONS request at all, for any of our cases |
| Which sites | only the API host in the Domain filter | every site you open in that window |
| Your logins, extensions, bookmarks | your normal profile | a separate profile in the --user-data-dir folder; a new folder starts empty (Chromium docs) |
| Firefox | works the same (all results matched Chrome) | no such flag (see below) |
| Turning it off | switch the profile off, or let the rows expire | close that Chrome |
What else the flag changes, from our runs:
- It is not only CORS. With the flag alone, a page on
127.0.0.1still could not read the DOM of a cross-site iframe onlocalhost(contentDocumentwasnull). With--disable-site-isolation-trialsadded, as some answers suggest, the page read the iframe's text. Do not browse other sites in that window. - The warning bar. Our runs were headless, so we could not see it. This Chrome build's English strings contain “You are using an unsupported command-line flag: $1. Stability and security will suffer.”, where
$1is the flag. --user-data-dir. The Chrome binary contains the message “Web security may only be disabled if '--user-data-dir' is also specified with a non-default value.” In our headless runs the flag took effect even without--user-data-dir, so we could not confirm when Chrome enforces this. Pass an empty folder anyway, so the unprotected window is never your everyday profile.
Firefox has no --disable-web-security. Its about:config pref content.cors.disable does the opposite of what the name suggests. With it set to true, every cross-origin fetch() in our test failed with (Reason: CORS disabled)., including the plain GET.
Steps in HeaderDial
- Click the HeaderDial icon. If the site access banner shows, allow access. The page and the API are usually on different hosts, and Chrome only changed the response when HeaderDial had access to both (tested here). Choose Allow on all sites, or Only <host> once on a page tab and once on an API tab.
- Click + Response header and add the headers your error needs, from the list above. Leave the op select on set, so it replaces any value the server already sends.
- Open Where it applies, click + Only on…, choose Domain and enter the API host, for example
localhostorapi.dev.example.com. - Set the expiry select on each row, for example 1 hour.
- Reload your app and check that the console line is gone and the Network panel shows the real request after the
OPTIONSone.
Shortcut (HeaderDial 0.7.0): open the popup on your app's tab and pick + Recipe… → CORS: allow calls from this page's origin. It adds Access-Control-Allow-Origin set to that tab's origin, Access-Control-Allow-Credentials: true, the usual methods, and Authorization, Content-Type as allowed headers. Add any other custom header names to that row, then do steps 3 and 4.
Things to know
- An Authorization header added by HeaderDial does not cause a preflight. We added
Authorization: Bearer …as a request header in HeaderDial, and the page made a plainGET. In both browsers the server received oneGETwith the token, and noOPTIONS. The browser decides on a preflight from what your code sends, not what an extension adds. The response still needsAccess-Control-Allow-Origin. The same header set by your own code did trigger a preflight. - The
xmlhttprequestrequest type covers the preflight. With the profile limited to that type, the added headers still reached theOPTIONSresponse in both browsers. - A passed preflight is reused for a short time. In Chrome, we changed the headers so that a credentialed
PUTshould fail, then called the same URL half a second later. Chrome sent no newOPTIONSand the call still worked. A different URL failed at once, and the same URL failed 6 seconds later. After an edit, wait a few seconds before you judge the result. - Make the server right before you ship. Everything here only changes your browser. Your users' browsers still get the server's real headers.
What we measured
A local Node server reachable as http://127.0.0.1:PORT (the page) and http://localhost:PORT (the API), which are different origins. The API sent no CORS headers and answered OPTIONS with an empty 200, 204, 404 or 405, depending on the endpoint. The server logged every request, so we could see whether a preflight or the real request arrived. HeaderDial 0.6.0, host access granted to all sites, one profile limited to Domain localhost. Chrome for Testing 159.0.8154.6 and Firefox 158.0.1, both headless on Linux, 20 November 2026. The flag column is Chrome with --disable-web-security and a new --user-data-dir, no extension.
| Request from the page to the API | Chrome 159 + HeaderDial | Firefox 158 + HeaderDial | Chrome, flag |
|---|---|---|---|
Plain GET, nothing added | blocked (error 1) | blocked (error 1) | works |
Plain GET, Allow-Origin: * | works | works | – |
credentials: 'include', Allow-Origin: * | blocked (error 5) | blocked (error 5) | works |
credentials: 'include', exact origin + Allow-Credentials: true | works | works | – |
PUT JSON or custom header, OPTIONS 200/204, only Allow-Origin: * | blocked (errors 3, 4) | blocked (errors 3, 4) | works, no preflight sent |
Same, with Allow-Origin, Allow-Headers, Allow-Methods | works | works | – |
Authorization from the page, Allow-Headers: * | works, no warning | works, with a warning | works |
Credentialed PUT, exact origin + Allow-Credentials: true, Allow-Methods: * | blocked (error 4) | blocked (error 4) | works |
PUT JSON, OPTIONS 404 or 405, all headers added | blocked (error 7) | blocked (error 7) | works, no preflight sent |
HeaderDial adds Authorization to a plain GET | no preflight; token arrives | no preflight; token arrives | – |
| Read the DOM of a cross-site iframe | – | – | blocked; readable with --disable-site-isolation-trials |
Add to ChromeFirefox: coming soon