WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

前端 未结 29 3447
旧巷少年郎
旧巷少年郎 2020-11-21 07:11

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         


        
相关标签:
29条回答
  • 2020-11-21 07:27

    In my case it happened when I've tried to use my default user profile:

    ...
    options.addArguments("user-data-dir=D:\\MyHomeDirectory\\Google\\Chrome\\User Data");
    ...
    

    This triggered chrome to reuse processes already running in background, in such a way, that process started by chromedriver.exe was simply ended.

    Resolution: kill all chrome.exe processes running in background.

    0 讨论(0)
  • 2020-11-21 07:27

    You can get this error simply for passing bad arguments to Chrome. For example, if I pass "headless" as an arg to the C# ChromeDriver, it fires up great. If I make a mistake and use the wrong syntax, "--headless", I get the DevToolsActivePort file doesn't exist error.

    0 讨论(0)
  • 2020-11-21 07:27

    It seems there are many possible causes for this error. In our case, the error happened because we had the following two lines in code:

    System.setProperty("webdriver.chrome.driver", chromeDriverPath);
    chromeOptions.setBinary(chromeDriverPath);
    

    It's solved by removing the second line.

    0 讨论(0)
  • 2020-11-21 07:27

    TL;DR: If you are using VirtualBox shared folders, do not create the Chrome profile there!


    I ran into this error under Debian 10, but it did not occur under Ubuntu 18.04.

    In my Selenium tests, I wanted to install an extension, and use the following Chrome options:

    chromeOptions.addArguments(
      `load-extension=${this.extensionDir}`,
      `user-data-dir=${this.profileDir}`,
      `disable-gpu`,
      `no-sandbox`,
      `disable-setuid-sandbox`,
      `disable-dev-shm-usage`,
    );
    

    The issue was that I was attempting to create a Chrome profile under a nonstandard directory which was part of a VirtualBox shared folder. Despite using the exact same version of Chrome and Chromedriver, it didn't work under Debian.

    The solution was to choose a profile directory somewhere else (e.g. ~/chrome-profile).

    0 讨论(0)
  • 2020-11-21 07:30

    In my case in the following environment:

    • Windows 10
    • Python 3.7.5
    • Google Chrome version 80 and corresponding ChromeDriver in the path C:\Windows
    • selenium 3.141.0

    I needed to add the arguments --no-sandbox and --remote-debugging-port=9222 to the ChromeOptions object and run the code as administrator user by lunching the Powershell/cmd as administrator.

    Here is the related piece of code:

    options = webdriver.ChromeOptions()
    options.add_argument('headless')
    options.add_argument('--disable-infobars')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('--no-sandbox')
    options.add_argument('--remote-debugging-port=9222')
    driver = webdriver.Chrome(options=options)
    
    0 讨论(0)
  • 2020-11-21 07:32

    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:

    • unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
    • Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd

    Outro

    Here is the link to the Sandbox story.

    0 讨论(0)
提交回复
热议问题