Reputation: 825
I have an ubuntu server having the UI as well. U can execute the test cases by firing mvn test command. But the problem is when I do ssh of the machine through the terminal from another machine I get the following error-
unknown error: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.4.0-121-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.04 seconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ubuntu-test', ip: 'X.X.X.X', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-121-generic', java.version: '1.8.0_171'
Driver info: driver.version: ChromeDriver
but the same command starts chrome successfully if I take remote of the machine through remmina and then execute the same command of this machines terminal.
Upvotes: 16
Views: 67348
Reputation: 6052
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 this issue. I eventually replaced 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, and that works perfectly.gets my builds
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`
Upvotes: 0
Reputation: 39
I had a similar issue when I was trying to selenium UI test cases in headless mode.
This occurred as I did not have a display server. Starting Xvfb worked for me.
sudo yum -y install Xvfb libXfont Xorg
sudo yum -y groupinstall "X Window System" "Desktop" "Fonts" "General Purpose Desktop"
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:1
Upvotes: 3
Reputation: 1
It happening to me using headless chrome driver and trying to set window size to 1366x768 or 1600x900. I could only fix it by returning to 1920x1080.
Upvotes: 0
Reputation: 2977
For me, the issue was that the /tmp/Crashpad folder was owned by root and could not be written by my user (centos). I did the following and all was ok:
chmod 664 -R /tmp/Crashpad
I manged to debug this by trying to run the google-chrome
binary directly from the terminal as the user I was trying to run selenium with (centos).
Doing that, I got the following error which helped me debug:
[19:11][[email protected] ~]$ /usr/bin/google-chrome --headless
[0110/191116.894836:ERROR:filesystem_posix.cc(63)] mkdir /tmp/Crashpad/new: Permission denied (13)
Upvotes: 0
Reputation: 1
I encountered this when running gitlab-runner. At the main display console, run xhost + to allow remote display access:
xhost +
And in .gitlab-ci.yml, I set the DISPLAY (assuming it's :10.0):
export DISPLAY=:10.0
Upvotes: 0
Reputation: 14328
as @DebanjanB answer is correct, but not clear.
After fixed issue and summary solution to here:
code:
from selenium import webdriver
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument('--headless’)
driver = webdriver.Chrome(options=chromeOptions)
run but error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
direct cause
unknown error: DevToolsActivePort file doesn't exist
means ChromeDriver spawn WebBrowser (Chrome Browser session) failedroot cause
use NORMAL USER to run Chrome
my case: in CentOS
(1) change chrome binary to own by normal user
sudo chown limao:limao /opt/google/chrome/google-chrome
note: here chrome binary is /usr/bin/google-chrome
after several soft link to real one is /opt/google/chrome/google-chrome
after change owner:
limao@localhost:~/dev/ShortLinkParseServer/logs $ ll /usr/bin/google-chrome
lrwxrwxrwx 1 root root 31 Aug 4 16:30 /usr/bin/google-chrome -> /etc/alternatives/google-chrome
limao@localhost:~/dev/ShortLinkParseServer/logs $ ll /etc/alternatives/google-chrome
lrwxrwxrwx 1 root root 29 Aug 4 16:30 /etc/alternatives/google-chrome -> /usr/bin/google-chrome-stable
limao@localhost:~/dev/ShortLinkParseServer/logs $ ll /opt/google/chrome/google-chrome
-rwxr-xr-x 1 limao limao 1.9K Jul 31 04:46 /opt/google/chrome/google-chrome
(2) set normal user for supervisord spawn program
add user=xxx
into your supervisord config file
, like this:
$ cat /etc/supervisord.d/supervisord_ShortLinkParseServer.conf
[program:ShortLinkParseServer]
command=/xxx/gunicorn/gunicorn_config.py app:app
...
; use normal user instead default root use, to avoid later chrome exception: unknown error: DevToolsActivePort file doesn't exist
user=limao
...
add flag --disable-dev-shm-usage
chromeOptions.add_argument('--disable-dev-shm-usage')
too much people used this: add flag --no-sandbox
but --no-sandbox
just means not use sandbox
-> true effect is just bypass OS security model
-> so highly NOT recommend to use --no-sandbox
Upvotes: 3
Reputation: 673
None of the above worked. Only solution was to use the driver from the below location:
'/snap/bin/chromium.chromedriver'
This question explains it: https://stackoverflow.com/a/61980562/1568464
Upvotes: 1
Reputation: 1
I was running it as a GitHub Action, but didn't add options.addArguments("--headless")
. Once I put that in, the fault went away. The various other suggestions in this thread were to no avail.
I know this is my stupidity, but I thought that it could be helpful to come clean about it, because the link between cause and effect in this case was not immediately clear.
Upvotes: 0
Reputation: 185
Try to run selenium-server without sudo
-privileges:
java -jar path/to/selenium-server-standalone.jar
Upvotes: 2
Reputation: 1807
Try this method to instantiate chrome web driver could help you to overcome this issue in ubuntu :
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
opt = Options()
opt.add_argument("--no-sandbox")
opt.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(chrome_options=opt,
executable_path='<your-chromedriver-path>')
driver.get('https://www.google.com/')
Thanks to @George Pantazes for his comment for the answer
And make sure the env variable DISPLAY
has been set to existing session in the terminal where you'll start the chrome browser.
Upvotes: 0
Reputation: 193078
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...
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 Java solution:
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
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("--no-sandbox"); // Bypass OS security model
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
As per base_switches.cc disable-dev-shm-usage
seems to be valid only on Linix 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.
You can find a couple of detailed discussions in:
Here is the link to the Sandbox story.
Upvotes: 13
Reputation: 161
I had been receiving this error specifically in chrome embedded applications with Selenium, like CEF or electron apps.
Using the arguments --headless and --no-sandbox and --disable-gpu was not a solution.
The cause of my issue was the electron and CEF applications. They were not forwarding all the chrome command line switches onto the running Chrome instance inside them and as a result the DevToolActivePort file was not being created.
I have published a manual process to follow in my answer to another similar question here -> https://stackoverflow.com/a/62545820/8708890. You can follow this manual process and see if it fixes your issue.
Upvotes: 1
Reputation: 7528
If you run from ssh without an X-forward your chrome browser will crash. To prevent that you can use the options DebanjanB posted, the most important being --headless. If running as root ( not recommended ) you need --no-sandbox as well.
I also had this error when I used al older version of selenium-java (3.5.3) with the newer chromedriver (75.x). It worked for me to use the 2.46 version of the chromedriver with the 3.5.3, or the 75.x with 3.141.59 of selenium java.
Running a local Xvfb should work too, but I suggest to use headless, it can be much faster.
Check the suggested duplicate post too and please update and mark as solved whatever helped you.
Upvotes: 1
Reputation: 31
I faced the same problem when I run selenium with cron job. And after long suffering I found the way to solve it. Just add this line to the beginning of the shell script:
export DISPLAY=:1
Upvotes: 1
Reputation: 819
Simply use headless mode
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
driver = new ChromeDriver(options);
Upvotes: -1
Reputation: 5099
I use this configuration using python
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("no-sandbox")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--headless")
driver = os.path.join("path/of/driver","chromedriver")
browser = webdriver.Chrome(executable_path=driver,chrome_options=chrome_options)
browser.get("https://www.example.com")
print(browser.title)
Upvotes: 3