DEV Community

Cover image for How to Run Safari Browser without CORS Restriction
junian
junian

Posted on • Originally published at junian.net on

How to Run Safari Browser without CORS Restriction

As a web developer, you likely need to test your REST API locally. When using a browser like Safari, you might encounter issues such as the following messages.

Origin http://localhost:8081 is not allowed by Access-Control-Allow-Origin. Status code: 200

Fetch API cannot load http://localhost:8080/api/ due to access control checks.

Failed to load resource: Origin http://localhost:8081 is not allowed by Access-Control-Allow-Origin. Status code: 200

Don't worry, this is actually a strong security feature implemented by modern web browsers.

I won't overwhelm you with details about CORS—you can read more in the official documentation. However, if you're interested, here's a 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.

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

Luckily, bypassing CORS restrictions in Safari is straightforward.

Solution to Disable CORS in Safari

  1. Click on Safari in the top menu bar and select Settings....
  2. Go to the Advanced tab and check the Show features for web developers option.
  3. A new Developer tab will appear.
  4. Select Developer tab and enable the Disable cross-origin restrictions option.
  5. Return to Safari and refresh the page. It should work now!

Video

Here is the video to visualize the steps above.

Conclusion

Disabling CORS on Safari through the settings is quite simple.
I do wish there were a command-line solution, but let's be grateful for any method available.

Thanks for reading, and see you around!

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

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay