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

52

369

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

Loo answered 1/6, 2018 at 11:21 Comment(2)
I received this error when vncserver crashed and I had no X display anymorePalmieri
For a fix for running without an X display, use export DISPLAY=:0, see #50791233Ilse
L
24

Update:

I am able to get through the issue and now I am able to access the chrome with desired url.

Results of trying the provided solutions:

I tried all the settings as provided above but I was unable to resolve the issue

Explanation regarding the issue:

As per my observation DevToolsActivePort file doesn't exist is caused when chrome is unable to find its reference in scoped_dirXXXXX folder.

Steps taken to solve the issue

  1. I have killed all the chrome processes and chrome driver processes.
  2. Added the below code to invoke the chrome

    System.setProperty("webdriver.chrome.driver","pathto\\chromedriver.exe");    
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(options);
    driver.get(url);
    

Using the above steps I was able to resolve the issue.

Thanks for your answers.

Loo answered 8/6, 2018 at 15:32 Comment(1)
Do you know what affect useAutomationExtension has? It disables extensions for automation (screenshots/control etc) no? Shouldn't the advent of DevTools render this change to have no affect? codereview.chromium.org/2785413002Uriel
C
232

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.

Cocci answered 1/6, 2018 at 11:57 Comment(13)
But what caused this specific error about DevToolsActivePort file doesn't exist, and why did it suddenly start popping up?Mernamero
The "Additional Consideration" items - they look like they're quite applicable to this issue. Especially this kind of situation where it hadn't been established exactly what caused the problem.Bahrain
From the deleted part of @DebanjanB's post, this can be caused by using a Chromedriver which does not support the version of the installed Chrome. This can happen, for example, if chrome is upgraded without upgrading Chromedriver.Turgite
This used to solve the issue for me, it doesn't on my current system (Ubuntu 18 + Python 3.7)Dicephalous
In case this helps anybody else, just adding disable-dev-shm-usage wasn't enough. I had to also add --no-sandbox to get it to work. This was the complete fix for me for Selenium-java: chromeOptions.addArguments("--no-sandbox", "--disable-dev-shm-usage");Porterfield
If none of the above options helped (as in my case) - just run: chrome --headless from command line and you will see the actual issue (in my case it was some lib incompatibility). If everything is ok with your chrome setup it should delay for few seconds and then return with something like: [1006/110844.401199:ERROR:browser_process_sub_thread.cc(203)] Waited 3 ms for network service Duthie
@GeorgePantazes, your statement is absolutely true.Leucocyte
Unfortunately, @GeorgePantazes's solution did not help me.Cammi
I was hit by this inside docker because I didn't have --headless.Pivoting
@Mernamero DevToolsActivePort file doesn't exist the error comes from chromedriver, we can run chromedriver whis options as chromedriver --verbose then log level will come into detailPolymerize
This post helped me resolve this issue with a Docker container. Thanks!Ulphi
Does this fix apply even for Windows OS, beacuse i faced the same issue on one of my windows machine. only different thing in that system was i had disabled upgrade of google chrome from Services.Occidentalize
I think there's more to it. The --no-sandbox helps in my case of running a headless Chromium in a Docker container — however, I don't run it as root, I run it as a plain user. So the explanation about running as root doesn't apply, Idk why I have that problem.Marxmarxian
B
99

I started seeing this problem on Monday 2018-06-04. Our tests run each weekday. It appears that the only thing that changed was the google-chrome version (which had been updated to current) JVM and Selenium were recent versions on Linux box ( Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62, and xvfb-run).
Specifically adding the arguments "--no-sandbox" and "--disable-dev-shm-usage" stopped the error. I'll look into these issues to find more info about the effect, and other questions as in what triggered google-chrome to update.

ChromeOptions options = new ChromeOptions();
        ...
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");
Bahrain answered 6/6, 2018 at 17:8 Comment(8)
I want to clarify that this code was running each weekday on an Ubuntu Linux box, but equivalent code on Windows desktop ran OK even on Monday. I've found no info about what the functionality of the DevToolsActivePort file is for and that would be useful too. PKBahrain
These options stopped the error for me too. pd: using a Rails stack.Dowden
I still get [java] [1536892035.965][SEVERE]: Timed out receiving message from renderer: 60.000 errors even with thisQuintic
@Quintic - Hi! can you supply some more detail, like which OS, which versions of the components you're using, or how you're invoking the process?Bahrain
@Toby : Hi! I didn't mean to imply that the position made a difference, just the minimal use of those parameters. It seemed that some of the default values that I had relied on were changed when upgrades happened. Any other details re your system or message that you provide might help.Bahrain
Using protractor I added the above args to the chrome-options and it fixed it, odd as last time I ran the regression pack - about a month ago - with no args, it worked!Anatomical
I additionally required --remote-debugging-port=9222 to get it to work on Fedora 33Miniature
adding options.addArguments("--no-sandbox"); did the trick for me. Thanks for sharing!Stelliform
R
86

We encountered the same issue on Jenkins (Linux machine) and tried all the options above.

The only thing that helped was setting the --headless argument:

chrome_options.add_argument('--headless')

When we investigated further, we noticed that the XVFB screen didn't start property, which caused this error. After we fixed the XVFB screen, the issue was resolved.

Retouch answered 25/7, 2018 at 4:39 Comment(5)
this solved my issue, when running using C# (in this case the option looked like this: options.AddArgument("--headless");Poundfoolish
XVFB was the issue for mePsychopathy
What was the issue with XVFB. Can you please explain.Kenaz
This absolutely solved my problem! I was trying to get a python3.9 project with selenium and chromedriver running on Ubuntu 20.04 headless, but I kept getting OP's error. With your addition I got it to work! Thanks!Gaines
That was it - thanks! Xvfb had not been started on the server. As soon as I started it, everything ran without issue. Wish the original error message had been at least a bit more helpful for tracking this down.Lobectomy
E
61

I had the same problem in python. The above helped. Here is what I used in python -

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/path/to/your_chrome_driver_dir/chromedriver',chrome_options=chrome_options)
Euripus answered 13/6, 2018 at 1:15 Comment(3)
I solved my problem with upgrade chrome (I already had the latest chromedrive), hence I had to upgrade the usual browser as well.Rondarondeau
Thanks a lot, this is helpful also to google colabMerozoite
Flawless solution.Lecturer
M
39

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)
Murielmurielle answered 11/2, 2020 at 11:39 Comment(8)
same for me with docker with ubuntu 18.04, py3.7, chrome(driver) 80Intransigent
This worked for me without further issues. I had just started running into this issue today, but because of your answer it is quickly fixed! My environment is essentially the same as yours.Ulphi
On ubuntu 18 and jenkins it worked like that. In my case the 'headless' argument as the important argument missing..Alurta
remote-debugging-port=9222 after no-sandbox and disable-dev-shm-usage works for me on Fedora 33Miniature
Works for me. python 3.7.3, ubuntu 20.04, chrome 87.0.4280Hiramhirasuna
--remote-debugging-port=9222 helped java 11, ubuntu 20.04 and chromium-browser 91Insertion
I am using a lambda-python3.6 docker. I don't know which one of these were relevant in removing the error, but adding these options worked. Nothing else worked.Jemima
just hit this on Ubuntu runners with chromium. Indeed setting port helped, thanks!Unmistakable
T
35

I was facing the same issue recently and after some trial and error it worked for me as well.

MUST BE ON TOP:

options.addArguments("--no-sandbox"); //has to be the very first option

BaseSeleniumTests.java

public abstract class BaseSeleniumTests {

    private static final String CHROMEDRIVER_EXE = "chromedriver.exe";
    private static final String IEDRIVER_EXE = "IEDriverServer.exe";
    private static final String FFDRIVER_EXE = "geckodriver.exe";
    protected WebDriver driver;

    @Before
    public void setUp() {
        loadChromeDriver();
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.close();
            driver.quit();
        }
    }

    private void loadChromeDriver() {
        ClassLoader classLoader = getClass().getClassLoader();
        String filePath = classLoader.getResource(CHROMEDRIVER_EXE).getFile();
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeDriverService service = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File(filePath))
                .build();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
        options.addArguments("--headless");
        options.setExperimentalOption("useAutomationExtension", false);
        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.merge(capabilities);
        this.driver = new ChromeDriver(service, options);
    }

}

GoogleSearchPageTraditionalSeleniumTests.java

@RunWith(SpringRunner.class)
@SpringBootTest
public class GoogleSearchPageTraditionalSeleniumTests extends BaseSeleniumTests {

    @Test
    public void getSearchPage() {
        this.driver.get("https://www.google.com");
        WebElement element = this.driver.findElement(By.name("q"));
        assertNotNull(element);
    }

}

pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>
Traps answered 11/2, 2019 at 20:6 Comment(3)
Interesting ! How do you generate a .side file ? Is this something that a QA person does manually ?Traps
You use the Selenium IDE to record a test. The result is a .side file. It runs fine using the IDE, but I'm trying to run it using selenium-side-runner but running into all kinds of problems with chromedriver.Complaisance
has to be first option -- spend days to find this hahaCreolacreole
F
32

I ran into this problem on Ubuntu 20 with Python Selenium after first downloading the chromedriver separately and then using sudo apt install chromium-browser Even though they were the same version this kept happening.

My fix was to use the provided chrome driver that came with the repo package located at

/snap/bin/chromium.chromedriver

driver = webdriver.Chrome(chrome_options=options, executable_path='/snap/bin/chromium.chromedriver')
Fernferna answered 24/5, 2020 at 1:28 Comment(4)
Thx alot. This helped me: Specs: Ubuntu 20.04, python 3.8 with a snap-based Chromium installation.Amalgam
As you figured out, when working on Ubuntu, seems like Chromium browser also install a compatible chrome-driver that will always interfere with the one downloaded from chromedriver.chromium.org/downloads. The default location of the preinstalled driver are found at: /snap/bin/chromium.chromedriver Search for snap in the post below for more info. pythonfixing.com/2021/10/… The recommendation to get this to work is: Do NOT download driver from on your own. Use the one in snap/bin. Otherwise you will always get this error!Hefner
Very helpful! I wonder if this will mark the end of the endless battle to keep chromedriver updated to the correct chrome version? I am assuming that the snaps update automatically. Any idea if the chrome driver updates along with it?Nanji
In Nightwatchjs edit the server path in a config file like this nightwatchjs.org/guide/configuration/…Rapturous
L
24

Update:

I am able to get through the issue and now I am able to access the chrome with desired url.

Results of trying the provided solutions:

I tried all the settings as provided above but I was unable to resolve the issue

Explanation regarding the issue:

As per my observation DevToolsActivePort file doesn't exist is caused when chrome is unable to find its reference in scoped_dirXXXXX folder.

Steps taken to solve the issue

  1. I have killed all the chrome processes and chrome driver processes.
  2. Added the below code to invoke the chrome

    System.setProperty("webdriver.chrome.driver","pathto\\chromedriver.exe");    
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(options);
    driver.get(url);
    

Using the above steps I was able to resolve the issue.

Thanks for your answers.

Loo answered 8/6, 2018 at 15:32 Comment(1)
Do you know what affect useAutomationExtension has? It disables extensions for automation (screenshots/control etc) no? Shouldn't the advent of DevTools render this change to have no affect? codereview.chromium.org/2785413002Uriel
T
21

In my case it was problem with CI Agent account on ubuntu server, I solved this using custom --user-data-dir

chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')

My account used by CI Agent didn't have necessary permissions, what was interesting everything was working on root account

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')

driver = webdriver.Chrome(options=chrome_options)
url = 'https://www.google.com'
driver.get(url) 
get_url = driver.current_url 
print(get_url)
Trudey answered 17/2, 2021 at 20:43 Comment(3)
I am getting this error selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Anyone got the solution for this issue?Wrenn
this option worked for me, but ONLY when I had ALL of the above arguments added. Missing one, any one, would cause me to get the same error. I was using selenium in a docker FROM python:3.8-slim-buster image.Lamented
This also works when using a custom user in a docker image that does not have rootReform
T
14

There is lot of possible reasons for the RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist error message (as we can see from the number of answers for this question). So let's dive deeper to explain what exactly this error message means.

According to chromedriver source code the message is created in ParseDevToolsActivePortFile method. This method is called from the loop after launching chrome process.

In the loop the driver check if the chrome process is still running and if the ParseDevToolsActivePortFile file was already created by chrome. There is a hardcoded 60s timeout for this loop.

I see two possible reasons for this message:

  • Chrome is really slow during startup - for example due to lack of system resources - mainly CPU or memory. In this case it can happen that sometimes chrome manage to start in time limit and sometimes not.
  • There is another issue which prevents chrome to start - missing or broken dependency, wrong configuration etc. In such case this error message is not really helpful and you should find another log message which explain the true reason of the failure.
Trousseau answered 25/8, 2021 at 12:21 Comment(0)
A
11

It happens when chromedriver fails to figure out what debugging port chrome is using.

One possible cause is an open defect with HKEY_CURRENT_USER\Software\Policies\Google\Chrome\UserDataDir

But in my last case, it was some other unidentified cause.

Fortunately setting port number manually worked:

final String[] args = { "--remote-debugging-port=9222" };
options.addArguments(args);
WebDriver driver = new ChromeDriver(options);
Airway answered 7/11, 2019 at 11:52 Comment(1)
Is it a constant port? Or where can I look for it?Solidus
B
10

I know it's an old question and it already has a lot of answers. However, I ran into this issue, bumped into this thread and none of the proposed solutions helped. After spending a few days(!) on it I finally found a solution:

My problem was that I was using the selenium/standalone-chrome image on a MacBook with M1 chip. After switching to seleniarm/standalone-chromium everything finally started to work.

Bernadinebernadotte answered 4/9, 2022 at 13:36 Comment(0)
E
9

I was stuck on this for a very long time and finally fixed it by adding this an additional option:

options.addArguments("--crash-dumps-dir=/tmp")

Examen answered 18/5, 2022 at 15:27 Comment(3)
Hey. @PlumsAhoy. Hope you are doing well. I had this problem all day, and tried to find the right solution all day... I followed all upvoted answers, but they were not for me. Just found your answer in over 24 hours, and this solved my problem... Thanks for your answer...Athenian
For selenium version 4.x+ you should change this line to this: chrome_options.add_argument("--crash-dumps-dir=/tmp") . As V4.X+ has changed addArguments() to add_argument()Brushwood
This works for me. Ubuntu 22 and selenium 4.19.0. Thanks!Wilmer
P
8

As stated in this other answer:

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

Among the possible causes, I would like to mention the fact that, in case you are running an headless Chromium via Xvfb, you might need to export the DISPLAY variable: in my case, I had in place (as recommended) the --disable-dev-shm-usage and --no-sandbox options, everything was running fine, but in a new installation running the latest (at the time of writing) Ubuntu 18.04 this error started to occurr, and the only possible fix was to execute an export DISPLAY=":20" (having previously started Xvfb with Xvfb :20&).

Preferential answered 7/8, 2019 at 22:40 Comment(3)
OMG Thank you. I was making a few changes to our docker container and I accidentally left out xvfb. I never would have found this if you hadn't had left this here :-).Ziegler
using xvfb-run is an option as well.Formic
This is almost exactly that worked for me, see my answer here https://mcmap.net/q/67213/-selenium-webdriverexception-chrome-failed-to-start-crashed-as-google-chrome-is-no-longer-running-so-chromedriver-is-assuming-that-chrome-has-crashedCantonese
S
6

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.

Semipermeable answered 2/11, 2019 at 17:50 Comment(1)
Thank you! This was the bug I was looking for, it's headless not --headlessBuxton
C
5

Old question but a similar issue nearly drove me to insanity so sharing my solution. None of the other suggestions fixed my issue.

When I updated my Docker image Chrome installation from an old version to Chrome 86, I got this error. My setup was not identical but we were instantiating Chrome through a selenium webdriver.

The solution was to pass the options as goog:chromeOptions hash instead of chromeOptions hash. I truly don't know if this was a Selenium, Chrome, Chromedriver, or some other update, but maybe some poor soul will find solace in this answer in the future.

Cheapen answered 13/10, 2020 at 17:4 Comment(2)
Could you describe how you used goog:chromeOptions a little more? Right now I'm using chrome_options = webdriver.ChromeOptions() and chrome_options.add_argument(...)Ledda
Unfortunately I recently left the company where I implemented this @Ledda so I don't have a code example in front of me. I was using the Ruby driver and I believe it was just a hash passed to ChromeOptions(). Something like chrome_options = webdriver.ChromeOptions({"goog:chromeOptions": { args: ["headless"] }). I'm sorry I don't have an exact snippet for the syntax.Cheapen
M
5

This is being discussed in ChromeDriver Issue #4403. The later comments 32 and 35 have valuable information from a Chromium team member.


https://bugs.chromium.org/p/chromedriver/issues/detail?id=4403#c32 /

Status: Started (was: Fixed)

We have not solved the issue with debuggerAddress in the pipes mode yet (see chromedriver:4533). Selenium cannot start a new session without this information as the whole BiDirectional API (CDP based) relies on this information (See https://www.selenium.dev/documentation/webdriver/bidirectional/bidi_api/). We will have to restore "remote-debugging-port" as a default mode for now.


https://bugs.chromium.org/p/chromedriver/issues/detail?id=4403#c35

Please try chrome_options.add_argument('--remote-debugging-pipe') In this mode DevToolsActivePort is not used. You will need ChromeDriver-117 or newer.

Mozart answered 1/10, 2023 at 3:45 Comment(1)
was looking for something newer. trying this.Ironstone
R
4

For Ubuntu 20 it did help me to use my systems chromium driver instead of the downloaded one:

# chromium which
/snap/bin/chromium

driver = webdriver.Chrome('/snap/bin/chromium.chromedriver',
                          options=chrome_options)

And for the downloaded webdriver looks like it needs the remote debug port --remote-debugging-port=9222 to be set, as in one of the answers (by Soheil Pourbafrani):

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome('<path_to>/chromedriver', options=chrome_options)
Rayraya answered 14/2, 2021 at 11:31 Comment(0)
E
4

Date 9/16/2021

Everything works fine running chrome with selenium locally with python inside the docker hosted ubuntu container. When attempting to run from Jenkins the error above is returned WebDriverException: unknown error: DevToolsActivePort

Environment:

-Ubuntu21.04 inside a docker container with RDP access.

-chromedriver for chrome version: 93

Solution: Inside the python file that starts the browser I had to set the DISPLAY environment variable using the following lines:

import os

os.environ['DISPLAY'] = ':10.0'
#DISPLAY_VAR = os.environ.get('DISPLAY')
#print("DISPLAY_VAR:", DISPLAY_VAR)
Emergency answered 17/9, 2021 at 0:8 Comment(0)
I
3

I had the same issue, but in my case chrome previously was installed in user temp folder, after that was reinstalled to Program files. So any of solution provided here was not help me. But if provide path to chrome.exe all works:

chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

I hope this helps someone =)

Iinde answered 13/7, 2018 at 13:21 Comment(1)
seems the exact opposite of @shiuu fix belowUriel
G
3

update capabilities in conf.js as

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js'],
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
    }
  },

};
Gandhiism answered 20/1, 2019 at 15:12 Comment(0)
L
3

Had the same issue. I am running the selenium script on Google cloud VM.

options.addArguments("--headless");

The above line resolved my issue. I removed the other optional arguments. I think the rest lines of code mentioned in other answers did not have any effect on resolving the issue on the cloud VM.

Loki answered 30/9, 2020 at 5:15 Comment(0)
N
3

I've received this issue while running multiple chromium instances at the same machine. You need to create a separate temp directory for every chromium instance.

addArguments(`user-data-dir=${CURRENT_CHROMIUM_TMP_DIR}`);
Neurotic answered 19/7, 2023 at 8:30 Comment(2)
Thanks @Neurotic Note: I had to do this in Rails options.add_argument("--user-data-dir=#{Rails.root.join('tmp')}"). Was only happening on Linux was multiple system testsHuey
Can you please elaborate on this? what exactly needs to be done?Aney
A
2

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.

Airway answered 15/11, 2018 at 13:21 Comment(2)
I had a similar issue, but in linux - my chrome processes were not properly exited after the script crashed, and they were being reused incorrectly. killing them solved the issueIrrevocable
This was my exact issue too. I wanted to use my default profile. After killing all other chrome instances I had already running, it worked fine.Scorekeeper
A
2

In my case, I was trying to create a runnable jar on Windows OS with chrome browser and want to run the same on headless mode in unix box with CentOs on it. And I was pointing my binary to a driver that I have downloaded and packaged with my suite. For me, this issue continue to occur irrespective of adding the below:

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
options.setBinary("/pointing/downloaded/driver/path/in/automationsuite");
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
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("window-size=1024,768"); // Bypass OS security model
options.addArguments("--log-level=3"); // set log level
options.addArguments("--silent");//
options.setCapability("chrome.verbose", false); //disable logging
driver = new ChromeDriver(options);

Solution that I've tried and worked for me is, download the chrome and its tools on the host VM/Unix box, install and point the binary to this in the automation suite and bingo! It works :)

Download command:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

Install command:

sudo yum install -y ./google-chrome-stable_current_*.rpm

Update suite with below binary path of google-chrome:

options.setBinary("/opt/google/chrome/google-chrome");

And.. it works!

Adjacent answered 19/11, 2018 at 7:4 Comment(1)
Where do we add this code? I see no C# code in my .side fileComplaisance
H
2

I also faced this issue while integrating with jenkins server, I was used the root user for jenkin job, the issue was fixed when I changed the user to other user. I am not sure why this error occurs for the root user.

  • Google Chrome Version 71.0
  • ChromeDriver Version 2.45
  • CentOS7 Version 1.153
Hahnemann answered 10/1, 2019 at 4:13 Comment(1)
Non-root user worked for me, I had the correct chrome driver version for the chromium.Convertible
A
2

I run selenium tests with Jenkins running on an Ubuntu 18 LTS linux. I had this error until I added the argument 'headless' like this (and some other arguments):

ChromeOptions options = new ChromeOptions();
options.addArguments("headless"); // headless -> no browser window. needed for jenkins
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
ChromeDriver driver = new ChromeDriver(options);

driver.get("www.google.com");
Alurta answered 31/8, 2020 at 9:5 Comment(0)
P
2

in my case, when i changed the google-chrome and chromedriver version, the error was fixed :)

#google-chrome version
[root@localhost ~]# /usr/bin/google-chrome --version
Google Chrome 83.0.4103.106 

#chromedriver version
[root@localhost ~]# /usr/local/bin/chromedriver -v
ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103@{#119})

ps: selenium verison was 3.9.1

Polymerize answered 24/3, 2021 at 11:2 Comment(0)
G
1

No solution worked for my. But here is a workaround:

maxcounter=5
for counter in range(maxcounter):
    try:           
        driver = webdriver.Chrome(chrome_options=options,
                          service_log_path=logfile,
                          service_args=["--verbose", "--log-path=%s" % logfile])
        break
    except WebDriverException as e:
        print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
        time.sleep(10)
        if counter==maxcounter-1:
            raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")
Gunflint answered 30/10, 2018 at 8:19 Comment(0)
G
1

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.

Gothicism answered 3/12, 2018 at 23:45 Comment(4)
seems the exact opposite of @sergiy-konoplyaniy fix above :'(Uriel
In our setBinary, we tried to set chrome driver, which seems a mistake. @sergiy-konoplyaniy's fix sets chrome.exe via setBinary.Gothicism
Where did you have this code? All I have is a .side file, and it has no C# code in it.Complaisance
Hahahaha, this solved issue for me, but not removing this line and adding it! Thank you) Seems driver couldn't find my executable using a default path. But why id didn't just say this, showing strange messages....Mendive
A
1

I ran into same issue, i am using UBUNTU, PYTHON and OPERA browser. in my case the problem was originated because i had an outdated version of operadriver.

Solution: 1. Make sure you install latest opera browser version ( do not use opera beta or opera developer), for that go to the official opera site and download from there the latest opera_stable version.

  1. Install latest opera driver (if you already have an opera driver install, you have to remove it first use sudo rm ...)

wget https://github.com/operasoftware/operachromiumdriver/releases/download/v.80.0.3987.100/operadriver_linux64.zip

   unzip operadriver_linux64.zip
   sudo mv operadriver /usr/bin/operadriver
   sudo chown root:root /usr/bin/operadriver
   sudo chmod +x /usr/bin/operadriver

in my case latest was 80.0.3987 as you can see

  1. Additionally i also installed chromedriver (but since i did it before testing, i do not know of this is needed) in order to install chromedriver, follow the steps on previous step :v

  2. Enjoy and thank me!

Sample selenium code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Opera()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()
Avouch answered 28/3, 2020 at 19:55 Comment(0)
H
1

I came across the same problem, in my case there are two different common user userA and userB in Linux system. userA first run the selinium programe which start chrome browswer with ChromeDriver successfully, when it came to userB, the DevToolsActivePort file doesn't exist error occur.

I tried the --remote-debugging-port=9222 option, but it lead to a new exception: selenium.common.exceptions.WebDriverException: Message: chrome not reachable

The I ran google-chome directory and see the following error:
mkdir /tmp/Crashpad/new: Permission denied (13)

The I search the problem and got this:
https://johncylee.github.io/2022/05/14/chrome-headless-%E6%A8%A1%E5%BC%8F%E4%B8%8B-devtoolsactiveport-file-doesn-t-exist-%E5%95%8F%E9%A1%8C/

chrome_options.add_argument(f"--crash-dumps-dir={os.path.expanduser('~/tmp/Crashpad')}")

Thanks to @johncylee.

Halbert answered 2/9, 2022 at 12:30 Comment(1)
I found the same problem and fixed it by making /tmp/Crashpad world-writable (on a shared workstation), but this is a better idea.Scare
E
1

For me, the issue was in the systemD service file. I pass the shell environment as venv

Environment="proejct/venv/bin"

when I add the /bin:/usr/bin to Environment:

Environment="proejct/venv/bin:/usr/bin:/bin"

and Finally, it worked.

Eade answered 21/10, 2022 at 17:39 Comment(0)
V
0

I ran into the same issue running Chrome via Behat/Mink and Selenium in a Docker container. After some fiddling, I arrived at the following behat.yml which supplies the switches mentioned above. Note that all of them were required for me to get it running successfully.

default:
    extensions:
        Behat\MinkExtension:
            base_url: https://my.app/
            default_session: selenium2
            selenium2:
                browser: chrome
                capabilities:
                    extra_capabilities:
                        chromeOptions:
                            args:
                                - "headless"
                                - "no-sandbox"
                                - "disable-dev-shm-usage"
Vegetarianism answered 19/6, 2019 at 16:13 Comment(0)
D
0

In my case, I'm in a Kubernetes environment where I cannot use the default TMPDIR because it will fill up the temp directory with garbage.

So I was using this to use a different tmpdir:

driver = new ChromeDriver(new ChromeDriverService.Builder()
                    .withEnvironment(ImmutableMap.of("TMPDIR", customTmpPath))
                    .build(), options);

But now that I've upgraded everything to the latest, this no longer seems to work. I will need to find a new way to do this.

Donoho answered 23/7, 2019 at 2:51 Comment(0)
C
0

Wrong port number in my case. Check if port number when starting Selenium server is the same as in your script.

Cherimoya answered 22/7, 2020 at 19:6 Comment(0)
N
0

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).

Nayarit answered 27/8, 2020 at 9:0 Comment(0)
L
0

I use chromium but I have created a shell script called chrome just to be easy for me to open the browser from dmenu.

#!/bin/bash

/usr/bin/chromium

Chrome driver looking for chrome in PATH and executes that. In result I got the same error.

org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /home/s1n7ax/.local/share/s1n7ax/bin/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 's1n7ax', ip: '127.0.1.16', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.70-1-lts', java.version: '11.0.8'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x56030c96dd99 <unknown>

I just removed the shell script and added a soft link to chromium. Everything working now.

Lesbianism answered 9/11, 2020 at 16:30 Comment(0)
E
0

My problem was a bug in php-webdriver. My code was:

$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments([
    '--headless',
    '--no-sandbox',
    '--disable-gpu',
    '--disable-dev-shm-usage',
    '--no-proxy-server'
]);
$chromeOptions->setExperimentalOption('detach', true);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(
    ChromeOptions::CAPABILITY,
    $chromeOptions
);

as you can see, everything is in line with the rest of possible reasons.

But actually capabilities weren't passing to chromedriver. I had to change setting chrome options capability to:

$capabilities->setCapability(
    ChromeOptions::CAPABILITY_W3C, // <<< Have to use W3C capabilities with recent versions of Chromedriver.
    $chromeOptions->toArray() // <<<<< bug in php-webdriver 1.9, object not getting serialized automatically like with the deprecated capability ChromeOptions::CAPABILITY
);

My setup was:

$ chromedriver --version
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614})
$ java -jar selenium-server-standalone-3.141.59.jar --version
Selenium server version: 3.141.59, revision: e82be7d358

Made a bug report and a PR to fix this bug in php-webdriver

https://github.com/php-webdriver/php-webdriver/issues/849

Equate answered 27/12, 2020 at 13:57 Comment(0)
D
0

I had the same error, and I found out that the cause was because my computer disk was full. After deleting some unnecessary files, the error went away.

Dangerous answered 28/1, 2021 at 13:48 Comment(0)
S
0

If adding arguments/options does not fix it then it could be a permissions issue on /tmp directory.

Make sure your user that executes Chrome has permissions to create folder/files in /tmp folder. This was the solution in my case

Solleret answered 24/5, 2022 at 21:41 Comment(0)
W
0

I also esperienced this issue and none of the proposed solutions seemed to work. Then I found out that the problem is that I was running on WSL version 1, and it seems there chromedriver works with the windows browser, not the one installed with aptitude.

To make it compatible with WSL version 1 and version 2 I found (and tested in debian WSLv2 and ubuntu WSLv1 that it works) that the version of the platform is displayed with the first letter in uppercase for the word Microsoft.

So the solution ended up like this:

    import platform
    from selenium.webdriver.chrome.service import Service as ChromeService
    from seleniumwire import webdriver

    chromedriver = 'chromedriver.exe'
    
    # According to:
    # https://mcmap.net/q/67214/-webdriverexception-message-unknown-error-devtoolsactiveport-file-doesn-39-t-exist
    # When using WSL v1 the chromedriver.exe of local chrome of windows is used
    # In WSL v2 (updated version) it does work using the installation shown in the README.md)
    # And according to
    # https://github.com/microsoft/WSL/issues/4555
    # It is possible to differentiate the version of WSL by the first uppercase of the platform 
    # version of Microsoft. Therefore only the linux chromedriver is used if that word is matched 
    # in the platform of the driver. 
    if platform.system() == 'Linux' and not re.search(re.escape('Microsoft'), platform.platform()):
        chromedriver = 'chromedriver'

    driver_path = os.path.join(drivers_path, chromedriver)
  service = ChromeService(driver_path)

    driver = webdriver.Chrome(
        service=service,
        options=__get_chrome_options(headless)
    )
Weldon answered 1/8, 2022 at 12:27 Comment(0)
U
0

This one worked for me. If you are on a server without a graphical environment, you might need to use Xvfb to simulate a display.

from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 800))
display.start()
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(chrome_options=options)
Unconcern answered 13/6, 2023 at 8:36 Comment(0)
L
0

Error: selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

  1. vps on DO
  2. ubuntu 22.10
  3. python 3.10.7

It worked for me:

options.add_argument('--no-sandbox')
options.add_argument("--remote-debugging-port=9222")
options.add_argument('--headless')
options.add_argument('--disable-gpu')
Lisette answered 13/7, 2023 at 15:7 Comment(0)
J
0

This may happen as well if the version of chrome & chrome driver do not match. The versions must be exactly the same version!

Jota answered 28/8, 2023 at 12:38 Comment(0)
W
0

For GitHub Actions

For anyone running into this error while running tests on their CI/CD environment (GitHub Actions in my case), I was getting this because I was trying to replace the GitHub runner's default version of Chrome with an earlier version in order to fix a separate issue. I fixed it by replacing my rm and mv commands with a simple ln command to symbolically link the default Chrome binary (located at usr/bin/google-chrome) to my newly-downloaded one.

Here is the relevant part of my GitHub Actions workflow:

  - name: Downgrade Chrome browser to v114
    uses: browser-actions/setup-chrome@v1
    with:
      chrome-version: 1134343 # Last commit number for Chrome v114
    id: setup-chrome
  - run: sudo ln -fs ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome
  - name: Downgrade Chrome driver to v114
    run: php artisan dusk:chrome-driver `/usr/bin/google-chrome --version | cut -d " " -f3 | cut -d "." -f1`
Whorl answered 29/8, 2023 at 19:27 Comment(0)
T
0

This issue happened to me when I tried to stop using incognito mode and selected a user profile while working on chrome, the following are the options I added so this happened:

    # Make sure to change your user pathand profile path
    options.add_argument("user-data-dir=C:/Users/LQss/AppData/Local/Google/Chrome/User Data")
    options.add_argument('profile-directory=Profile 2')

When this error occured It got fixed only when I closed all other chrome instances

Taffy answered 23/1 at 0:48 Comment(0)
S
0

I read all the answers and could not fix the issue. My solution has been just to point the user data directory to a non-existing directory:

options.add_argument('--user-data-dir=/home/myUser/.config/non-existing-dir')

Before that, I was pointing to the usual user data directory where the daily use browser is directed, but there must be something that is causing the error.

Susurrate answered 2/3 at 19:11 Comment(0)
Q
-1

Since this is the most active message for this type of error, I wanted to mention my solution (after spending hours to fix this).

On Ubuntu 18.04, using Chrome 70 and Chromedriver 2.44, and Python3 I kept getting the same DevToolsActivePort error, even when I disabled all options listed above. The chromedriver log file as well as ps showed that the chromedriver I set in chrome_options.binary_location was running, but it always gave DevToolsActivePort error. When I removed chrome_options.binary_location='....' and add it to webdriver creation, I get it working fine. webdriver.Chrome('/path to ... /chromedriver',chrome_options=chrome_options)

Thanks everybody for your comments that make me understand and resolve the issue.

Querulous answered 27/11, 2018 at 22:48 Comment(0)
H
-1

was facing the same issue while trying to run selenium on a linux server ,try downgrading your chrome version ,it did the trick for me

pick version from here

http://170.210.201.179/linux/chrome/deb/pool/main/g/google-chrome-stable/

Hyetography answered 22/8, 2022 at 10:6 Comment(0)
F
-2

I solve this problem by installing yum -y install gtk3-devel gtk3-devel-docs", it works ok

My work env is :

Selenium Version 3.12.0
ChromeDriver Version v2.40
Chrome 68 level

Before:
enter image description here enter image description here

After:
enter image description here enter image description here

Faletti answered 30/7, 2018 at 6:43 Comment(2)
From Review: Please don't post text in images. EDIT your answer and replace those images with text. ThanksGui
Does this solve the problem for anyone? This didn't solve the problem for meAha
H
-3
Hollie answered 5/8, 2021 at 3:58 Comment(2)
Hi crifan. I can see in your other linked answer that you've correctly demonstrated the recommended solution to run as a non-root user. Did you perhaps have a typo here and mean to say don't use the root user?Guardi
@Guardi thanks for your kind remind. I has fixed my typoHollie

© 2022 - 2024 — McMap. All rights reserved.