Run Chrome with CORS enable on MacOS / Windows / Linux

Dakshika Jayathilaka
2 min readJun 4, 2024

--

CORS blocked

When running your app in a local environment, you might need to connect to APIs. However, modern browsers block Cross-Origin Resource Sharing (CORS) by default in JavaScript APIs. Here are a couple of options:

  1. Include CORS Headers: You can include the proper CORS headers in the response from your server to allow requests from the specified origin.
  2. Disable Same-Origin Policy for Local Testing:

to run Google Chrome without CORS restrictions, follow these steps:

For MacOS

open -na Google\ Chrome --args --user-data-dir=/tmp/temporary-chrome-profile-dir 
--disable-web-security --disable-site-isolation-trials

For Windows

  • Right click on the desktop, create a new shortcut
  • Add the target as
"[PATH_TO_CHROME]\chrome.exe" --disable-web-security --user-data-dir=~/chromeTemp
  • Click OK.

For Linux

google-chrome --disable-web-security

Remember that this approach is for development purposes only. In production, it’s essential to handle CORS properly to ensure security and prevent unauthorized access. If possible, consider setting the necessary CORS headers on your server or deploying your app on the same domain as the service you want to call.

Happy Coding..!

--

--