有没有办法在谷歌的Chrome浏览器上禁用同源策略?
当前回答
在Ubuntu中使用以下命令启动chrome(禁用同源策略并在分离模式下打开chrome):
nohup google-chrome --disable-web-security --user-data-dir='/tmp' &
其他回答
关闭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
对于使用**Chrome版本60.0.3112.78(解决方案测试和工作的当天)的windows用户,至少到今天为止是2022年11月24日(版本106.05.249.119(官方版本)(64位))。您不需要关闭任何chrome实例。
在桌面上创建快捷方式右键单击快捷方式,然后单击“财产”编辑Target属性将其设置为“C:\Program Files(x86)\Google\Chrome\Application\Chrome.exe”--禁用web安全--用户数据dir=“C:\ChromeDevSession”启动chrome并忽略消息:禁用网络安全不受支持!
注意不要使用这个特定的浏览器实例进行浏览,因为你可能会被黑客入侵!
有一个名为CORS Toggle的Chrome扩展。
单击此处访问并将其添加到Chrome。
添加后,将其切换到打开位置以允许跨域请求。
禁用此标志为chrome-chrome://flags/#reduced-引用者粒度它应该起作用
是的。对于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。稳定和安全将受到影响。
然而,您可以在开发时忽略该信息。