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!

Top comments (0)

Hot sauce if you're wrong - web dev trivia for staff engineers

Hot sauce if you're wrong · web dev trivia for staff engineers (Chris vs Jeremy, Leet Heat S1.E4)

  • Shipping Fast: Test your knowledge of deployment strategies and techniques
  • Authentication: Prove you know your OAuth from your JWT
  • CSS: Demonstrate your styling expertise under pressure
  • Acronyms: Decode the alphabet soup of web development
  • Accessibility: Show your commitment to building for everyone

Contestants must answer rapid-fire questions across the full stack of modern web development. Get it right, earn points. Get it wrong? The spice level goes up!

Watch Video 🌶️🔥