【问题标题】:Trying to disable Chrome same origin policy尝试禁用 Chrome 同源策略
【发布时间】:2014-03-28 10:20:26
【问题描述】:

我正在尝试学习 melonJS 教程。它说我应该使用以下两种方法之一禁用跨域请求:

--disable-web-security

--allow-file-access-from-files**

我已经在我的命令提示符中尝试了这两种方法:

C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --allow-file-access-from-files

C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --disable-web-security

当我尝试在 Chrome 中运行游戏时,我仍然收到此错误:

XMLHttpRequest cannot load file:///C:/Users/danniu/Desktop/JavaScript/melonJS/data/map/area01.tmx. Cross origin requests are only supported for HTTP.

我做错了什么?

谢谢

【问题讨论】:

    标签: javascript security google-chrome same-origin-policy


    【解决方案1】:

    要在 Mac 上禁用 chrome 网络安全,请在终端上使用此命令

    $ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir="/tmp/chrome_dev_session" --disable-web-security

    如果 $ open -a Google\ Chrome --args --disable-web-security --allow-file-access-from-files 没有帮助

    【讨论】:

      【解决方案2】:

      反SOP参数: --disable-web-security -–allow-file-access-from-files

      为了使参数生效,不能有另一个chrome实例在运行。如果您chrome已经在运行并使用anti-SOP参数启动一个新实例,它将没有任何效果。

      当您关闭 chrome 时,请确保所有实例都已关闭。这也包括没有 GUI 的实例(任务管理器是你的朋友)!

      【讨论】:

        【解决方案3】:

        您应该通过 HTTP 协议请求

        这是一个非常简单的答案:https://stackoverflow.com/a/23118676/1585438

        【讨论】:

          【解决方案4】:

          您需要同时使用这两个参数。这就是我在我的 Mac 上运行它的方式。

          open -a Google\ Chrome --args --disable-web-security -–allow-file-access-from-files
          

          Windows 应该是这样的:

          "C:\PathTo\Chrome.exe" –allow-file-access-from-files -disable-web-security
          

          【讨论】:

          • 所以它看起来像这样? C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e xe --disable-web-security --allow-file-access-from-files ,那么我可以在那个新的浏览器窗口中打开我的游戏吗?
          • 您可能还需要添加 --args 参数
          • 查看编辑。对于 Windows,您实际上只需要使用一个破折号
          • 好的嗯。还是行不通。有什么方法可以在新的浏览器窗口中验证我是否禁用了这些功能?
          • 好吧,一种方法是您没有收到跨源错误。但是,一旦您打开浏览器,顶部就会出现一个黄色条,表示您处于不安全模式。此外,请确保在运行该标志之前终止所有 chrome 任务。否则就不行了
          猜你喜欢
          • 2015-12-27
          • 2012-08-29
          • 2014-02-05
          • 2015-12-08
          • 1970-01-01
          • 2013-06-09
          相关资源
          最近更新 更多