Chrome 48+ 禁用网络安全
Disable-web-security in Chrome 48+
我对 --disable-web-security
标志有疑问。它在 Chrome 48 和 Chrome 49 测试版 Windows 上不起作用。
我试过杀死所有实例,重新启动并首先使用标志运行 Chrome,还尝试了不同的机器。在测试版中,我可以看到警告弹出窗口 ("You are using unsupported flag.."),但 CORS 仍在执行中。 Public 版本似乎完全忽略了该标志。
似乎没有关于这方面的新闻或报道,所以这可能是当地的问题。
将不胜感激帮助或任何相关信息。
我也看到了同样的事情。快速 google 找到了这个问题,然后 bug on the chromium forums。现在似乎需要 --user-data-dir
标志。
编辑以添加 user-data-dir guide
版本 49.0.2623.75(64 位)不再处于测试阶段。
修复 CORS 问题的命令是
google-chrome-stable --disable-web-security --user-data-dir
Mac OS:
open -a Google\ Chrome --args --disable-web-security --user-data-dir=
UPD:将 =
添加到 --user-data-dir
因为较新的 chrome 版本需要它才能工作
它对我有用。
试试这个..它会帮助你..
c:\Program Files\Google\Chrome\Application>chrome.exe --disable-web-security --user-data-dir="D:\chrome"
在 Chrome::
中安装此 Chrome 禁用网络安全插件
" Allow-Control-Allow-Origin: * "
link Here 或者你可以 google 以上插件,如果你愿意的话。
使用此插件启用和禁用安全性非常容易。
选择的答案很好,但对于那些仍在为他们正在谈论的内容而苦苦挣扎的人(你第一次处理这个问题),以下对我有用。
我在桌面上创建了一个新的 Chrome 快捷方式,右键单击它,然后将 "Target" 字段设置为以下内容,
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="c:/chromedev"
目录可以是任何你想要的,我决定在我的 C: 目录中创建一个名为 chrome dev 的空文件夹。它与计算机上安装 chrome 的位置无关。这只是一种绒毛类型的东西。
这个 link 也有针对其他操作系统的明确指示。 How to disable web securityin Chrome
对于 Chrome 版本 50+ 对于 Mac 用户。首先关闭所有打开的 chrome 和 运行 下面的命令
open -a Google\ Chrome --args --disable-web-security --user-data-dir=""
以上方法可行。谢谢
在 OS X 上,打开一个新的 Chrome window - 无需先关闭已经打开的 windows - 传入额外的 -n 标志。确保为 data-dir 指定空字符串(Chrome 的较新版本所必需的,例如 v50 something+)。
open -na /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=""
我发现在 Mac OS X Sierra 上使用 Chrome 60+,上面的命令不再有效,但稍微修改一下:
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_sess_1" --disable-web-security
数据目录路径很重要。即使您在发出命令时站在您的主目录中,您也不能简单地引用本地目录。必须是绝对路径。
对于 Mac,使用 Safari 是用于本地开发目的的一个很好的替代选项,并且该功能内置于浏览器中(因此无需添加浏览器扩展程序或启动 Chrome 使用 bash 命令如 [open -a Google\ Chrome --args --disable-web-security --user-data-dir=""].
要使用 Safari (v11+) 禁用跨源限制:从菜单中单击“开发 > 禁用跨源限制”。
这不需要重新启动浏览器,因为它是一个开关,您可以轻松切换到安全模式。
在终端中输入这些:
cd C:\Program Files (x86)\Google\Chrome\Application
chrome.exe --disable-web-security --user-data-dir="c:/chromedev"
2021-10-18更新
从 Chrome 95 开始,在 MacOS 和 Windows 上,--disable-site-isolation-trials
仍然是禁用网络安全所需的标志,因此 [=103= 的命令行参数] 下面看到的仍然有效。 (Chrome 并未正式支持某些论点,因为它会警告您。)
要测试您是否已在禁用网络安全的情况下成功启动 Chrome,运行 此 网络安全测试 底部的片段 post.
2020-04-30更新
从 Chrome 81 开始,必须按顺序通过 --disable-site-isolation-trials
和非空配置文件路径 --user-data-dir
--disable-web-security
生效:
# MacOS (in Terminal)
open -na Google\ Chrome --args --user-data-dir=/tmp/temporary-chrome-profile-dir --disable-web-security --disable-site-isolation-trials
# Windows (from "Run" dialog [Windows+R] or start menu in Windows 8+)
chrome.exe --user-data-dir=%TMP%\temporary-chrome-profile-dir --disable-web-security --disable-site-isolation-trials
(推测)Chrome 可能需要一个非空的配置文件路径,以减轻在默认配置文件上禁用网络安全的情况下启动浏览器的高安全风险。有关详细信息,请参阅 --user-data-dir=
与 --user-data-dir=/some/path
。
感谢 @Snæbjørn 在评论中提供 Chrome 81 条提示。
更新 2020-03-06
从 Chrome 80(可能更早)开始,标志组合 --user-data-dir=/tmp/some-path --disable-web-security --disable-site-isolation-trials
不再禁用网络安全性 .
尚不清楚 Chromium 代码库何时退化,但下载旧版本的 Chromium(在 "Not-so-easy steps" on the Chromium download page 之后)是我找到的唯一解决方法。我最终使用了版本 77.0.3865.0,它使用这些标志正确禁用了网络安全。
原创 Post 2019-11-01
在 Chrome 67+ 中,必须将 --disable-site-isolation-trials
标志与参数 --user-data-dir=
和 --disable-web-security
一起传递才能真正禁用网络安全。
在 MacOS 上,完整命令变为:
open -na Google\ Chrome --args --user-data-dir= --disable-web-security --disable-site-isolation-trials
关于--user-data-dir
根据 ,仍然需要为 Chrome 指定 --user-data-dir=
以遵守 --disable-web-security
选项。
--user-data-dir=
对比 --user-data-dir=/some/path
虽然通过 --user-data-dir=
传递一个空路径可以与 --disable-web-security
一起使用,但出于安全目的不建议这样做,因为它使用默认的 Chrome 配置文件,该配置文件具有活动登录会话电子邮件等。禁用 Chrome 安全性后,您的活动会话因此容易受到浏览器内其他攻击的攻击。
因此,建议为您的 Chrome 配置文件使用 --user-data-dir=/tmp/chrome-sesh
或同等目录的替代目录。感谢 @James B 在评论中指出这一点。
来源
此修复是在浏览器测试框架 Cypress 中发现的:https://github.com/cypress-io/cypress/issues/1951
网络安全测试
运行 此代码段用于确认此解决方案实际上在 Google Chrome:
中禁用了网络安全
window.addEventListener("DOMContentLoaded", () => {
const iframe = document.querySelector("iframe");
iframe.addEventListener("load", () => {
const canAccessIframeDocument = !!iframe.contentDocument;
document
.querySelector(
canAccessIframeDocument ? ".security-disabled" : ".security-enabled"
)
.classList.remove("hidden");
});
// To ensure the `load` event always fires, only set iframe src after the
// event listener is attached.
iframe.src = "https://google.com";
});
body {
font-family: sans-serif;
}
.hidden {
display: none;
}
/* Web security should normally be enabled, so this is colored green, despite
the objective of this solution to disable it. */
.security-enabled {
font-weight: bold;
color: darkgreen;
}
.security-disabled {
font-weight: bold;
color: darkred;
}
<h1>Web Security Test</h1>
<p>
This test attempts to access the inner contents of a cross-origin iframe,
which is normally disallowed.
</p>
<p class="security-enabled hidden">
Web security is enabled. The cross-origin iframe document could not be
accessed.
</p>
<p class="security-disabled hidden">
Web security is disabled. The cross-origin iframe document was
successfully accessed.
</p>
<iframe class="hidden">
Iframes are not supported.
</iframe>
截至本回答之日(2020 年 3 月),chrome 有一个名为 CORS unblock 的插件,可让您跳过该浏览器政策。 'same origin policy' 是浏览器的一项重要安全功能。请仅出于开发或测试目的安装此插件。不要在终端客户端浏览器中推广它的安装,因为你会危及用户的安全,chrome 社区将被迫从商店中删除这个插件。
来自 Chorme v81 的参数 --user-data-dir=
需要一个实际参数,而在过去则不需要。
像这样的东西对我来说很好
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="\tmp\chrome_test"
我对 --disable-web-security
标志有疑问。它在 Chrome 48 和 Chrome 49 测试版 Windows 上不起作用。
我试过杀死所有实例,重新启动并首先使用标志运行 Chrome,还尝试了不同的机器。在测试版中,我可以看到警告弹出窗口 ("You are using unsupported flag.."),但 CORS 仍在执行中。 Public 版本似乎完全忽略了该标志。
似乎没有关于这方面的新闻或报道,所以这可能是当地的问题。 将不胜感激帮助或任何相关信息。
我也看到了同样的事情。快速 google 找到了这个问题,然后 bug on the chromium forums。现在似乎需要 --user-data-dir
标志。
编辑以添加 user-data-dir guide
版本 49.0.2623.75(64 位)不再处于测试阶段。
修复 CORS 问题的命令是
google-chrome-stable --disable-web-security --user-data-dir
Mac OS:
open -a Google\ Chrome --args --disable-web-security --user-data-dir=
UPD:将 =
添加到 --user-data-dir
因为较新的 chrome 版本需要它才能工作
它对我有用。 试试这个..它会帮助你..
c:\Program Files\Google\Chrome\Application>chrome.exe --disable-web-security --user-data-dir="D:\chrome"
在 Chrome::
中安装此 Chrome 禁用网络安全插件" Allow-Control-Allow-Origin: * " link Here 或者你可以 google 以上插件,如果你愿意的话。
使用此插件启用和禁用安全性非常容易。
选择的答案很好,但对于那些仍在为他们正在谈论的内容而苦苦挣扎的人(你第一次处理这个问题),以下对我有用。
我在桌面上创建了一个新的 Chrome 快捷方式,右键单击它,然后将 "Target" 字段设置为以下内容,
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="c:/chromedev"
目录可以是任何你想要的,我决定在我的 C: 目录中创建一个名为 chrome dev 的空文件夹。它与计算机上安装 chrome 的位置无关。这只是一种绒毛类型的东西。
这个 link 也有针对其他操作系统的明确指示。 How to disable web securityin Chrome
对于 Chrome 版本 50+ 对于 Mac 用户。首先关闭所有打开的 chrome 和 运行 下面的命令
open -a Google\ Chrome --args --disable-web-security --user-data-dir=""
以上方法可行。谢谢
在 OS X 上,打开一个新的 Chrome window - 无需先关闭已经打开的 windows - 传入额外的 -n 标志。确保为 data-dir 指定空字符串(Chrome 的较新版本所必需的,例如 v50 something+)。
open -na /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=""
我发现在 Mac OS X Sierra 上使用 Chrome 60+,上面的命令不再有效,但稍微修改一下:
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_sess_1" --disable-web-security
数据目录路径很重要。即使您在发出命令时站在您的主目录中,您也不能简单地引用本地目录。必须是绝对路径。
对于 Mac,使用 Safari 是用于本地开发目的的一个很好的替代选项,并且该功能内置于浏览器中(因此无需添加浏览器扩展程序或启动 Chrome 使用 bash 命令如 [open -a Google\ Chrome --args --disable-web-security --user-data-dir=""].
要使用 Safari (v11+) 禁用跨源限制:从菜单中单击“开发 > 禁用跨源限制”。
这不需要重新启动浏览器,因为它是一个开关,您可以轻松切换到安全模式。
在终端中输入这些:
cd C:\Program Files (x86)\Google\Chrome\Application
chrome.exe --disable-web-security --user-data-dir="c:/chromedev"
2021-10-18更新
从 Chrome 95 开始,在 MacOS 和 Windows 上,--disable-site-isolation-trials
仍然是禁用网络安全所需的标志,因此 [=103= 的命令行参数] 下面看到的仍然有效。 (Chrome 并未正式支持某些论点,因为它会警告您。)
要测试您是否已在禁用网络安全的情况下成功启动 Chrome,运行 此 网络安全测试 底部的片段 post.
2020-04-30更新
从 Chrome 81 开始,必须按顺序通过 --disable-site-isolation-trials
和非空配置文件路径 --user-data-dir
--disable-web-security
生效:
# MacOS (in Terminal)
open -na Google\ Chrome --args --user-data-dir=/tmp/temporary-chrome-profile-dir --disable-web-security --disable-site-isolation-trials
# Windows (from "Run" dialog [Windows+R] or start menu in Windows 8+)
chrome.exe --user-data-dir=%TMP%\temporary-chrome-profile-dir --disable-web-security --disable-site-isolation-trials
(推测)Chrome 可能需要一个非空的配置文件路径,以减轻在默认配置文件上禁用网络安全的情况下启动浏览器的高安全风险。有关详细信息,请参阅 --user-data-dir=
与 --user-data-dir=/some/path
。
感谢 @Snæbjørn 在评论中提供 Chrome 81 条提示。
更新 2020-03-06
从 Chrome 80(可能更早)开始,标志组合 --user-data-dir=/tmp/some-path --disable-web-security --disable-site-isolation-trials
不再禁用网络安全性 .
尚不清楚 Chromium 代码库何时退化,但下载旧版本的 Chromium(在 "Not-so-easy steps" on the Chromium download page 之后)是我找到的唯一解决方法。我最终使用了版本 77.0.3865.0,它使用这些标志正确禁用了网络安全。
原创 Post 2019-11-01
在 Chrome 67+ 中,必须将 --disable-site-isolation-trials
标志与参数 --user-data-dir=
和 --disable-web-security
一起传递才能真正禁用网络安全。
在 MacOS 上,完整命令变为:
open -na Google\ Chrome --args --user-data-dir= --disable-web-security --disable-site-isolation-trials
关于--user-data-dir
根据 --user-data-dir=
以遵守 --disable-web-security
选项。
--user-data-dir=
对比 --user-data-dir=/some/path
虽然通过 --user-data-dir=
传递一个空路径可以与 --disable-web-security
一起使用,但出于安全目的不建议这样做,因为它使用默认的 Chrome 配置文件,该配置文件具有活动登录会话电子邮件等。禁用 Chrome 安全性后,您的活动会话因此容易受到浏览器内其他攻击的攻击。
因此,建议为您的 Chrome 配置文件使用 --user-data-dir=/tmp/chrome-sesh
或同等目录的替代目录。感谢 @James B 在评论中指出这一点。
来源
此修复是在浏览器测试框架 Cypress 中发现的:https://github.com/cypress-io/cypress/issues/1951
网络安全测试
运行 此代码段用于确认此解决方案实际上在 Google Chrome:
中禁用了网络安全window.addEventListener("DOMContentLoaded", () => {
const iframe = document.querySelector("iframe");
iframe.addEventListener("load", () => {
const canAccessIframeDocument = !!iframe.contentDocument;
document
.querySelector(
canAccessIframeDocument ? ".security-disabled" : ".security-enabled"
)
.classList.remove("hidden");
});
// To ensure the `load` event always fires, only set iframe src after the
// event listener is attached.
iframe.src = "https://google.com";
});
body {
font-family: sans-serif;
}
.hidden {
display: none;
}
/* Web security should normally be enabled, so this is colored green, despite
the objective of this solution to disable it. */
.security-enabled {
font-weight: bold;
color: darkgreen;
}
.security-disabled {
font-weight: bold;
color: darkred;
}
<h1>Web Security Test</h1>
<p>
This test attempts to access the inner contents of a cross-origin iframe,
which is normally disallowed.
</p>
<p class="security-enabled hidden">
Web security is enabled. The cross-origin iframe document could not be
accessed.
</p>
<p class="security-disabled hidden">
Web security is disabled. The cross-origin iframe document was
successfully accessed.
</p>
<iframe class="hidden">
Iframes are not supported.
</iframe>
截至本回答之日(2020 年 3 月),chrome 有一个名为 CORS unblock 的插件,可让您跳过该浏览器政策。 'same origin policy' 是浏览器的一项重要安全功能。请仅出于开发或测试目的安装此插件。不要在终端客户端浏览器中推广它的安装,因为你会危及用户的安全,chrome 社区将被迫从商店中删除这个插件。
来自 Chorme v81 的参数 --user-data-dir=
需要一个实际参数,而在过去则不需要。
像这样的东西对我来说很好
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="\tmp\chrome_test"