mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.14k stars 1.52k forks source link

Firefox fails to start-up on Debian 10 in headless mode (Failed to open MarionetteActivePort) #2082

Open ltanase77 opened 1 year ago

ltanase77 commented 1 year ago

System

Testcase

Stacktrace

Facebook\WebDriver\Exception\TimeoutException Failed to read marionette port (Most recent call first) at (unknown method)(/opt/bitnami/sites/Cabinet/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:133) at Facebook\WebDriver\Exception\WebDriverException::throwException(/opt/bitnami/sites/Cabinet/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:385) at Facebook\WebDriver\Remote\HttpCommandExecutor::execute(/opt/bitnami/sites/Cabinet/vendor/php-webdriver/webdriver/lib/Remote/Service/DriverCommandExecutor.php:42) at Facebook\WebDriver\Remote\Service\DriverCommandExecutor::execute(/opt/bitnami/sites/Cabinet/vendor/php-webdriver/webdriver/lib/Firefox/FirefoxDriver.php:61) at Facebook\WebDriver\Firefox\FirefoxDriver::startUsingDriverService(/opt/bitnami/sites/Cabinet/vendor/php-webdriver/webdriver/lib/Firefox/FirefoxDriver.php:33) at Facebook\WebDriver\Firefox\FirefoxDriver::start(/opt/bitnami/sites/Cabinet/app/Http/Controllers/Maps/CheckLaw.php:60)

Trace-level log

ssada1975 commented 1 year ago

@ltanase77 and @whimboo here are my steps mkdir -m 777 /tmp/firefox/profile/ chown www-data:www-data /tmp/firefox/profile/ su -pc "geckodriver --profile-root /tmp/firefox/profile" www-data

it starts but again same problem not finding marionette port

ssada1975 commented 1 year ago

Not sure if helps, but if i run a batch with the above sh instruction from PHP and print output i get

geckodriver 0.33.0 (a80e5fd61076 2023-04-02 18:31 +0000) WebDriver implementation for Firefox USAGE: geckodriver [OPTIONS] OPTIONS: --allow-hosts ... List of hostnames to allow. By default the value of --host is allowed, and in addition if that's a well known local address, other variations on well known local addresses are allowed. If --allow-hosts is provided only exactly those hosts are allowed. --allow-origins ... List of request origins to allow. These must be formatted as scheme://host:port. By default any request with an origin header is rejected. If --allow-origins is provided then only exactly those origins are allowed. --android-storage Selects storage location to be used for test data (deprecated). [possible values: auto, app, internal, sdcard] -b, --binary Path to the Firefox binary --connect-existing Connect to an existing Firefox instance -h, --help Prints this message --host Host IP to use for WebDriver server [default: 127.0.0.1] --jsdebugger Attach browser toolbox debugger for Firefox --log Set Gecko log level [possible values: fatal, error, warn, info, config, debug, trace] --log-no-truncate Disable truncation of long log lines --marionette-host Host to use to connect to Gecko [default: 127.0.0.1] --marionette-port Port to use to connect to Gecko [default: system-allocated port] -p, --port Port to use for WebDriver server [default: 4444] --profile-root Directory in which to create profiles. Defaults to the system temporary directory. -v Log level verbosity (-v for debug and -vv for trace level) -V, --version Prints version and copying information --websocket-port Port to use to connect to WebDriver BiDi [default: 9222]

whimboo commented 1 year ago

@ssada1975 sorry for the late reply but I was out the last three weeks. This log shows that there was a problem with specifying arguments. Could you try again by using --profile-root=/tmp/firefox/profile? Does that work?

whimboo commented 1 year ago

I am using aws lightsail bitnami lamp stack, which according with their docs runs apache and php under daemon user and group. Starting geckodriver manually with --profile-root /var/www-data returns this errorgeckodriver: error: Unable to write to temporary directory; consider --profile-root with a writeable directory Geckodriver is creating temporary firefox profile in directly in /tmp by creating a folder rust_mozprofile{uid}. Some of such folders are created by the daemon user, some by the ssh user under which I log in the machine. I assume that when php-webdriver is trying to start geckodriver is using the daemon user under which php is running.

@ltanase77 yes, if PHP starts geckodriver it will automatically run under the same user. So if you specify the --profile-root and set a writable folder does it work for you?

Also (as already asked the last time) could you try without --profile-root and headful? I assume that this is also affected and not only headless.

Thanks.

ssada1975 commented 1 year ago

@whimboo same problem

root@a91c65994790:/home# su -pc "geckodriver --profile-root=/tmp/firefox/profile" www-data bash: /root/.bashrc: Permission denied 1691008088291 geckodriver INFO Listening on 127.0.0.1:4444 1691008104269 mozrunner::runner INFO Running command: MOZ_CRASHREPORTER="1" MOZ_CRASHREPORTER_NO_REPORT="1" MOZ_CRASHREPORTER_SHUTDOWN="1" MOZ_NO_REMOTE="1" "/opt ... "--profile-root" "/tmp/firefox/profile/" "--shm-size 2g" "-no-remote" "-profile" "/tmp/firefox/profile/rust_mozprofileCj7WvS" 1691008104287 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1 1691008104288 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/rust_mozprofileCj7WvS/MarionetteActivePort 1691008104288 geckodriver::marionette TRACE Retrying in 100ms 1691008104389 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/rust_mozprofileCj7WvS/MarionetteActivePort 1691008104394 geckodriver::marionette TRACE Retrying in 100ms *** You are running in headless mode.

whimboo commented 1 year ago

@ssada1975 but has www-data write permissions for /tmp/firefox/profile? Also note bash: /root/.bashrc: Permission denied which might indicate a problem.

whimboo commented 1 year ago

@ltanase77 or @ssada1975 do you have any further feedback to my above question? Thanks a lot!

ssada1975 commented 1 year ago

@whimboo I created a group getent group test usermod -G test www-data usermod -G test root chown test /tmp/firefox/profile chmod r+w /tmp/firefox/profile -R

that should give rights both to root and www-data but no changes, always same errors as above

MatzFan commented 10 months ago

[GFX1-]: glxtest: Unable to open a connection to the X server looks suspiciously like: https://bugzilla.mozilla.org/show_bug.cgi?id=1375585, would that be correct? Did anyone ever get a workaround working for headless WebGL support for Debian-based Linux?

whimboo commented 9 months ago

@MatzFan how do you run geckodriver? Is it with your normal user account or a different one? Does the Firefox profile in use have the correct permissions so that Firefox can write to it?

MatzFan commented 9 months ago

Hi @whimboo, thanks for your response. I'm using Selenium (Ruby bindings). I have not modified the permissions for my profile and in any case I'm starting a Selenium driver without a profile. I'm not using a different user account. It is actually Tor Browser I'm using too, not regular Firefox. My project is a Selenium-driver Tor Browser.

I've now managed a workaround for my tests by using Xvfb. This showed up an issue that I needed to set the screen dimensions, as when using the default screen size it was smaller than my specified Selenium window size and WebGL did not work. It works now I have set the screen size large enough.

whimboo commented 9 months ago

Ok, good to hear that a workaround via xvfb works for you. I cannot give a promise when headless will work given that this is outside of our team, and it's still not clear what affects that. Sadly I don't have a way to reproduce at the moment.

klemens-u commented 4 months ago

I had a lot of problems troubleshooting a similar issue. The problem was that we run our docker container with user:group of the host (=dev) machine. Headless Firefox does not like that at all. The solution was to run Firefox with sudo.

Here is a complete writeup: https://www.ullright.org/ullWiki/show/symfony7-panther-e2e-testing-with-docker-setup-and-troubleshooting