在 Safari 中禁用同源策略

发布于 2024-10-09 18:33:07 字数 145 浏览 9 评论 0原文

出于开发目的,我需要在我的计算机上的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

风轻花落早 2024-10-16 18:33:07

如果你想在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.

两人的回忆 2024-10-16 18:33:07

更高版本的 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.

ˇ宁静的妩媚 2024-10-16 18:33:07

转到,

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

宣告ˉ结束 2024-10-16 18:33:07

不幸的是,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.

我的影子我的梦 2024-10-16 18:33:07

对于那些将 iPhone 插入 Mac 并在 iOS Safari 中调试网站并使用 Mac 的开发菜单检查手机上的网站的用户,如果禁用跨源限制选项code> 呈灰色,请按照以下步骤操作。

  • 单击 Mac 上的 Safari 菜单
  • 单击首选项... 单击
  • 隐私选项卡
  • 删除防止交叉的复选标记- 站点跟踪
  • 刷新手机上的页面
  • 在计算机上贴一张便利贴,提醒您在完成工作后将复选标记放回去

(在 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.

  • 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)

凉城已无爱 2024-10-16 18:33:07

Safari 9 中有一个选项可以禁用跨域限制,这与上面提到的本地文件限制不同。

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

薆情海 2024-10-16 18:33:07

这些答案大多数都是旧的。最新的 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.

分分钟 2024-10-16 18:33:07

对于 Safari 17,菜单项移至“首选项”->“选项”中的复选框。开发商->禁用跨源限制。

For Safari 17, the menu item moved to a checkbox in Preferences -> Developer -> Disable cross-origin restrictions.

得不到的就毁灭 2024-10-16 18:33:07

根据上面的 soylent-graham 的评论,我花了有点找不到他所说的电话图标,但它位于开发人员面板的左上角。关闭在开发人员>中找到的设置开发者设置不适用于您连接的设备,仅适用于桌面 Safari。这是您想要在 iOS 或 iPadOS 设备上关闭 CORS 的设置。

关闭Safari 17.5 中的 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.

Turn off CORS in Safari 17.5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文