ChatGPT解决这个技术问题 Extra ChatGPT

Disabling same-origin policy in Safari

For development purposes, I need to disable the same-origin policy in Safari (on Windows) on my machine.

In Chrome, this can be done by launching with the flag --disable-web-security. Is there an equivalent flag or hidden setting in Safari?


t
ttemple

If you want to disable the same-origin policy on Safari (I have 9.1.1), then you only need to enable the developer menu, and select "Disable Cross-Origin Restrictions" from the develop menu.


This is the correct answer. You must to reload the webpage.
For Germans: "Ursprungsübergreifende Beschränkungen deaktivieren"
Does not work. In Safari 11.0.3 i Disable Cross-origin restrictions and still same.
Works like a charm!
This works for me with Safari 12.0.3. I also had to clear the cache (with Shortcut or in developer menu --> Empty Caches) + reload the webpage as from @TlmaK0 suggested.
s
skymook

Later versions of Safari allow you to Disable Cross-Origin Restrictions. Just enable the developer menu from Preferences >> Advanced, and select "Disable Cross-Origin Restrictions" from the develop menu.

If you want local only, then you only need to enable the developer menu, and select "Disable local file restrictions" from the develop menu.


This menu item is in the Develop menu which needs to be enabled in preferences under Advanced "Show Develop menu in menu bar". But it doesn't seem to avoid the the cors issue.
I'm running Safari 7 on Mavericks. Happy to say this still works.
The same origin policy and local file restrictions are not the same thing, this answer does not answer the question correctly.
you can turn off local file restrictions, but for testing cross-browser stuff with same-origin policy problems use firefox or chrome. For chrome and OS X see here: stackoverflow.com/a/6083677/2526914
This answer seems to be helping some people with running local files. It won't help with CORS however. Rather than down voting, may I suggest you provide a solution that people can upvote?
P
Pramodya Abeysinghe

goto,

Safari -> Preferences -> Advanced

then at the bottom tick Show Develop Menu in menu bar

then in the Develop Menu tick Disable Cross-Origin Restrictions


It works with desktop safari but how to switch this option on mobile device?
not sure whether we have same option on mobile Safari. But Settings -> Safari -> Advanced you may find something
For mobile's iOS Safari, see this answer.
B
Brad Rippe

Unfortunately, there is no equivalent for Safari and the argument --disable-web-security doesn't work with Safari.

If you have access to the server side application, you can modify the https response headers to allow access. Mainly the Access-Control-Allow-Origin header. Modifying it will allow Safari to access the resource. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Origin for more information on the response headers that will help.


Can confirm that sadly Safari has no command line arguments. discussions.apple.com/thread/8044532
G
Gofake1

There is an option to disable cross-origin restrictions in Safari 9, different from local file restrictions as mentioned above.


E
Edward De Jong

Most of these answers are old. The latest Safari 14.0.2 (in 2021), has the option to Disable Cross-Origin Restrictions, however, it doesn't work if the paths have ../../ kind of path names; even though Safari correctly resolves to a local file path, it still doesn't permit loading the file, even though it exists. This is a recent bug in Safari 14 that didn't happen in 13.


s
samurai_jane

For those debugging a site in iOS Safari with an iPhone plugged into a Mac and using the Mac's Develop menu to inspect the site on the phone, if the option for Disable Cross-Origin Restrictions is greyed out, follow these steps.

Click on the Safari menu on your Mac

Click on Preferences...

Click on the tab for Privacy

Remove the checkmark for Prevent cross-site tracking

Refresh the page on your phone

Put a sticky note on your computer with a reminder to put the checkmark back when you are done working

(Tested on iOS 15.3.1 and Desktop Safari 14.0.1)