0

在 Chrome 中有一个严格的站点隔离设置,可以在 chrome://flags/#enable-site-per-process 页面中手动启用。我在使用 WebDriver C# 绑定测试 Chrome 时尝试启用此标志,但未启用。

该开关列在https://peter.sh/experiments/chromium-command-line-switches/中,因此我尝试将其作为参数添加到 ChromeOptions 中,但这没有任何效果。

ChromeOptions options = new ChromeOptions();
options.AddArgument("--site-per-process");
IWebDriver driver = new ChromeDriver(@"c:\browserdrivers",options);
driver.Navigate().GoToUrl("www.google.com");
driver.Quit();

我还尝试根据https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc中列出的设置将其设置为首选项

options.AddUserProfilePreference("site_isolation.site_per_processs", true);

但这也不起作用。

有谁知道如何打开这个?

4

2 回答 2

0

我们正在使用 PS 脚本部署此更改,以在 Windows 上的 %AppDataLocal%\Google\Chrome\User Data 编辑本地状态文件

该脚本有点基本,但可以为我们完成工作。最好使用 GPO 选项,但不幸的是,这只适用于 Chrome 63 和更新版本。


$USRPROF = Get-Childitem env:APPDATA | %{ $_.Value }
$ChromeLocalState = (Get-item $USRPROF).parent.FullName + "\Local\Google\Chrome\User Data\Local State"

#original (Get-Content $ChromeLocalState) | Foreach-Object {$_ -replace '{"browser":{"last_redirect_origin"', '{"browser":{"enabled_labs_experiments":["enable-site-per-process"],"last_redirect_origin"'} | Set-Content $ChromeLocalState

#add site-per-process setting. Ok if it doubles the same nested statement. Chrome will parse it out.
(Get-Content $ChromeLocalState) | Foreach-Object {$_ -replace 'last_redirect_origin', 'enabled_labs_experiments":["enable-site-per-process"],"last_redirect_origin'} | Set-Content $ChromeLocalState
于 2018-01-05T19:41:58.860 回答
-1

基于 Fiddles 代码,这个版本解决了我在测试中发现的几个问题。必须以登录用户身份运行。见最后的注释。

“本地状态”json 文件包含启用此实验设置的“启用站点每进程”配置项的每个用户设置

使用本地系统环境变量获取用户 C:\Users\UserID\Appdata\Local 文件夹

$USRPROF = Get-Childitem env:LOCALAPPDATA 

在该文件夹下是'\Google\Chrome\User Data'包含'Local State'我们需要修改的文件的文件夹

$ChromeLocalState =  -Join($USRPROF.Value.ToString(),'\','Google\Chrome\User Data\Local State')

停止 Chrome

Stop-Process -Name chrome -Force -ErrorAction SilentlyContinue

添加每个进程的站点设置。好的,如果它将相同的嵌套语句加倍。Chrome 会解析出来。

(Get-Content $ChromeLocalState) | Foreach-Object {$_ -replace 'last_redirect_origin', 'enabled_labs_experiments":["enable-site-per-process"],"last_redirect_origin'} | Set-Content $ChromeLocalState

查找安装了哪个版本的 Chrome 并启动它

Switch($TRUE) {

{Test-Path 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'} {Start-Processs -FilePath 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' }

{Test-Path 'C:\Program Files\Google\Chrome\Application\chrome.exe'}       {Start-Processs -FilePath 'C:\Program Files\Google\Chrome\Application\chrome.exe' }

}

测试期间的观察

如果此脚本启动时 chrome 正在运行,则“本地状态”文件中的值已生成但不生效。如果 Chrome 然后关闭,“本地状态”文件将被内存中的信息覆盖,并且设置被删除!!

因此,为了获得最大的工作机会,脚本已修改为 1. 停止 Chrome 2. 更改设置 3. 重新启动 Chrome

重新启动 chrome 是可选的,由于 Chrome 的非标准终止,用户将被要求恢复打开的选项卡。

进一步的观察是,即使 chrome 在后台,本地状态文件也会不断被修改。这是首先停止 chrome 的另一个原因。

于 2018-01-07T19:36:06.400 回答