新版ChromeDriver为何自动导出浏览器Cookie至文件?
问题描述
- 将NuGet包
Selenium.WebDriver.ChromeDriver by jsakamoto更新至117.0.5938.9200版本后,创建Chrome驱动程序时,浏览器的Cookie会被导出到名为C和C-journal的sqlite文件中。 - 生成文件路径:
D:\my-programs\CD:\my-programs\C-journal
- 程序路径:
D:\my-programs\C#\my-thing\my-thing\bin\Debug\my-thing.exe - Chrome配置文件路径:
D:\my-programs\C#\my-thing\my-thing\bin\Debug\my-chrome-profile - 通过断点确认,执行代码
tempDriver = new ChromeDriver(service, chromeOptions);时会创建这些文件。 - 将
C#文件夹重命名为Cz#后,生成的文件变为Cz和Cz-journal,推测文件名由路径片段生成。 - 此前版本的
Selenium.WebDriver.ChromeDriver从未出现自动导出Cookie至文件的情况,怀疑是否存在恶意行为,也不确定这是否与ChromeDriver更新端点变更有关。
创建驱动的代码
private IWebDriver CreateDriver() { ChromeOptions chromeOptions; IWebDriver tempDriver = null; string uniqueId = "my-program-" + Environment.TickCount; string myExtensionPath = Environment.CurrentDirectory + "\\my-stuff\\my-extension"; string extensionId = settings.GetValue("extension id"); try { chromeOptions = new ChromeOptions(); if (cbHideBrowser.Checked == true) { chromeOptions.AddArgument("--window-position=-10000,0"); chromeOptions.AddArgument("--window-size=1920,1080"); } else { chromeOptions.AddArgument("--window-position=-1920,0"); chromeOptions.AddArgument("--window-size=1920,1080"); } chromeOptions.AddArgument(uniqueId); chromeOptions.AddArgument("--disable-infobars"); chromeOptions.AddArgument("--user-data-dir=" + Path.GetFullPath("my-chrome-profile")); chromeOptions.AddArgument("--my-program"); chromeOptions.AddArgument("--process-per-site"); chromeOptions.AddArgument(@"--load-extension=" + myExtensionPath + "," + Environment.CurrentDirectory + "\\uBlock-Origin-development-build_v1.24.5.4"); chromeOptions.AddArgument(@"--allowlisted-extension-id=" + extensionId); chromeOptions.AddUserProfilePreference("download.prompt_for_download", false); chromeOptions.AddUserProfilePreference("download.directory_upgrade", true); chromeOptions.AddUserProfilePreference("download.default_directory", Environment.CurrentDirectory + "\\myfiles"); chromeOptions.BinaryLocation = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"; ChromeDriverService service = ChromeDriverService.CreateDefaultService(); service.HideCommandPromptWindow = cbHideBrowser.Checked; tempDriver = new ChromeDriver(service, chromeOptions); if (cbHideBrowser.Checked == true) { processId = GetProcessIdByCommandLineArg(uniqueId); Process p = Process.GetProcessById(processId); ShowWindow(p.MainWindowHandle, 0); } } catch (Exception x) { } return tempDriver; }
内容的提问来源于stack exchange,提问作者John
相关产品推荐
相关产品推荐

