[snap] chromedriver doesn't work without --headless under Wayland

Bug #1874415 reported by Marius Gedminas
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
chromium-browser (Ubuntu)
Fix Released
Low
Unassigned

Bug Description

Since I upgraded my Ubuntu 19.04 laptop to Ubuntu 19.10 I've been unable to run Robot Framework tests using SeleniumLibrary with Chrome. I keep getting errors from chromedriver:

Parent suite setup failed:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /snap/chromium/current/command-chromium.wrapper is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Things work somewhat better when I ask chromium to run in headless mode, although I still get weird failures partway through the test suite (I think on the first test that uses Select Window): TimeoutException: Message: timeout: Timed out receiving message from renderer: 300.000.

It would be easier to debug this if I could _see_ what the browser is doing, which brings us back to the original problem: non-headless chromium doesn't work in 19.10.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in chromium-browser (Ubuntu):
status: New → Confirmed
Revision history for this message
Olivier Tilloy (osomon) wrote :

I am able to successfully run the chromium snap's (admittedly very basic) tests without headless mode. The tests are at https://git.launchpad.net/~chromium-team/chromium-browser/+git/snap-from-source/tree/tests?h=stable.

Marius, could you maybe share a minimal reproducer that fails, so I can investigate further?

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Here's my minimal example:

#!/usr/bin/env python3
import time
import sys
from selenium import webdriver

options = webdriver.chrome.options.Options()
if '--headless' in sys.argv:
    options.add_argument("headless")
driver = webdriver.Chrome(options=options)
driver.get("https://ubuntu.com")
time.sleep(1)
print(driver.current_url)
driver.quit()

I can run python3 ex.py --headless, and it works (prints https://ubuntu.com after 10 seconds).
I can run it without --headless and I get

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 /snap/chromium/current/command-chromium.wrapper is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Revision history for this message
Olivier Tilloy (osomon) wrote :

That minimal example doesn't run here in a clean 20.04 VM with the chromium snap. However if I apply this minimal modification to the script, it succeeds, with and without the headless switch:

    -driver = webdriver.Chrome(options=options)
    +driver_path = "/snap/bin/chromium.chromedriver"
    +driver = webdriver.Chrome(options=options, executable_path=driver_path)

Does this work for you?

Revision history for this message
Marius Gedminas (mgedmin) wrote :

This is interesting information!

I have the chromium and chromium-chromedriver packages installed via apt. I wonder if that is why my example (headless) can work without overriding executable_path? chromium-chromedriver ships a /usr/bin/chromedriver that's a shell script that exec's /snap/bin/chromium.chromedriver.

> Does this work for you?

No. I get

seleniumwhy.py:10: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(options=options, executable_path=driver_path)
Traceback (most recent call last):
  File "seleniumwhy.py", line 10, in <module>
    driver = webdriver.Chrome(options=options, executable_path=driver_path)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/chrome/webdriver.py", line 95, in __init__
    RemoteWebDriver.__init__(
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 152, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 249, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
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 /snap/chromium/current/command-chromium.wrapper is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Meanwhile --headless emits the same DeprecationWarning, but works.

I'm also on Ubuntu 20.04 today (was on 19.10 when I filed the bug). Possibly relevant: I use the Ubuntu on Wayland session.

Revision history for this message
Olivier Tilloy (osomon) wrote :

Indeed, your last comment is relevant, I can now reproduce the problem in a Wayland session. The same test runs fine in an X11 session.

summary: - chromedriver doesn't work with the snap package, without --headless
+ [snap] chromedriver doesn't work without --headless under Wayland
tags: added: snap
Changed in chromium-browser (Ubuntu):
importance: Undecided → Low
tags: added: focal wayland
Revision history for this message
Marius Gedminas (mgedmin) wrote :

I can no longer observe this on Ubuntu 22.04 LTS (Wayland session) with chromium snap 101.0.4951.64 (1993).

(An xeyes test confirms that the selenium-driven chromium is using Xwayland.)

Revision history for this message
Olivier Tilloy (osomon) wrote :

Confirmed, this now works in 22.04.

Changed in chromium-browser (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Ian Russel Adem (ianrussel) wrote :

I'm still facing this issue on ubuntu 22.04

The process started from chrome location /snap/chromium/2168/usr/lib/chromium-browser/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Any help would be appreciated

Revision history for this message
Ian Russel Adem (ianrussel) wrote :

Exception in thread Thread-1 (start):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ian/projects/fame/fame/./webdriver.py", line 136, in start
    driver = get_chromedriver(use_proxy=True)
  File "/home/ian/projects/fame/fame/./webdriver.py", line 134, in get_chromedriver
    driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver', options=options)
  File "/home/ian/projects/fame/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/ian/projects/fame/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
    super().__init__(
  File "/home/ian/projects/fame/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 272, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/ian/projects/fame/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 364, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/ian/projects/fame/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
    self.error_handler.check_response(response)
  File "/home/ian/projects/fame/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
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 /snap/chromium/2168/usr/lib/chromium-browser/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x5581d9dfe3a3 <unknown>
#1 0x5581d9bda698 <unknown>
#2 0x5581d9c017e6 <unknown>
#3 0x5581d9bfc9be <unknown>
#4 0x5581d9c401a4 <unknown>
#5 0x5581d9c3fccf <unknown>
#6 0x5581d9c383d3 <unknown>
#7 0x5581d9c089ce <unknown>
#8 0x5581d9c09d51 <unknown>
#9 0x5581d9e447b6 <unknown>
#10 0x5581d9e46d8e <unknown>
#11 0x5581d9e4758d <unknown>
#12 0x5581d9e2dd7e <unknown>
#13 0x5581d9e47c7c <unknown>
#14 0x5581d9e217a8 <unknown>
#15 0x5581d9e62e58 <unknown>
#16 0x5581d9e62ff8 <unknown>
#17 0x5581d9e7d6d8 <unknown>
#18 0x7f4551ef8609 <unknown>

Revision history for this message
Marius Gedminas (mgedmin) wrote :

I'm now using Xephyr to confine my ChromeDriver-based Selenium tests

    Xephyr :2 -screen 1300x720
    export DISPLAY=:2
    unset WAYLAND_DISPLAY

This works fine for me on Ubuntu 22.10 in a Wayland session (and it also worked on 22.04 LTS).

As a bonus, the Chromium window doesn't steal focus any more when my Selenium tests close and open new browser windows!

But since things worked fine for me on 22.04 even before I implemented the Xephyr sandboxing, I'm not sure if this will be helpful to you or not.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.