How To Bypass CORS Errors On Chrome And Firefox For Testing

Whenever you work with any kind of a REST API the CORS issue comes and haunts you. You don’t know if your code isn’t working or if your browser is having some problems but when you debug using the web inspector tools you see an error like this:

For Firefox:

CORS error firefox

For Chrome:

CORS error chrome

So how do you get around it, well thankfully there are plugins for that but sometimes the plugins don’t work so I will show you both how to disable it manually.

But before we disable it lets take a moment to know what CORS is.

A webpage may contain embedded items such as a style sheet, images, JavaScript, etc and traditionally accessing of these items have been limited to the same domain as the page. So if the page was at somedomain.com the resources allowed for that page were only from somedomain.com this is called Same-origin policy.

But for an API that doesn’t make any sense as APIs by nature have to provide data across various domains. Enter Cross-origin resource sharing (CORS), CORS allows the server to do just that, but it has to be enabled on the server. But may APIs don’t have it enabled.

But this post is not about to teach you CORS but to bypass it.

Plugins:

Let’s see how you can do that using plugins

For Chrome:

Plugin Name: Allow-Control-Allow-Origin: *

Link: Download here

For Firefox:

Plugin Name: cors everywhere

You need to search firefox add-on section to get this plugin.

Manually:

This plugins are great and they get the job done and i love using them but at times you might to do things manually so the following are some ways you can do it manually

For Chrome:

Using the command prompt first navigate to the directory where chrome is installed and issue the following command:

For Firefox

Open your Firefox and type about:config into the URL bar.  Agree to the statement about risk and do a search for:

And change it to false.

 

Leave Me Your Questions And Feedback

Getting your feedback inspires me the most so hit me up in the comments here or on the comments section on my YouTube Channel or on twitter @uncutAcademy
Consider Subscribing / Donating
Subscribe To Mailing List
Donate
If my site was helpful to you, then please consider donating via paypal:
Prantik Vaghela

Prantik Vaghela (uncutAcademy)

Hi my name is Prantik Vaghela. I have done my Bachelors and Masters in Computer Science and am a web developer and now a Tutor through my blog. :-)