WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
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
- I have killed all the chrome processes and chrome driver processes.
-
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:
- 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.
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)
Related videos on Youtube
Kumar Sampath
Updated on September 17, 2021Comments
-
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 over 5 yearsI received this error when vncserver crashed and I had no X display anymore
-
bers about 2 yearsFor a fix for running without an X display, use
export DISPLAY=:0
, see stackoverflow.com/questions/50790733/…
-
Pete Kelley almost 6 yearsI 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 almost 6 yearsBut what caused this specific error about
DevToolsActivePort file doesn't exist
, and why did it suddenly start popping up? -
Mario Pérez Alarcón almost 6 yearsThese options stopped the error for me too. pd: using a Rails stack.
-
Pete Kelley almost 6 yearsThe "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 almost 6 yearsFrom Review: Please don't post text in images. EDIT your answer and replace those images with text. Thanks
-
Bendram over 5 yearsDoes this solve the problem for anyone? This didn't solve the problem for me
-
axel_ande over 5 yearsI solved my problem with upgrade chrome (I already had the latest chromedrive), hence I had to upgrade the usual browser as well.
-
Jonathan over 5 yearsI still get
[java] [1536892035.965][SEVERE]: Timed out receiving message from renderer: 60.000
errors even with this -
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 over 5 yearsFrom 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 over 5 yearsthis solved my issue, when running using C# (in this case the option looked like this: options.AddArgument("--headless");
-
jeremycg over 5 yearsI 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 over 5 yearsseems the exact opposite of @shiuu fix below
-
Toby over 5 yearsseems the exact opposite of @sergiy-konoplyaniy fix above :'(
-
Toby over 5 yearsDo 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 over 5 yearsIn our setBinary, we tried to set chrome driver, which seems a mistake. @sergiy-konoplyaniy's fix sets chrome.exe via setBinary.
-
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 about 5 yearsThis used to solve the issue for me, it doesn't on my current system (Ubuntu 18 + Python 3.7)
-
AEngineer almost 5 yearsUsing 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 almost 5 yearsWhere do we add this code? I see no C# code in my .side file
-
pabrams almost 5 yearsWhere did you have this code? All I have is a .side file, and it has no C# code in it.
-
Nital almost 5 yearsInteresting ! How do you generate a .side file ? Is this something that a QA person does manually ?
-
pabrams almost 5 yearsYou 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 over 4 yearsIn 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 over 4 yearsOMG 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 over 4 yearsIf 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 over 4 years@GeorgePantazes, your statement is absolutely true.
-
Alpha over 4 yearsUnfortunately, @GeorgePantazes's solution did not help me.
-
Mike Shiyan about 4 yearsIs it a constant port? Or where can I look for it?
-
patroqueeet about 4 yearssame for me with docker with ubuntu 18.04, py3.7, chrome(driver) 80
-
Ryan Harris about 4 yearsThis 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 about 4 yearsI was hit by this inside docker because I didn't have
--headless
. -
Jacob Brazeal about 4 yearshas to be first option -- spend days to find this haha
-
Admin almost 4 yearsNon-root user worked for me, I had the correct chrome driver version for the chromium.
-
lucaswxp almost 4 yearsXVFB was the issue for me
-
Codev over 3 yearsOn ubuntu 18 and jenkins it worked like that. In my case the 'headless' argument as the important argument missing..
-
Tyler Gallenbeck over 3 yearsWhat was the issue with XVFB. Can you please explain.
-
CPak over 3 yearsCould you describe how you used
goog:chromeOptions
a little more? Right now I'm usingchrome_options = webdriver.ChromeOptions()
andchrome_options.add_argument(...)
-
Eric Dauenhauer over 3 yearsUnfortunately 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. over 3 yearsI additionally required
--remote-debugging-port=9222
to get it to work on Fedora 33 -
Scott P. over 3 yearsremote-debugging-port=9222 after no-sandbox and disable-dev-shm-usage works for me on Fedora 33
-
Pramod Yadav over 3 yearsadding options.addArguments("--no-sandbox"); did the trick for me. Thanks for sharing!
-
horaceT over 3 yearsWorks for me. python 3.7.3, ubuntu 20.04, chrome 87.0.4280
-
dnwjn about 3 yearsThis 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 about 3 years@user9315861
DevToolsActivePort file doesn't exist
the error comes from chromedriver, we can run chromedriver whis options aschromedriver --verbose
then log level will come into detail -
bhattraideb about 3 yearsI am getting this error
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
Anyone got the solution for this issue? -
Trook2007 almost 3 yearsusing xvfb-run is an option as well.
-
hatze almost 3 yearsThx alot. This helped me: Specs: Ubuntu 20.04, python 3.8 with a snap-based Chromium installation.
-
Kamil Szuster almost 3 years--remote-debugging-port=9222 helped java 11, ubuntu 20.04 and chromium-browser 91
-
klapshin almost 3 yearsThis is almost exactly that worked for me, see my answer here stackoverflow.com/a/67747781/6875391
-
Frankie Drake almost 3 yearsHahahaha, 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 almost 3 yearsThis post helped me resolve this issue with a Docker container. Thanks!
-
Osman Tuzcu almost 3 yearsYou save my life +1
-
Caleb Jay over 2 yearsthis 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 over 2 yearsThank you! This was the bug I was looking for, it's
headless
not--headless
-
BSQ over 2 yearsPerfect ! Thank you
-
Criminally Inane over 2 yearsThat 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 over 2 yearsDoes 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 about 2 yearsThis also works when using a custom user in a docker image that does not have root
-
Daniel Nelson about 2 yearsAs 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 about 2 yearsThanks a lot, this is helpful also to google colab
-
Digestible1010101 about 2 yearsVery 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?