在 Safari 中禁用同源策略
出于开发目的,我需要在我的计算机上的 Safari(Windows 上)中禁用同源策略。
在 Chrome 中,这可以通过使用 --disable-web-security
标志启动来完成。 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果你想在Safari上禁用同源策略(我的是9.1.1),那么你只需要启用开发者菜单,并从开发者菜单中选择“禁用跨源限制”即可。
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.
更高版本的 Safari 允许您禁用跨源限制。只需从“首选项>>”启用开发人员菜单即可高级,然后从开发菜单中选择“禁用跨源限制”。
如果您只需要本地,则只需启用开发人员菜单,然后从开发菜单中选择“禁用本地文件限制”即可。
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.
转到,
Safari ->首选项->高级
,然后在底部勾选在菜单栏中显示开发菜单,
然后在开发菜单中勾选禁用跨源限制
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
不幸的是,Safari 没有对应的选项,并且参数
--disable-web-security
不适用于 Safari。如果您有权访问服务器端应用程序,则可以修改 https 响应标头以允许访问。主要是
Access-Control-Allow-Origin
标头。修改它将允许 Safari 访问该资源。请参阅 https://developer.mozilla。 org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Origin 了解有关响应标头的更多信息,这将有所帮助。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.对于那些将 iPhone 插入 Mac 并在 iOS Safari 中调试网站并使用 Mac 的开发菜单检查手机上的网站的用户,如果
禁用跨源限制选项code> 呈灰色,请按照以下步骤操作。
(在 iOS 15.3.1 和桌面 Safari 14.0.1 上测试)
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.(Tested on iOS 15.3.1 and Desktop Safari 14.0.1)
Safari 9 中有一个选项可以禁用跨域限制,这与上面提到的本地文件限制不同。
There is an option to disable cross-origin restrictions in Safari 9, different from local file restrictions as mentioned above.
这些答案大多数都是旧的。最新的 Safari 14.0.2(2021 年)可以选择
禁用跨源限制
,但是,如果路径具有 ../../ 类型的路径名,则该选项不起作用;即使 Safari 正确解析为本地文件路径,它仍然不允许加载该文件,即使该文件存在。这是 Safari 14 中最近出现的一个错误,在 13 中没有发生。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.对于 Safari 17,菜单项移至“首选项”->“选项”中的复选框。开发商->禁用跨源限制。
For Safari 17, the menu item moved to a checkbox in Preferences -> Developer -> Disable cross-origin restrictions.
根据上面的 soylent-graham 的评论,我花了有点找不到他所说的电话图标,但它位于开发人员面板的左上角。关闭在开发人员>中找到的设置开发者设置不适用于您连接的设备,仅适用于桌面 Safari。这是您想要在 iOS 或 iPadOS 设备上关闭 CORS 的设置。
Based on soylent-graham's comment above, it took me a bit to find the phone icon he was talking about, but it's in the top left of the developer panel. Turning off the setting found at Developer > Developer Settings doesn't apply to the device you're connected to, just to desktop Safari. This is the setting you want to turn off CORS on your iOS or iPadOS device.