gpt4 book ai didi

google-chrome - WebDriver异常: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

转载 作者:太空宇宙 更新时间:2023-11-04 09:49:20 24 4
gpt4 key购买 nike

我尝试使用 URL 启动 Chrome,浏览器启动后什么也不做。

1 分钟后我看到以下错误:

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

我的配置:

  • Chrome :66
  • Chrome浏览器:2.39.56

P.S 在 Firefox 中一切正常

最佳答案

经验法则

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.

<小时/>

此错误消息...

org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist 

...意味着 ChromeDriver 无法启动/生成新的 WebBrowser,即 Chrome 浏览器 session 。

您的代码试验和所有二进制文件的版本控制信息会给我们一些关于问题所在的提示。

但是根据 Add --disable-dev-shm-usage to default launch flags似乎添加参数 --disable-dev-shm-usage 将暂时解决该问题。

如果您希望启动/跨越新的 Chrome 浏览器 session ,可以使用以下解决方案:

System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
<小时/>

禁用-dev-shm-使用

根据 base_switches.cc disable-dev-shm-usage 似乎仅在 Linux 操作系统 上有效:

#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The /dev/shm partition is too small in certain VM environments, causing
// Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
// work-around this issue (a temporary directory will always be used to create
// anonymous shared memory files).
const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
#endif

在讨论中Add an option to use /tmp instead of /dev/shm大卫提到:

I think it would depend on how are /dev/shm and /tmp mounted.If they are both mounted as tmpfs I'm assuming there won't be any difference.if for some reason /tmp is not mapped as tmpfs (and I think is mapped as tmpfs by default by systemd), chrome shared memory management always maps files into memory when creating an anonymous shared files, so even in that case shouldn't be much difference. I guess you could force telemetry tests with the flag enabled and see how it goes.

As for why not use by default, it was a pushed back by the shared memory team, I guess it makes sense it should be useing /dev/shm for shared memory by default.

Ultimately all this should be moving to use memfd_create, but I don't think that's going to happen any time soon, since it will require refactoring Chrome memory management significantly.

<小时/>

引用

您可以在以下位置找到一些详细的讨论:

<小时/>

片尾

这里是 Sandbox 的链接故事。

关于google-chrome - WebDriver异常: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54984422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com