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

369,163

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

We were having the same issues on our jenkins slaves (linux machine) and tried all the options above.

The only thing helped is setting the argument

chrome_options.add_argument('--headless')

But when we investigated further, noticed that XVFB screen doesn't started property and thats causing this error. After we fix XVFB screen, it resolved the issue.

Solution 5

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)
Share:
369,163

Related videos on Youtube

Kumar Sampath
Author by

Kumar Sampath

Updated on September 17, 2021

Comments

  • Kumar Sampath
    Kumar Sampath over 2 years

    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

    • xtian
      xtian over 5 years
      I received this error when vncserver crashed and I had no X display anymore
    • bers
      bers about 2 years
      For a fix for running without an X display, use export DISPLAY=:0, see stackoverflow.com/questions/50790733/…
  • Pete Kelley
    Pete Kelley almost 6 years
    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. PK
  • Admin
    Admin almost 6 years
    But what caused this specific error about DevToolsActivePort file doesn't exist, and why did it suddenly start popping up?
  • Mario Pérez Alarcón
    Mario Pérez Alarcón almost 6 years
    These options stopped the error for me too. pd: using a Rails stack.
  • Pete Kelley
    Pete Kelley almost 6 years
    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.
  • sɐunıɔןɐqɐp
    sɐunıɔןɐqɐp almost 6 years
    From Review: Please don't post text in images. EDIT your answer and replace those images with text. Thanks
  • Bendram
    Bendram over 5 years
    Does this solve the problem for anyone? This didn't solve the problem for me
  • axel_ande
    axel_ande over 5 years
    I solved my problem with upgrade chrome (I already had the latest chromedrive), hence I had to upgrade the usual browser as well.
  • Jonathan
    Jonathan over 5 years
    I still get [java] [1536892035.965][SEVERE]: Timed out receiving message from renderer: 60.000 errors even with this
  • Pete Kelley
    Pete Kelley over 5 years
    @Jonathan - 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?
  • expz
    expz over 5 years
    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.
  • ozz
    ozz over 5 years
    this solved my issue, when running using C# (in this case the option looked like this: options.AddArgument("--headless");
  • jeremycg
    jeremycg over 5 years
    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 issue
  • Toby
    Toby over 5 years
    seems the exact opposite of @shiuu fix below
  • Toby
    Toby over 5 years
    seems the exact opposite of @sergiy-konoplyaniy fix above :'(
  • Toby
    Toby over 5 years
    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/2785413002
  • shiuu
    shiuu over 5 years
    In our setBinary, we tried to set chrome driver, which seems a mistake. @sergiy-konoplyaniy's fix sets chrome.exe via setBinary.
  • Pete Kelley
    Pete Kelley over 5 years
    @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.
  • tw0000
    tw0000 about 5 years
    This used to solve the issue for me, it doesn't on my current system (Ubuntu 18 + Python 3.7)
  • AEngineer
    AEngineer almost 5 years
    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!
  • pabrams
    pabrams almost 5 years
    Where do we add this code? I see no C# code in my .side file
  • pabrams
    pabrams almost 5 years
    Where did you have this code? All I have is a .side file, and it has no C# code in it.
  • Nital
    Nital almost 5 years
    Interesting ! How do you generate a .side file ? Is this something that a QA person does manually ?
  • pabrams
    pabrams almost 5 years
    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.
  • George Pantazes
    George Pantazes over 4 years
    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");
  • Ryan Shillington
    Ryan Shillington over 4 years
    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 :-).
  • ARA1307
    ARA1307 over 4 years
    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
  • S.K. Venkat
    S.K. Venkat over 4 years
    @GeorgePantazes, your statement is absolutely true.
  • Alpha
    Alpha over 4 years
    Unfortunately, @GeorgePantazes's solution did not help me.
  • Mike Shiyan
    Mike Shiyan about 4 years
    Is it a constant port? Or where can I look for it?
  • patroqueeet
    patroqueeet about 4 years
    same for me with docker with ubuntu 18.04, py3.7, chrome(driver) 80
  • Ryan Harris
    Ryan Harris about 4 years
    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.
  • GGhe
    GGhe about 4 years
    I was hit by this inside docker because I didn't have --headless.
  • Jacob Brazeal
    Jacob Brazeal about 4 years
    has to be first option -- spend days to find this haha
  • Admin
    Admin almost 4 years
    Non-root user worked for me, I had the correct chrome driver version for the chromium.
  • lucaswxp
    lucaswxp almost 4 years
    XVFB was the issue for me
  • Codev
    Codev over 3 years
    On ubuntu 18 and jenkins it worked like that. In my case the 'headless' argument as the important argument missing..
  • Tyler Gallenbeck
    Tyler Gallenbeck over 3 years
    What was the issue with XVFB. Can you please explain.
  • CPak
    CPak over 3 years
    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(...)
  • Eric Dauenhauer
    Eric Dauenhauer over 3 years
    Unfortunately I recently left the company where I implemented this @CPak 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.
  • Scott P.
    Scott P. over 3 years
    I additionally required --remote-debugging-port=9222 to get it to work on Fedora 33
  • Scott P.
    Scott P. over 3 years
    remote-debugging-port=9222 after no-sandbox and disable-dev-shm-usage works for me on Fedora 33
  • Pramod Yadav
    Pramod Yadav over 3 years
    adding options.addArguments("--no-sandbox"); did the trick for me. Thanks for sharing!
  • horaceT
    horaceT over 3 years
    Works for me. python 3.7.3, ubuntu 20.04, chrome 87.0.4280
  • dnwjn
    dnwjn about 3 years
    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!
  • huang botao
    huang botao about 3 years
    @user9315861 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 detail
  • bhattraideb
    bhattraideb about 3 years
    I am getting this error selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Anyone got the solution for this issue?
  • Trook2007
    Trook2007 almost 3 years
    using xvfb-run is an option as well.
  • hatze
    hatze almost 3 years
    Thx alot. This helped me: Specs: Ubuntu 20.04, python 3.8 with a snap-based Chromium installation.
  • Kamil Szuster
    Kamil Szuster almost 3 years
    --remote-debugging-port=9222 helped java 11, ubuntu 20.04 and chromium-browser 91
  • klapshin
    klapshin almost 3 years
    This is almost exactly that worked for me, see my answer here stackoverflow.com/a/67747781/6875391
  • Frankie Drake
    Frankie Drake almost 3 years
    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....
  • Ryan Harris
    Ryan Harris almost 3 years
    This post helped me resolve this issue with a Docker container. Thanks!
  • Osman Tuzcu
    Osman Tuzcu almost 3 years
    You save my life +1
  • Caleb Jay
    Caleb Jay over 2 years
    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.
  • Scout721
    Scout721 over 2 years
    Thank you! This was the bug I was looking for, it's headless not --headless
  • BSQ
    BSQ over 2 years
    Perfect ! Thank you
  • Criminally Inane
    Criminally Inane over 2 years
    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.
  • ItsPrinceAk
    ItsPrinceAk over 2 years
    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.
  • Paul Collingwood
    Paul Collingwood about 2 years
    This also works when using a custom user in a docker image that does not have root
  • Daniel Nelson
    Daniel Nelson about 2 years
    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!
  • jarh1992
    jarh1992 about 2 years
    Thanks a lot, this is helpful also to google colab
  • Digestible1010101
    Digestible1010101 about 2 years
    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?