有没有办法在谷歌的Chrome浏览器上禁用同源策略?
当前回答
编辑3:扩展似乎不再存在。。。这些天来,为了避开CORS,我通常会在单独的目录中设置另一个版本的Chrome,或者使用Firefoxhttps://addons.mozilla.org/en-US/firefox/addon/cors-everywhere/相反
编辑2:我再也无法让这项工作持续下去了。
编辑:前几天我试着用另一个项目,但它停止了工作。卸载并重新安装扩展修复了它(以重置默认值)。
原始答案:
我不想重启Chrome并禁用我的网络安全(因为我在开发时正在浏览),无意中发现了这个Chrome扩展。
Chrome Web Store允许控件允许来源:*(https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en)
基本上,它是一个小切换开关,用于打开和关闭“允许访问源代码控制”检查。对于我所做的一切来说,这是完美的。
其他回答
创建快捷方式:
粘贴命令:
cmd/c start chrome--禁用web安全--用户数据dir=“c:\temp\chrome”
以管理员身份运行
Chrome的Allow Control Allow Origin插件不起作用。这是针对MacOS的
我将别名chrome='open-n-a/Applications/Google\chrome.app/Contents/MacOS/Google\Chrme--args-user data dir--disable web security'作为别名添加到我的.profile中。
其他命令将禁用我的其他扩展,这将在禁用cors的情况下启动正常的chrome
你可以使用这个名为“允许控制允许来源:*”的chrome插件。。。这使它变得非常简单,而且工作得非常好。在此处检查:*
是的。对于OSX,打开终端并运行:
$ open -a Google\ Chrome --args --disable-web-security --user-data-dir
--OSX上的Chrome 49+需要用户数据目录
对于Linux运行:
$ google-chrome --disable-web-security
此外,如果您试图访问本地文件以用于开发目的,如AJAX或JSON,也可以使用此标志。
--allow-file-access-from-files
对于Windows,进入命令提示符并进入Chrome.exe所在的文件夹,然后键入
chrome.exe --disable-web-security
这将禁用同源策略并允许您访问本地文件。
更新:对于Chrome 22+,您将看到一条错误消息,上面写着:
您正在使用不受支持的命令行标志:--disable web security。稳定和安全将受到影响。
然而,您可以在开发时忽略该信息。
关闭chrome(或chrome)并使用--disable web安全参数重新启动。我刚刚测试了这个,并验证了我可以使用src=“”访问iframe的内容http://google.com嵌入在“localhost”(在chromium 5/ubuntu下测试)提供的页面中
注意:在运行命令之前杀死所有chrome实例
chromium-browser --disable-web-security --user-data-dir="[some directory here]"
浏览器首次打开时会警告您“您正在使用不受支持的命令行”,您可以忽略这一点。
铬源:
// Don't enforce the same-origin policy. (Used by people testing their sites.)
const wchar_t kDisableWebSecurity[] = L"disable-web-security";
在Chrome 48之前,您可以使用:
chromium-browser --disable-web-security