heroku-buildpack-google-chrome icon indicating copy to clipboard operation
heroku-buildpack-google-chrome copied to clipboard

DevToolsActivePort file doesn't exist.

Open eduardostalinho opened this issue 6 years ago • 50 comments

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?

eduardostalinho avatar Jun 08 '18 16:06 eduardostalinho

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 avatar Jun 13 '18 01:06 vinodhkps

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=

CalebRouleau avatar Jun 18 '18 18:06 CalebRouleau

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.

christophlsa avatar Jun 20 '18 07:06 christophlsa

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: https://github.com/heroku/heroku-buildpack-google-chrome/issues/48

laverick avatar Jun 26 '18 13:06 laverick

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?

Shinoby1992 avatar Jul 01 '18 19:07 Shinoby1992

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

danny408 avatar Jul 17 '18 03:07 danny408

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.

CalebRouleau avatar Jul 18 '18 00:07 CalebRouleau

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

anuraktinigam avatar Jul 26 '18 10:07 anuraktinigam

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

sng94 avatar Jul 30 '18 11:07 sng94

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

TheoSeo93 avatar Jul 30 '18 19:07 TheoSeo93

@NehirGokce Have you found out what was the problem?

DimitryRd avatar Aug 07 '18 13:08 DimitryRd

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

sng94 avatar Aug 12 '18 14:08 sng94

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

Shinoby1992 avatar Aug 12 '18 15:08 Shinoby1992

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.

benfr1 avatar Aug 14 '18 12:08 benfr1

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)

mugbya avatar Aug 29 '18 05:08 mugbya

@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

ryangurazov avatar Sep 13 '18 23:09 ryangurazov

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

drdataflow avatar Sep 26 '18 23:09 drdataflow

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

YurieCo avatar Oct 20 '18 18:10 YurieCo

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

alex4200 avatar Oct 30 '18 08:10 alex4200

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

levinsamuel avatar Nov 28 '18 02:11 levinsamuel

@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

Luckyfive avatar Nov 29 '18 23:11 Luckyfive

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.

xywang68 avatar Dec 31 '18 22:12 xywang68

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 avatar Jan 01 '19 15:01 benfr1

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.

benfr1 avatar Jan 01 '19 15:01 benfr1

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

tinchysvenom avatar Jan 03 '19 11:01 tinchysvenom

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. :sob:

tobyweston avatar Jan 07 '19 13:01 tobyweston

Maybe the chrome process that you are starting doesn't have permission to write to C:\dev\programs\BuildAgent\temp\buildTmp\scoped_dir23312_26653

you can check the permissions on that folder.

Otherwise you can start chrome yourself using that command

[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:,

in a terminal and make sure that the Chrome browser pops up and the C:\dev\programs\BuildAgent\temp\buildTmp\scoped_dir23312_26653 directory has a DevToolsActivePort file in it.

CalebRouleau avatar Jan 07 '19 21:01 CalebRouleau

Thanks @CalebRouleau I'd completely missed the reference to the folder. I seem to have mixed results here. As I run my test suite and multiple instances of chrome come and go, the DevToolsActivePort file comes and goes, as do the dynamic scoped_dirXXXX folders. So I'm not sure what to read into that. I imagine its as expected but doesn't help me diagnose.

What I can confirm is that the permissions are all set correctly. I suspect a crash somewhere and StackOverflow is full of suggestions to set --no-sandbox (amongst other things). None of which fix it for me.

Apologies all, this is probably OT at this point...

tobyweston avatar Jan 08 '19 20:01 tobyweston

Does this give any more insight? Running from my windows box terminal...

C:\code>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-
default-apps --disable-extensions --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-ru
n --no-sandbox --password-store=basic --remote-debugging-port=0 --test-type=browser --use-mock-keychain --user-data-dir=_chromedriver --window-size=1600,1080

C:\code>[0112/163302.612:ERROR:gpu_process_transport_factory.cc(980)] Lost UI shared context.

DevTools listening on ws://127.0.0.1:58954/devtools/browser/ab9c4cee-1fd4-46c5-b7f7-eee295cbd3e4
[0112/163302.613:ERROR:cache_util_win.cc(19)] Unable to move the cache: 3
[0112/163302.613:ERROR:cache_util.cc(140)] Unable to move cache folder _chromedriver\Default\GPUCache to _chromedriver\Default\old_GPUCache_000
[0112/163302.613:ERROR:disk_cache.cc(168)] Unable to create cache
[0112/163302.613:ERROR:devtools_http_handler.cc(288)] Error writing DevTools active port to file
[0112/163302.613:ERROR:shader_disk_cache.cc(620)] Shader Cache Creation failed: -2

https://chromium.googlesource.com/chromium/src/+/master/net/disk_cache/cache_util_win.cc#19

tobyweston avatar Jan 12 '19 16:01 tobyweston

The key error is [0112/163302.613:ERROR:devtools_http_handler.cc(288)] Error writing DevTools active port to file

The issue is that it cannot add a file to the directory "_chromedriver" from the argument: "--user-data-dir=_chromedriver"

Could you pass a fully qualified path to a writable directory instead of just passing "_chromedriver"?

CalebRouleau avatar Jan 15 '19 22:01 CalebRouleau