Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevToolsActivePort file doesn't exist. #46

Open
eduardostalinho opened this issue Jun 8, 2018 · 50 comments
Open

DevToolsActivePort file doesn't exist. #46

eduardostalinho opened this issue Jun 8, 2018 · 50 comments

Comments

@eduardostalinho
Copy link

eduardostalinho commented Jun 8, 2018

I`m trying to run selenium with chromedriver (with python) on heroku and I'm getting this error:

Traceback (most recent call last):
...
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
    self.error_handler.check_response(response)
  File "/app/.heroku/python/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.4.0-1019-aws x86_64)

I added the builpack for chromedriver (https://github.com/heroku/heroku-buildpack-chromedriver) and added the following config keys:

GOOGLE_CHROME_BIN:        /app/.apt/usr/bin/google-chrome
CHROMEDRIVER_PATH:        /app/.chromedriver/bin/chromedriver

I've tried locally and in heroku (with a builpack fork) without the --remote-debugging option=9222. It worked locally, but it didn't work on heroku.
Can I get some help here?

@vinodhkps
Copy link

vinodhkps commented Jun 13, 2018

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

@CalebRouleau
Copy link

I wrote that error message. It means that ChromeDriver isn't finding the port it needs to talk to Chrome over. That could happen because Chrome crashed or failed to start or because you were using an old version of Chrome. ChromeDriver 2.40 only supports Chrome versions 66.x.x.x to 68.x.x.x.

It's also possible that it is failing because you are setting the "remote-debugging-port" argument. Could you try removing that argument?

See related bug https://bugs.chromium.org/p/chromedriver/issues/detail?id=2470&can=2&start=0&num=100&q=&colspec=ID%20Status%20Pri%20Owner%20Summary&groupby=&sort=&hotlist_id=

@christophlsa
Copy link

We are not using heroku but had the same issue. The advice from @vinodhkps helped. We already used "--headless" but after adding the other arguments it didn't fail anymore.

@laverick
Copy link

We had this same issue even though we had all the necessary arguments for running Chrome. It was working and then suddenly it stopped working.

Turns out that we were still on the Cedar-14 stack and upgrading to the Heroku-16 stack fixed the problem.

It looks like the chrome and chromedriver buildpacks track the stable version of their respective softwares. I'm guessing a version bump on Google's side may have broken chrome on Cedar-14.

I've raised the following issue as a way to have more control over versioning: #48

@Shinoby1992
Copy link

have a docker image that opens chrome via python-> selenium -> chromedriver as soon i run 51 docker containers through my vpn container i get

Message: unknown error: DevToolsActivePort file doesn't exist,
  (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.9.93-linuxkit-aufs x86_64)

How to Solve this issue, and why does this error accour?

@danny408
Copy link

I also have this issue running on Chromedriver 2.40, Google Chrome 67, Ubuntu 16.04 w/ selenium python
have those 3 arguments, sandbox , headless and shm on and it crashes with this port error after a while

@CalebRouleau
Copy link

Hi everyone!

This error usually means that the Chrome binary that you passed in failed to start. If you can get a chromedriver.log file (instructions: http://chromedriver.chromium.org/logging ) and find where it prints "Launching Chrome" or something like that, then you can take that commandline and paste it into this bug. You can also try running that commandline locally and see if it successfully starts Chrome.

@anuraktinigam
Copy link

anuraktinigam commented Jul 26, 2018

Ran my script after enabling logs. Below are my logs. @CalebRouleau

[1532599807.795][INFO]: Launching chrome: /var/tmp/qa_automation/chromedriver --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-extensions-except=/tmp/.org.chromium.Chromium.6muhD4/internal --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors --log-level=0 --metrics-recording-only --no-first-run --no-sandbox --password-store=basic --remote-debugging-port=0 --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.VkT4E5 data:,
[1532599867.819][INFO]: RESPONSE InitSession unknown error: DevToolsActivePort file doesn't exist

@sng94
Copy link

sng94 commented Jul 30, 2018

Hello everyone. I'm also having the same issue on the Selenium Grid Chrome node container I've made using Docker. The containers I've made both for the node and the hub use windowsservercore as its base image. Here's the Dockerfile contents for both of them if you want to take a look:

Windows Selenium Hub: https://hub.docker.com/r/nehirgokce/windows-selenium-hub/
Dockerfile:

FROM microsoft/windowsservercore

RUN powershell (new-object System.Net.WebClient).Downloadfile('http://javadl.oracle.com/webapps/download/AutoDL?BundleId=234443_96a7b8442fe848ef90c96a2fad6ed6d1', 'C:\JavaSetup8u181.exe')
RUN powershell start-process -filepath C:\JavaSetup8u181.exe -passthru -wait -argumentlist "/s,INSTALLDIR=c:\Java\jre1.8.0_181,/L,install64.log"
RUN del C:\JavaSetup8u181.exe
RUN powershell (new-object System.Net.WebClient).Downloadfile('https://goo.gl/4g538W', 'C:\selenium-server-standalone-3.13.0.jar')
RUN powershell SetX /M PATH "\"C:\Java\jre1.8.0_181\bin;$env:PATH""
RUN powershell SetX /M JAVA_HOME "\"C:\Java\jre1.8.0_181""
CMD java -jar selenium-server-standalone-3.13.0.jar -role hub

Windows Selenium Chrome Node
Dockerfile:

FROM microsoft/windowsservercore

RUN powershell (new-object System.Net.WebClient).Downloadfile('http://javadl.oracle.com/webapps/download/AutoDL?BundleId=234443_96a7b8442fe848ef90c96a2fad6ed6d1', 'C:\JavaSetup8u181.exe')
RUN powershell start-process -filepath C:\JavaSetup8u181.exe -passthru -wait -argumentlist "/s,INSTALLDIR=c:\Java\jre1.8.0_181,/L,install64.log"
RUN powershell SetX /M PATH "\"C:\Java\jre1.8.0_181\bin;$env:PATH""
RUN powershell SetX /M JAVA_HOME "\"C:\Java\jre1.8.0_181""
RUN del C:\JavaSetup8u181.exe
ADD https://www.7-zip.org/a/7z1805-x64.exe \7z1805-x64.exe
RUN powershell Start-Process -Wait -FilePath '\7z1805-x64.exe' -ArgumentList '/S'
RUN powershell SetX /M PATH "\"C:\Program Files\7-zip;$env:PATH""
RUN powershell Remove-Item -Force /7z1805-x64.exe
RUN powershell (new-object System.Net.WebClient).Downloadfile('https://chromedriver.storage.googleapis.com/2.41/chromedriver_win32.zip','C:\chromedriver_win32.zip')
RUN powershell (new-object System.Net.WebClient).Downloadfile('https://goo.gl/4g538W', 'C:\selenium-server-standalone-3.13.0.jar')
RUN 7z.exe e chromedriver_win32.zip
RUN powershell SetX /M PATH "\"C:;$env:PATH""
RUN powershell SetX /M PATH "\"C:\chromedriver.exe;$env:PATH""
RUN powershell (new-object System.Net.WebClient).Downloadfile('https://dl.google.com/chrome/install/latest/chrome_installer.exe', 'C:\ChromeSetup.exe')
RUN powershell . C:\ChromeSetup.exe /silent /install
CMD java -Dwebdriver.chrome.driver=C:/chromedriver.exe -jar C:/selenium-server-standalone-3.13.0.jar -port 5556 -role node -hub 'registrationIPFromTheHub' -browser "browserName=chrome, version=ANY, maxInstances=10, platform=WINDOWS"

Finally, here's the error message I receive

org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)

The chrome version installed on my node container is v68. Also, I've already tried adding the following arguements onto my chrome options:
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

@TheoSeo93
Copy link

Same thing happens to me. For the first several scheduled tasks work, but after a few hours it fails with the same message.

@DimitryRd
Copy link

@nehirgokce Have you found out what was the problem?

@sng94
Copy link

sng94 commented Aug 12, 2018

@DimitryRd Apparently, the windowsservercore image does not support GUI applications, Google Chrome included. --headless option does not seem to work as well, eventhough GUI support is the problem. So the team I'm working with provided a VM for me in order to build and create the chrome nodes. The automation within the browser/s (based on your max session preference) is also run in this VM.

@Shinoby1992
Copy link

Shinoby1992 commented Aug 12, 2018

My problem was that using fakedisplay pyvirtualdisplay xfvc has a maximum client, if the maximum client is achieved it won't create any chrome instances anymore, so this error gets thrown. So this error gets not only thrown like the exception explains that a port was not possible to find, it also get thrown if it can't create a instance session because of displaying issues in any way

@benfr1
Copy link

benfr1 commented Aug 14, 2018

chrome_options.add_argument('--headless') option alone (see above) seems to fix the issue in chrome68/chromedriver 2.41 pair on a ubuntu without gui.

@mugbya
Copy link

mugbya commented Aug 29, 2018

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

browser = webdriver.Chrome(chrome_options=chrome_options)

@ryangurazov
Copy link

@mugbya's solution worked for Centos 7 64-bit
Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),
platform=Linux 3.10.0-514.6.1.el7.x86_64 x86_64

sue445 added a commit to sue445/app-stat-api that referenced this issue Sep 23, 2018
sue445 added a commit to sue445/app-stat-api that referenced this issue Sep 23, 2018
@drdataflow
Copy link

Doesn't work for me
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.4.0-1027-aws x86_64)

@YurieCo
Copy link

YurieCo commented Oct 20, 2018

I used


from selenium import webdriver
import os 
options = webdriver.ChromeOptions()
CHROMEDRIVER_PATH = '/app/.chromedriver/bin/chromedriver'
GOOGLE_CHROME_SHIM = os.getenv('GOOGLE_CHROME_SHIM',"chromedriver")

options.binary_location = '/app/.apt/usr/bin/google-chrome-stable'
options.add_argument("start-maximized")
options.add_argument('--disable-gpu')
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
browser = webdriver.Chrome( options=options)

and it worked, I havent used option for driver and before run above code better to add to requirements.txt
chromedriver_installer

@alex4200
Copy link

I have the same issue and I created 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.")

@levinsamuel
Copy link

Throwing my 2 cents in: I tried most of the suggestions here, none of them worked. What worked was changing from Chromium to Chrome. Both are version 70, with chromedriver 2.44. I got this same error, "DevToolsActivePort file doesn't exist", as well as something like "Failed to connect to chrome" in my debug log (sorry, accidentally wiped my log file after it worked.)

@Luckyfive
Copy link

Luckyfive commented Nov 29, 2018

@eduardostalinho have you tried deleting the GOOGLE_CHROME_BIN heroku variable since the google chrome heroku buildpack already creates one? I just fixed this same issue with a Selenium python app I am deploying to heroku

reference: https://github.com/heroku/heroku-buildpack-google-chrome#selenium

yongjinjiang pushed a commit to yongjinjiang/WebScraping_MissionToMars that referenced this issue Dec 30, 2018
…olved my 'Chrome cannot launch on Heroku' problem
@xywang68
Copy link

I faced a similar issue while running my automation test inside a docker container. Addition information in my situation is:
while running the docker container in interactive mode with a bash command sequence, the test passed as expected;
while running the docker container in detached mode with the exact same bash command sequence, the test failed with this "DevToolsActivePort file doesn't exist" error.
I have narrowed down to this point, by adding "--no-sandbox", in detached mode the test also passed as expected.

@benfr1
Copy link

benfr1 commented Jan 1, 2019

I faced a similar issue while running my automation test inside a docker container. Addition information in my situation is:
while running the docker container in interactive mode with a bash command sequence, the test passed as expected;
while running the docker container in detached mode with the exact same bash command sequence, the test failed with this "DevToolsActivePort file doesn't exist" error.
I have narrowed down to this point, by adding "--no-sandbox", in detached mode the test also passed as expected.

interesting documentation, xywang68, thank you.

@benfr1
Copy link

benfr1 commented Jan 1, 2019

it is now in version 2.4* with chrome 70 that from a ubuntu on which a gui interface has ben installed (gnome):

  • such error is still displayed
  • it does not prevent test execution
  • it does not prevent screen capture
  • so for me this error is a goner now.

@tinchysvenom
Copy link

when deploying your code to heroku did you still have to use the pyvirtualdisplay library or any similar ones to create a virtual display for the code or where they any other implementations you used to pass that area

@tobyweston
Copy link

tobyweston commented Jan 7, 2019

Ran my script after enabling logs. Below are my logs. @CalebRouleau

[1532599807.795][INFO]: Launching chrome: /var/tmp/qa_automation/chromedriver --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-extensions-except=/tmp/.org.chromium.Chromium.6muhD4/internal --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors --log-level=0 --metrics-recording-only --no-first-run --no-sandbox --password-store=basic --remote-debugging-port=0 --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.VkT4E5 data:,
[1532599867.819][INFO]: RESPONSE InitSession unknown error: DevToolsActivePort file doesn't exist

I'm having similar issues and my verbose log includes the following

[1546857022.900][INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" \
--disable-background-networking --disable-client-side-phishing-detection \
--disable-default-apps --disable-extensions --disable-extensions-except="C:\dev\programs\BuildAgent\\
temp\buildTmp\scoped_dir23312_26017\internal" --disable-gpu \
--disable-hang-monitor --disable-plugins --disable-popup-blocking --disable-prompt-on-repost \
--disable-sync --disable-web-resources --enable-automation --enable-logging \
--force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors \
--log-level=0 --metrics-recording-only --no-first-run --password-store=basic \
--remote-debugging-port=0 --test-type --use-mock-keychain \
--user-data-dir="C:\dev\programs\BuildAgent\temp\buildTmp\scoped_dir23312_26653" \
--window-size=1600,1080 data:,
[[1546857082.960][INFO]: Failed to connect to Chrome. Attempting to kill it.
[1546857083.001][INFO]: [9660d4d07fc559cdc8e82035fd5f352b] RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist

Running Windows, ChromeDriver 2.45, Chrome 70.x and selenium-server 3.14.0. 😭

@sliwinski-milosz
Copy link

On MacOS I noticed that I get this error when I try to run selenium when the browser is already opened.

Two ways of fixing that :

  1. Either make sure that your browser is closed before starting selenium.
  2. Or use chrome_options.add_argument('--headless')

@eespitiarea
Copy link

@sliwinski-milosz, Selenium already added contextmanager support to webdriver, a good way to avoid lingering instances eating out your memory is to use it, like so:

# Options and settings needed here
with webdriver.Chome() as driver:
    pass# Rest of your code

And in the case you're trying to speed up your tests with parallelization, go for a grid instead of standalone (or local), a really nice tutorial about all of these: https://github.com/SeleniumHQ/docker-selenium.

@saltypatrick
Copy link

Ran it as root in my case and the issue was that my terminal session was root and executing as root, but the desktop session was for my own non sudo user.

I ran it as my own server user nonroot and it worked just fine.
I noticed the same behavior in a containerized environment.
TLDR/simple answer for now: do not run chrome as root. In any environment you really shouldn't be doing this anyways, and I'd go as far as chrome does not support it (chrome or chromium binaries) as both issue out warnings.

@learncodetest
Copy link

I get the same issue when trying to run my {selenium, testng & java) scripts in Linux machine (It works without any issue in Windows machine).

Exception
14:33:40 org.openqa.selenium.WebDriverException:
14:33:40 unknown error: Chrome failed to start: exited abnormally
14:33:40 (unknown error: DevToolsActivePort file doesn't exist)
14:33:40 (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

I was able to get pass through it by adding "headless" option to the Chrome driver. But, wondering if there is any other way to resolve it without adding "headless" option

Workaround
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
driver = new ChromeDriver(options);

@eespitiarea
Copy link

eespitiarea commented May 6, 2019

@learncodetest I think this is the same issue that @saltypatrick commented before, being root while running the tests, if you don't start a new process for the rendering (xvfb, GTK or anyother you might be using for display) you'll be just fine (like the headless option you're currently doing).

There are several ways to address that problem, one is to create a non-root user and test with it (which I personally consider the best option since you're running in a limited and controlled environment), other is to add the executing process (python for example) to wheel group, another is to start the rendering/display process with root, which can be done using the --privileged option for docker (I personally discourage this, I considered it to be risky).

@ledinhtri97
Copy link

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

thank you

@meyer59
Copy link

meyer59 commented May 28, 2019

Hi
For my part, running on debian , i had to install google-chrome (yes the browser) to fix this issue. All previous solutions didn't work for me

@ryenski
Copy link

ryenski commented Jun 13, 2019

I am having this problem with heroku-18 using webdrivers.

The shim seems like it is adding the required arguments:

irb(main):001:0> chrome_shim = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
=> "/app/.apt/usr/bin/google-chrome-stable"
irb(main):002:0> chrome_bin = ENV.fetch('GOOGLE_CHROME_BIN', nil)
=> "/app/.apt/opt/google/chrome/chrome"
irb(main):003:0>
~ $ cat /app/.apt/usr/bin/google-chrome-stable
#!/usr/bin/env bash
exec $HOME/.apt/opt/google/chrome/chrome --headless --no-sandbox --disable-gpu --remote-debugging-port=9222 $@
~ $

Here's what our setup looks like:

require 'webdrivers'

chrome_shim = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
chrome_bin = ENV.fetch('GOOGLE_CHROME_BIN', nil)

Selenium::WebDriver::Chrome.path = chrome_bin if chrome_bin

chrome_args = { args: %w[window-size=1280,1024] }
selenium_options = Selenium::WebDriver::Chrome::Options.new(chrome_args)
selenium_options.binary = chrome_shim if chrome_shim

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome, options: selenium_options
  )
end

Capybara.javascript_driver = :chrome

We did have to specify the Chrome.path separately from the chrome_shim options because of how the --version flag returns. titusfortner/webdrivers#134

Still, when running my tests, we're seeing DevToolsActivePort file doesn't exist:

Run options: --seed 48777
# Running:
E
Error:
Admin::NewDonationTest#test_0003_creating a manual donation with a negative amount:
Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /app/.apt/opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    test/system/admin/donations/new_test.rb:112:in `block in <class:NewDonationTest>'

@eric-burel
Copy link

eric-burel commented Jul 22, 2019

Hi, facing this issue and @eespitiarea solution did work for me, using --remote-debugging-port=9222. I did not need any other argument (headless etc.), with the code here.

Edit: why 9222 though? where is this documented?

@eespitiarea
Copy link

Can be any port actually, as long as you specify this while launching the binary, 9222 is the default. Found it digging Chromedriver's project: https://chromedevtools.github.io/devtools-protocol.

@as3379
Copy link

as3379 commented Sep 25, 2019

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

Facing the sample issue @

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

@vinodhkps I'm facing the same issue. I have a project running in docker container where ;

driver = webdriver.Chrome(executable_path=root + '/drivers/chromedriver', options=options)
when i run this, following error is displayed - selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

So how to and what to set as executable PATH

@vinodhkps
Copy link

@as3379 - sorry for the delayed response, I had chrome driver installed in this location -
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ and this is the PATH. Eg. from that test docker file I had back then

# Install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

@Tian-YS
Copy link

Tian-YS commented Mar 1, 2020

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

it works for me,but '--headless' means chrome will not open, dose have any way to solve it

@KrishnaKamakshi
Copy link

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`thanks for sharing this for dockers . Could you please help me on fixing similar kind of issue in azure. Tested the same but it Is not working

bluurr added a commit to bluurr/quora-loader that referenced this issue Mar 3, 2021
bluurr added a commit to bluurr/quora-loader that referenced this issue Mar 4, 2021
* Init for API project for fetching data from Quora.

* Added project scoped maven build tools.

* Refactoring of infinite scroller to be more efficient, added limit support to the API interface,

* Refactored driver to a factory component.

* Refactored small cleanup of data classes and removed extra spacing.

* Added happy path test for service. Extracted cache setup to Spring configuration stage.

* Added support for handling multiple requests concurrently (using blocking queue implementation).

* Added configuration support for web driver and minor renames and documentation.

* Refactor to the client pool to simplify the consumer interface.

* Added first pass of testing service layer.

* Refactor to align domain and model package layout, included openapi UI within API.

* Added configuration to tune headless mode.

* Added contact email configuration as required by Quora TOS.

* Added client shutdown support and base test to verify the API is returning a response.

* Updated readme and added heroku deployment properties.

* Added spring configuration to produce a fat jar for deployment.

* Added web deployment configuration for Heroku.

* Added additional chrome driver options to prevent crashes when running inside a dymo/container.

* Added additional chrome driver options for binary location override as documented in chrome build pack.

* Removed disable sim command as buildpack should take care of this now.

* Workaround for chrome issue in Heroku using extra build config until fix applied for - heroku/heroku-buildpack-google-chrome#46

* Added tests to verify API endpoint. Renamed loader artifact to follow standard maven conventions.

* Added heroku app.json for quick deployment.

* Refactored client library as a new component & updated readme with details of the different sub components.

* Minor tweak to readme to update Functions text.

* Minor tweak to readme to update testing text case.

* Updated to 1.8.0 application version.
@lordsherman
Copy link

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

I have had these arguments specified in my script for a while without issue. Needed to update Chrome Driver to version 93 recently as the script decided to stop working. This is when I started encountering this error. As others have mentioned adding in the following argument completely fixed my issue.

chrome_options.add_argument('--remote-debugging-port=9222')

@Open-AGI
Copy link

Don't think it's has a heroku issue. Had a similar issue with docker container as well. Here is my fix that worked in docker -

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

`

thanks, am run it stop in driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)

i delete

# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-dev-shm-usage')

its working

@david-mears-2
Copy link

For me, the problem that was causing this error was that Selenium was not picking up the Chrome that had been installed by heroku-buildpack-google-chrome, and so it installed a new copy (which wasn't adapted to work on Heroku). The instructions given at https://github.com/heroku/heroku-buildpack-google-chrome#selenium therefore were not having the desired effect. I think this may be to do with recent changes to the selenium-webdriver Ruby gem (I updated to 4.12 because of titusfortner/webdrivers#247). Selenium logs:

2023-09-19 19:25:42 DEBUG Selenium [:selenium_manager] chrome not found in PATH
2023-09-19 19:25:42 DEBUG Selenium [:selenium_manager] chrome not found in the system
2023-09-19 19:25:42 DEBUG Selenium [:selenium_manager] Discovering versions from https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json
2023-09-19 19:25:42 DEBUG Selenium [:selenium_manager] Required browser: chrome 117.0.5938.88
2023-09-19 19:25:42 DEBUG Selenium [:selenium_manager] Downloading chrome 117.0.5938.88 from https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/117.0.5938.88/linux64/chrome-linux64.zip
2023-09-19 19:25:42 DEBUG Selenium [:selenium_manager] chrome 117.0.5938.88 has been downloaded at /app/.cache/selenium/chrome/linux64/117.0.5938.88/chrome

I eventually discovered I could force Selenium to pick up the correct Chrome by passing in the SHIM environment variable as the binary option on Selenium::WebDriver::Chrome::Options.new:

chrome_shim = ENV.fetch('GOOGLE_CHROME_SHIM', nil)

Capybara.register_driver :chrome_headless do |app|
  options = if ENV['GOOGLE_CHROME_SHIM'].present?
              ::Selenium::WebDriver::Chrome::Options.new(binary: chrome_shim)
            else
              ::Selenium::WebDriver::Chrome::Options.new
            end
  options.add_argument('--headless')
  options.add_argument('--window-size=1920,1080')

  Capybara::Selenium::Driver.new(app, browser: :chrome, options:)
end

Capybara.default_driver = :chrome_headless
Capybara.javascript_driver = :chrome_headless

I've submitted a PR that updates the README Selenium example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests