有没有办法在谷歌的Chrome浏览器上禁用同源策略?
当前回答
对于Windows。。。在桌面上创建Chrome快捷方式。右键单击>财产>快捷方式编辑“目标”路径:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --args --disable-web-security
(将“C:….\chrome.exe”更改为chrome所在的位置)。
等等:)
其他回答
使用当前最新的chrome版本103.0.5060.134(官方版本)(64位)
windows:单击开始按钮,然后复制粘贴以下内容(根据您的喜好更改D:\temp)。:
chrome.exe --disable-site-isolation-trials --disable-web-security --user-data-dir="D:\temp"
Linux:启动终端,然后运行以下命令(根据需要更改~/tmp目录)
google-chrome --disable-site-isolation-trials --disable-web-security --user-data-dir="~/tmp"
注意:此解决方案将在独立的沙盒中启动chrome,并且不会影响主chrome配置文件。
关闭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
创建快捷方式:
粘贴命令:
cmd/c start chrome--禁用web安全--用户数据dir=“c:\temp\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。稳定和安全将受到影响。
然而,您可以在开发时忽略该信息。
对于Selenium Webdriver,在这种情况下,您可以使用适当的参数(或“开关”)让Selenium启动Chrome。
@driver = Selenium::WebDriver.for(:Chrome, {
:detach => false,
:switches => ["--disable-web-security"]
})
推荐文章
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?
- 如何使用jQuery检测页面的滚动位置
- if(key in object)或者if(object. hasownproperty (key)
- 一元加/数字(x)和parseFloat(x)之间的区别是什么?
- angularjs中的compile函数和link函数有什么区别
- 删除绑定中添加的事件监听器
- 很好的初学者教程socket.io?
- HtmlSpecialChars在JavaScript中等价于什么?
- HttpOnly cookie如何与AJAX请求一起工作?
- React: 'Redirect'没有从' React -router-dom'中导出
- 如何在React中使用钩子强制组件重新渲染?
- 我如何使用Jest模拟JavaScript的“窗口”对象?
- 我如何等待一个承诺完成之前返回一个函数的变量?
- 在JavaScript中根据键值查找和删除数组中的对象