DEV Community

Cover image for How to Run Google Chrome without CORS Error
junian
junian

Posted on • Originally published at junian.net on

How to Run Google Chrome without CORS Error

If you're a Web developer you probably have a task to test your REST API locally.
When you're using a browser like Google Chrome, you may experience some issues like the following message.

Access to fetch at 'http://localhost:8080/api' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Don't worry, it's actually a good security measure by modern web browsers.

I don't want to bother you with the details about CORS, you can read it on official documentation. But if you must know, here's the summary from wikipedia.

Cross-origin resource sharing (CORS) is a mechanism to safely bypass the Same-origin policy, that is, it allows a web page to access restricted resources from a server on a domain different than the domain that served the web page.

An example of a cross-origin request: the front-end JavaScript code served from https://example.com/ uses fetch() to make a request for https://example.org/api/data.json.

Fortunately, it's easy to bypass CORS restricton from Google Chrome. Just follow one of these guides based on the Operating System you're currently using.

How to Run Google Chrome without CORS on macOS

Open your Terminal and type the following command to start a new Google Chrome instance without CORS.

open -n "/Applications/Google Chrome.app" --args --user-data-dir="$HOME/chrome-dev-data" --disable-web-security
Enter fullscreen mode Exit fullscreen mode

How to Run Google Chrome without CORS on Windows 11

There are 2 kinds of command-line interpreters on Windows: PowerShell and Command Prompt (cmd.exe).
I personally prefer Windows Terminal on modern Windows and it's using PowerShell by default.

Here's how to start Google Chrome with CORS disabled with PowerShell.

. "C:\Program Files\Google\Chrome\Application\chrome.exe" --user-data-dir=C:\chrome-dev-data\ --disable-web-security
Enter fullscreen mode Exit fullscreen mode

If you're still using the Command Prompt / cmd.exe, you can start Google Chrome without CORS with the following command. Notice that I just simply removed the dot as the first character.

"C:\Program Files\Google\Chrome\Application\chrome.exe" --user-data-dir=C:\chrome-dev-data\ --disable-web-security
Enter fullscreen mode Exit fullscreen mode

How to Run Chromium / Google Chrome without CORS on Linux (Ubuntu, Debian, etc.)

On Linux, you can just open the Terminal and use the following command to open a Chrome window without CORS.

chromium --user-data-dir="$HOME/chrome-dev-data" --disable-web-security
Enter fullscreen mode Exit fullscreen mode

I personally use Chromium on a Linux system. If you're using Google Chrome, simply replace chromium with google-chrome.

Video

I also created a video to show you how to execute the command for each operating system.

Subscribe to Junian Dev YouTube channel

Conclusion

That's all I can show you.
You can start a Google Chrome window without CORS enabled and without polluting the main Google Chrome user data.

Thanks for reading and see you next time!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay