Forums

Please activate headless Chrome on my account

Hello,

Please activate headless Chrome on my account.

Please check the link below for more information: https://www.pythonanywhere.com/forums/topic/13623/#id_post_68541

Sure! That's done now. You can now install the latest Selenium by running

pip3.7 install --user --upgrade selenium

...adjusting the Python version as necessary, and then you can start a browser in headless mode with Python code like this:

            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument("--headless")
            chrome_options.add_argument("--disable-gpu")
            browser = webdriver.Chrome(options=chrome_options)

...no need to use a virtual display.

It works like a charm!

Thank you for the outstanding customer service (as always!).

Much appreciated!

No problem, always glad to help!

I tried to upgrade selenium on my terminal but when I try to launch a Google driver I get this 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/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.) (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.4.0-1106-aws x86_64)

Am I doing anything wrong?

You just needed the new virtualization system to be activated for your account; I've done that now, and it will be used for any new consoles you start. So if you follow the steps in my previous post then it should all work for you now.

Great! It works perfectly now. Thank you so much for your help.

No problem!

Hi. Please activate headless Chrome on my account.

To do that, we'd need to update your system image first. Updating your system image may break some of your existing code that worked on older versions. You may need to recreate any virtualenvs that you're using and you will need to start new consoles and reload your web apps. You will also need to kill any ipython notebook processes that are running by using the "Fetch processes" button on the Consoles page.

Let us know if you'd like to go ahead with that.

Hi, I'm trying to check if selenium works on my account by running this code:

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options = chrome_options)

But I'm getting:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'options'

Could you please help?

Did you upgrade Selenium as advised here?

Thanks, it started working. Unfortunately, after a couple of minutes I'm getting following error:

Message: invalid session id
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.4.0-1020-aws x86_64)
Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
  (Session info: headless chrome=78.0.3904.70)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.4.0-1020-aws x86_64)

And when I'm trying to catch this exception and reopen chrome I'm getting sth like:

Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.4.0-1020-aws x86_64)

Thing is it works fine on my local machine

It sounds like Chrome is crashing; are you getting emails about it running out of memory?

Nope, I haven't. My daily CPU usage is also OK.

I managed to solve this issue - it appeared that when reaching my quota capacity server was killing Chrome session. And my capacity was consumed by some tmp files that Chrome produces. I simply added some code to clear /tmp in a loop:

        try:
            os.system('rm -rf /tmp*')
        except Exception as e:
            pass

Now everything works fine.

Ah, that would explain it.

Hi, can you check my virtualization system setup? i get the same error as the others above.

You seem to have all of the appropriate bits in place to be able to use it. Could you try running this minimal code to see what happens?

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)

try:
    browser.get("https://www.google.com")
    print("Page title was '{}'".format(browser.title))

finally:
    browser.quit()

Hi, is it possible to run chrome driver without the headless option ? So with the chrome window showing Many thanks for your help

It is possible to run it without the headless option, but you'd need to use a virtual display, and you still would not be able to see it running -- when you run code on PythonAnywhere, it runs on our servers, and they don't have connected graphical displays.

Hi. Please activate headless Chrome on my account.

It is already enabled for your account.

I get this error: OSError: [Errno 8] Exec format error: './chromedriver'

I suspect I might be using wrong version of chromedriver, while it shall match with Chrome version, installed in the system. Which version I shall use for pythonanywhere?

Use the one that is already there. If you place your own copy of chromedriver in the PATH, it is very unlikely to work.

What is the path to existed chromedriver? Apparently it is not in the path

It is on the PATH unless you have changed the path: /usr/local/bin/chromedriver