WebDriverException:未知错误:尝试启动 Chrome 浏览器时 DevToolsActivePort 文件不存在 [英] WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

查看:271
本文介绍了WebDriverException:未知错误:尝试启动 Chrome 浏览器时 DevToolsActivePort 文件不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 URL 启动 chrome,浏览器启动后什么也不做.

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

无法打开带有 url 的浏览器:'https://www.google.com'(根本原因:org.openqa.selenium.WebDriverException:未知错误:DevToolsActivePort 文件不存在(驱动程序信息:chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64)(警告:服务器没有提供任何堆栈跟踪信息)

我的配置:

  • 铬:66
  • Chrome 浏览器:2.39.56

P.S在 Firefox 中一切正常

解决方案

Thumb rule

<块引用>

Chrome 在启动过程中崩溃的一个常见原因是以 root 用户(administrator>) 在 Linux 上.虽然可以通过在创建 WebDriver 会话时传递 --no-sandbox 标志来解决此问题,但这种配置不受支持且非常不鼓励.您需要将环境配置为以普通用户身份运行 Chrome.


这个错误信息...

org.openqa.selenium.WebDriverException:未知错误:DevToolsActivePort 文件不存在

...表示 ChromeDriver 无法启动/生成新的 WebBrowser,即 Chrome 浏览器 会话.

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

但是根据 将 --disable-dev-shm-usage 添加到默认启动标志 似乎添加参数 --disable-dev-shm-usage 将暂时解决问题.

如果您希望发起/跨新的 Chrome 浏览器会话,您可以使用以下解决方案:

System.setProperty(webdriver.chrome.driver", C:\path\to\chromedriver.exe");ChromeOptions options = new ChromeOptions();options.addArguments(开始最大化");//以最大化模式打开浏览器options.addArguments("disable-infobars");//禁用信息栏options.addArguments("--disable-extensions");//禁用扩展options.addArguments("--disable-gpu");//仅适用于 windows 操作系统options.addArguments("--disable-dev-shm-usage");//克服资源有限的问题options.addArguments("--no-sandbox");//绕过操作系统安全模型WebDriver driver = new ChromeDriver(options);driver.get(https://google.com");


禁用-dev-shm-usage

根据 base_switches.cc disable-dev-shm-usage 似乎只在 Linux OS 上有效:

#if 已定义(OS_LINUX) &&!defined(OS_CHROMEOS)///dev/shm 分区在某些 VM 环境中太小,导致//Chrome 失败或崩溃(参见 http://crbug.com/715363).使用这个标志来//解决此问题(将始终使用临时目录来创建//匿名共享内存文件).const char kDisableDevShmUsage[] = "disable-dev-shm-usage";#万一

在讨论中 添加一个选项以使用/tmp 而不是/dev/shm 大卫提到:

<块引用>

我认为这取决于/dev/shm 和/tmp 的安装方式.如果它们都安装为 tmpfs,我假设不会有任何区别.如果由于某种原因/tmp 没有映射为 tmpfs(我认为 systemd 默认映射为 tmpfs),chrome 共享内存管理在创建匿名共享文件时总是将文件映射到内存中,所以即使在这种情况下也不应该差别很大.我想你可以在启用标志的情况下强制进行遥测测试,看看它是如何进行的.

<块引用>

至于为什么不默认使用,这是共享内存团队的推论,我想应该默认使用/dev/shm作为共享内存是有道理的.

<块引用>

最终所有这些都应该转向使用 memfd_create,但我认为这不会很快发生,因为它需要显着重构 Chrome 内存管理.


参考

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


尾声

这是沙盒的链接 故事.

I am trying to launch chrome with an URL, the browser launches and it does nothing after that.

I am seeing the below error after 1 minute:

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)

My configuration:

  • Chrome : 66
  • ChromeBrowser : 2.39.56

P.S everything works fine in Firefox

解决方案

Thumb rule

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.


This error message...

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

...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

Your code trials and the versioning information of all the binaries would have given us some hint about what's going wrong.

However as per Add --disable-dev-shm-usage to default launch flags seems adding the argument --disable-dev-shm-usage will temporary solve the issue.

If you desire to initiate/span a new Chrome Browser session you can use the following solution:

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");


disable-dev-shm-usage

As per base_switches.cc disable-dev-shm-usage seems to be valid only on Linux OS:

#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

In the discussion Add an option to use /tmp instead of /dev/shm David mentions:

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.


Reference

You can find a couple of detailed discussions in:


Outro

Here is the link to the Sandbox story.

这篇关于WebDriverException:未知错误:尝试启动 Chrome 浏览器时 DevToolsActivePort 文件不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆