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

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

Open
ltanase77 opened this issue Feb 6, 2023 · 63 comments
Labels

Comments

@ltanase77
Copy link

ltanase77 commented Feb 6, 2023

System

  • Version: 0.32.0
  • Platform: Debian 10
  • Firefox: 109.0.1
  • Selenium: facebook/php-webdriver 1.13 (used with Laravel 8)

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

@ltanase77
Copy link
Author

ltanase77 commented Feb 6, 2023

The error appears when WebDriver needs to start the GeckoDriver with this line of code: $driver = Firefox\FirefoxDriver::start($desiredCapabilities); If I start manually firefox and gecko driver and I am using $driver = RemoteWebDriver::create($serverUrl, $desiredCapabilities); everything is fine. But this implies that firefox and geckodriver to run permanently.
My full PHP code below:

$desiredCapabilities = DesiredCapabilities::firefox();
$desiredCapabilities->setCapability('acceptSslCerts', false);
 $firefoxOptions = new FirefoxOptions();
$firefoxOptions->addArguments(['-headless', '-vv', '-marionette-port', '0']);
$firefoxOptions->setOption("binary", "/usr/bin/firefox");
$desiredCapabilities->setCapability(FirefoxOptions::CAPABILITY, $firefoxOptions);
$serverUrl = 'http://localhost:4444';
$driver = Firefox\FirefoxDriver::start($desiredCapabilities);

@whimboo
Copy link
Collaborator

whimboo commented Feb 6, 2023

Could you please attach a trace-level log from geckodriver? Read more about reporting actionable bugs in our contribution guidelines.

@ltanase77
Copy link
Author

ltanase77 commented Feb 6, 2023

Where does geckodriver save his log files? How can I locate them? I saw requirements for providing such trace-level log, but I do not know where to find them or how can I obtain them.

@whimboo
Copy link
Collaborator

whimboo commented Feb 7, 2023

This depends on the Selenium binding. As you are using the PHP one as I can see you may want to check their support pages. We actually don't have that in our listing because it's not part of the official Selenium repository.

@whimboo
Copy link
Collaborator

whimboo commented Feb 7, 2023

Alternatively you could try to use geckodriver directly by using eg curl:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Usage.html#standalone

@ltanase77
Copy link
Author

ltanase77 commented Feb 7, 2023

Does not have geckodriver a default settings which tell where to place the log files? I tried using it directly with curl but I am not able to pass in the curl data the headless flag.

@whimboo
Copy link
Collaborator

whimboo commented Feb 8, 2023

You have to specify it similarly to what is described in our documentation.

But I also have just seen that you are using '-marionette-port', '0' in the capabilities. This is not needed and might confuse geckodriver. It's doing that actually already on its own. Probably this might already fix it.

@ltanase77
Copy link
Author

I have tried: $firefoxOptions->setOption("log", ["level" => "trace"]);

The exception is the following:

Facebook\WebDriver\Exception\WebDriverCurlException Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"firefox","moz:firefoxOptions":{"binary":"/usr/lib/firefox/firefox","log":{"level":"trace"},"args":["-headless"],"prefs":{"reader.parse-on-load.enabled":false,"devtools.jsonview.enabled":false}},"acceptInsecureCerts":false}]}}

Operation timed out after 180001 milliseconds with 0 bytes received

In the curl request seems that log level is set, but there is no sign of a log file. Or at least I do not know where to look.

@whimboo
Copy link
Collaborator

whimboo commented Feb 10, 2023

geckodriver isn't writing the log to the log file but to stdout. So probably you ignore the output? Maybe start geckodriver manually in a terminal and running the curl command in a different one.

@ltanase77
Copy link
Author

ltanase77 commented Feb 10, 2023

Ok. I raised an issue with php-webdriver team for not being able to output log files. They set a dev-feature/driver-service-logging branch. I used it and set the log level to trace. This is the output of the geckodriver.log file:

1676027182808   geckodriver     INFO    Listening on 127.0.0.1:9515

1676027182828   mozrunner::runner       INFO    Running command: "/usr/lib/firefox/firefox" "--marionette" "-headless" "-no-remote" "-profile" "/tmp/rust_mozprofileLrnVv3"
1676027182828   geckodriver::marionette DEBUG   Waiting 60s to connect to browser on 127.0.0.1
1676027182828   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027182828   geckodriver::marionette TRACE   Retrying in 100ms
[GFX1-]: glxtest: Unable to open a connection to the X server
1676027182928   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027182928   geckodriver::marionette TRACE   Retrying in 100ms
1676027183028   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183028   geckodriver::marionette TRACE   Retrying in 100ms
[GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
1676027183129   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183129   geckodriver::marionette TRACE   Retrying in 100ms
1676027183229   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183229   geckodriver::marionette TRACE   Retrying in 100ms
1676027183329   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183329   geckodriver::marionette TRACE   Retrying in 100ms
1676027183429   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183429   geckodriver::marionette TRACE   Retrying in 100ms
1676027183529   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183529   geckodriver::marionette TRACE   Retrying in 100ms
1676027183630   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183630   geckodriver::marionette TRACE   Retrying in 100ms
1676027183730   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183730   geckodriver::marionette TRACE   Retrying in 100ms
1676027183830   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183830   geckodriver::marionette TRACE   Retrying in 100ms
1676027183930   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027183930   geckodriver::marionette TRACE   Retrying in 100ms
1676027184030   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184030   geckodriver::marionette TRACE   Retrying in 100ms
1676027184130   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184130   geckodriver::marionette TRACE   Retrying in 100ms
1676027184231   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184231   geckodriver::marionette TRACE   Retrying in 100ms
1676027184331   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184331   geckodriver::marionette TRACE   Retrying in 100ms
1676027184431   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184431   geckodriver::marionette TRACE   Retrying in 100ms
1676027184531   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184531   geckodriver::marionette TRACE   Retrying in 100ms
1676027184631   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184631   geckodriver::marionette TRACE   Retrying in 100ms
1676027184732   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184732   geckodriver::marionette TRACE   Retrying in 100ms
1676027184832   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184832   geckodriver::marionette TRACE   Retrying in 100ms
1676027184932   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027184932   geckodriver::marionette TRACE   Retrying in 100ms
1676027185032   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027185032   geckodriver::marionette TRACE   Retrying in 100ms
1676027185132   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027185132   geckodriver::marionette TRACE   Retrying in 100ms
1676027185232   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027185232   geckodriver::marionette TRACE   Retrying in 100ms
1676027185333   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileLrnVv3/MarionetteActivePort
1676027185333   geckodriver::marionette TRACE   Retrying in 100ms

*** You are running in headless mode.

(firefox:6759): dconf-CRITICAL **: 11:44:01.685: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.685: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.686: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.686: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.687: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.849: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.850: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.850: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:44:01.850: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:45:01.687: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:45:01.687: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:45:01.690: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:45:01.690: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:45:01.690: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6759): dconf-CRITICAL **: 11:45:01.690: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

1676029561715   geckodriver::browser    TRACE   Failed to open /tmp/rust_mozprofileFbK2B6/MarionetteActivePort


@ltanase77
Copy link
Author

ltanase77 commented Feb 10, 2023

The stack trace error for this is:

Facebook\WebDriver\Exception\Internal\WebDriverCurlException Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"firefox","moz:firefoxOptions":{"binary":"/usr/lib/firefox/firefox","log":{"level":"trace"},"args":["-headless"],"prefs":{"reader.parse-on-load.enabled":false,"devtools.jsonview.enabled":false}},"acceptInsecureCerts":false}]}}

Operation timed out after 180001 milliseconds with 0 bytes received

There is no MarionetteActivePort file in the moz profile directory. Just an user.js file. Furthemore there is no .cache directory in the /usr/sbin directory. At least I do not see it.

@ltanase77
Copy link
Author

ltanase77 commented Feb 10, 2023

If i do not set the log level, geckodriver.log file looks like this:

1676028690758   geckodriver     INFO    Listening on 127.0.0.1:9515

1676028690778   mozrunner::runner       INFO    Running command: "/usr/lib/firefox/firefox" "--marionette" "-headless" "-no-remote" "-profile" "/tmp/rust_mozprofilesy2VqH"
[GFX1-]: glxtest: Unable to open a connection to the X server
[GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt

*** You are running in headless mode.

(firefox:6417): dconf-CRITICAL **: 11:32:30.820: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.820: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.821: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.821: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.822: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.831: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.831: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.831: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:32:30.831: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:33:30.822: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:33:30.822: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:33:30.825: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:33:30.825: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:33:30.826: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

(firefox:6417): dconf-CRITICAL **: 11:33:30.826: unable to create directory '/usr/sbin/.cache/dconf': Permission denied.  dconf will not work properly.

The stack trace error is : Facebook\WebDriver\Exception\TimeoutException Failed to read marionette port

@whimboo
Copy link
Collaborator

whimboo commented Feb 10, 2023

So Firefox doesn't correctly startup on this machine and geckodriver tries only 60s to find the marionette port file. Could you please check if headful mode works? Maybe headless mode needs some library which isn't available. To further investigate this issue probably a Firefox bug should be filed on Bugzilla.

@ltanase77
Copy link
Author

Is there any explanation why the problem did not persist if geckodriver is running in the background, permanently and pops only when php-webdriver try to start geckodriver?

@ltanase77
Copy link
Author

ltanase77 commented Feb 11, 2023

I created a .cache directory in the /usr/sbin and grant it relevant permissions and now (firefox:6417): dconf-CRITICAL error has disappeared from the geckodriver.log file. However the issue is not fixed. So I think the problem is connected with the other error mentioning that geckodriver fails to open /tmp/rust_mozprofile3pRsPd/MarionetteActivePort. Is just retrying until is timing out.

@ltanase77
Copy link
Author

ltanase77 commented Feb 11, 2023

The issue seems related with this bug Read Marionette port from MarionetteActivePort file within the Firefox profile directory which was closed one year ago.

@ltanase77
Copy link
Author

ltanase77 commented Feb 11, 2023

Running in headful mode results in this error: Error: no DISPLAY environment variable specified. Manually I can export this DISPLAY variable and firefox starts in headful mode, as I am using Xfvb emulator. But I do not know how to do it when using php-webdriver to start geckodriver.

@OndraM
Copy link
Contributor

OndraM commented Feb 11, 2023

But I do not know how to do it when using php-webdriver to start geckodriver.

Hi, php-webdriver maintainer here. Environment variables passed to geckodriver process are (by default) inherited from the parent process (via $_ENV). So you should be able to pass them like this:

  1. make sure ENV values are injected to PHP, run php -i | grep 'variables_order' and if you don't see "E" in the value (like in "EGPCS") but only something like "GPCS", go to your php.ini and change it to variables_order = "EGPCS".
  2. My first guess would be to just try to start the headless mode now, as the environment variables may be the difference causing the issue:
php your-script.php
  1. If this doesn't help, try the headful mode or anything else you may need to debug the issue
export DISPLAY=...; php your-script.php

Also to add some context, all what php-webdriver does when starting geckodriver binary is just executing command geckodriver -p 9515, nothing else. However, the environment may actually differ from what you get when running the same command manually (what @ltanase77 says its working fine), because PHP may not by exposing any environment variables to the process (however - I just tried this and it works for me in any scenario, I'm unable to reproduce this locally no Arch linux and it also works fine in GH Actions tests).

@ltanase77
Copy link
Author

I changed my php.ini file as suggested by there is no change. I cannot simply php myscript.php because the php code sits in Laravel controller and when I am trying php LaravelController.php I get an error like this:
PHP Fatal error: Uncaught Error: Class 'App\Http\Controllers\Controller' not found in path to my controller. Probably I need to make a custom artisan command to run the controller from the terminal.
I have found that after each failed attempt there is a firefox process still running. It seems that geckodriver start the firefox : /usr/lib/firefox/firefox --marionette -headless -no-remote -profile /tmp/rust_mozprofileetc. Then it tries to reach a certain file in this rust_mozprofile directories, repsectively: MarionetteActivePort. I do not know if geckodriver is creating such directories or firefox, but somehow it seems geckodriver expect firefox to write a certain file in this directories which firefox does not, for some unknown reasons.

@whimboo
Copy link
Collaborator

whimboo commented Feb 12, 2023

Yes, geckodriver waits for such a file that is created by Marionette after Firefox has started up. If the file doesn't appear then there is a problem with the startup. As said please file a bug for Firefox and tell us the bug number here. I'm happy to continue helping once I'm back and in case no-one did on the bug until then. Thanks.

@ltanase77
Copy link
Author

New Firefox bug created: https://bugzilla.mozilla.org/show_bug.cgi?id=1816409

@whimboo whimboo changed the title Failed to read marionette port Firefox fails to start-up on Debian 10 in headless mode (Failed to open MarionetteActivePort) Feb 20, 2023
@murkl
Copy link

murkl commented Mar 15, 2023

Same issue here. Unfortunately when i run the docker container with user permissions (in docker compose: user: "${UID:-1000}:${GID:-1000}") i got the same error. When deleted this flag, it works :)

@whimboo
Copy link
Collaborator

whimboo commented Mar 15, 2023

@murkl this is a very interesting information! When you have this flag set, can you start Firefox manually in headless mode? You could try to use the --screenshot argument which uses headless by default and will exit Firefox once the screenshot has been created.

@whimboo
Copy link
Collaborator

whimboo commented Mar 15, 2023

Changing the permissions didn't help for another user. So it might not be the right solution.

Anyone who can see this could you please run the test with the environment variable MOZ_LOG="Process:5"set? I would like to know if there might be something interesting in the trace log of geckodriver.

@whimboo
Copy link
Collaborator

whimboo commented Mar 22, 2023

@ltanase77 or @murkl would you mind trying out what I suggested in my last comment? I would appreciate any feedback so that we can get it investigated. Thanks!

@whimboo
Copy link
Collaborator

whimboo commented Jul 4, 2023

You can use the su command under Linux.

@ssada1975
Copy link

@whimboo confirm that if i run manually geckodriver as www-data, "su -pc geckodriver www-data", it doesn't work likewise if I run automatically

root@714e8dfc4dd1:~# su -pc geckodriver www-data
bash: /root/.bashrc: Permission denied
1688589263837 geckodriver INFO Listening on 127.0.0.1:4444
1688589266837 geckodriver::browser DEBUG Backing up prefs to "/tmp/firefox/profile/user.geckodriver_backup_1"
1688589266846 mozrunner::runner INFO Running command: MOZ_CRASHREPORTER="1" MOZ_CRASHREPORTER_NO_REPORT="1" MOZ_CRASHREPORTER_SHUTDOWN="1" MOZ_NO_REMOTE="1" "/opt/firefox/./firefox" "--marionette" "-headless" "-vv" "-profile" "/tmp/firefox/profile/" "--shm-size 2g" "-no-remote"
1688589266848 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1
1688589266849 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589266849 geckodriver::marionette TRACE Retrying in 100ms
*** You are running in headless mode.
1688589266951 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589266952 geckodriver::marionette TRACE Retrying in 100ms
[GFX1-]: glxtest: Unable to open a connection to the X server
1688589267052 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267055 geckodriver::marionette TRACE Retrying in 100ms
1688589267156 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267159 geckodriver::marionette TRACE Retrying in 100ms
[GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
1688589267259 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267260 geckodriver::marionette TRACE Retrying in 100ms
1688589267360 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267360 geckodriver::marionette TRACE Retrying in 100ms
1688589267460 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267460 geckodriver::marionette TRACE Retrying in 100ms
1688589267561 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267561 geckodriver::marionette TRACE Retrying in 100ms
1688589267661 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267661 geckodriver::marionette TRACE Retrying in 100ms
1688589267761 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267761 geckodriver::marionette TRACE Retrying in 100ms
1688589267861 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267862 geckodriver::marionette TRACE Retrying in 100ms
1688589267962 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589267962 geckodriver::marionette TRACE Retrying in 100ms
1688589268062 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268062 geckodriver::marionette TRACE Retrying in 100ms
1688589268163 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268163 geckodriver::marionette TRACE Retrying in 100ms
1688589268263 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268263 geckodriver::marionette TRACE Retrying in 100ms
1688589268363 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268363 geckodriver::marionette TRACE Retrying in 100ms
1688589268464 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268464 geckodriver::marionette TRACE Retrying in 100ms
1688589268564 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268564 geckodriver::marionette TRACE Retrying in 100ms
1688589268664 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268664 geckodriver::marionette TRACE Retrying in 100ms
1688589268764 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268764 geckodriver::marionette TRACE Retrying in 100ms
1688589268865 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268865 geckodriver::marionette TRACE Retrying in 100ms
1688589268965 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589268965 geckodriver::marionette TRACE Retrying in 100ms
1688589269065 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269065 geckodriver::marionette TRACE Retrying in 100ms
1688589269165 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269165 geckodriver::marionette TRACE Retrying in 100ms
1688589269266 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269266 geckodriver::marionette TRACE Retrying in 100ms
1688589269366 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269366 geckodriver::marionette TRACE Retrying in 100ms
1688589269466 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269466 geckodriver::marionette TRACE Retrying in 100ms
1688589269566 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269566 geckodriver::marionette TRACE Retrying in 100ms
1688589269667 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269667 geckodriver::marionette TRACE Retrying in 100ms
1688589269767 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269767 geckodriver::marionette TRACE Retrying in 100ms
1688589269867 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269867 geckodriver::marionette TRACE Retrying in 100ms
1688589269967 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589269967 geckodriver::marionette TRACE Retrying in 100ms
1688589270068 geckodriver::browser TRACE Failed to open /tmp/firefox/profile/MarionetteActivePort
1688589270068 geckodriver::marionette TRACE Retrying in 100ms

(firefox:6288): dconf-CRITICAL **: 20:34:30.157: unable to create directory '/root/.cache/dconf': Permission denied. dconf will not work properly.

(firefox:6288): dconf-CRITICAL **: 20:34:30.157: unable to create directory '/root/.cache/dconf': Permission denied. dconf will not work properly.

(firefox:6288): dconf-CRITICAL **: 20:34:30.162: unable to create directory '/root/.cache/dconf': Permission denied. dconf will not work properly.

(firefox:6288): dconf-CRITICAL **: 20:34:30.163: unable to create directory '/root/.cache/dconf': Permission denied. dconf will not work properly.

(firefox:6288): dconf-CRITICAL **: 20:34:30.163: unable to create directory '/root/.cache/dconf': Permission denied. dconf will not work properly.

(firefox:6288): dconf-CRITICAL **: 20:34:30.163: unable to create directory '/root/.cache/dconf': Permission denied. dconf will not work properly.

@whimboo
Copy link
Collaborator

whimboo commented Jul 6, 2023

@ssada1975 thanks a lot! So could you now try to start Firefox by using the www-data user? I would assume that it doesn't start as well. If that is the case it would be best to get a bug filed for Firefox directly. Let me know and I can guide you.

@whimboo
Copy link
Collaborator

whimboo commented Jul 6, 2023

Oh, I actually found https://answers.launchpad.net/ubuntu/+question/695824. As it looks like www-data doesn't have a home directory by default and as such Firefox fails to store the profile. Comment 5 on this bug tracker issue should help you. Please let us know.

@ltanase77
Copy link
Author

Hi whimboo!
So, in the home directory should I create a www-data folder with the same write access as the other user, where firefox will create the .mozilla folder when run by www-data user?

@whimboo
Copy link
Collaborator

whimboo commented Jul 7, 2023

@ltanase77 please have a look at https://linuxhandbook.com/create-home-directory-existing-user/. That should do it.

@ltanase77
Copy link
Author

sudo mkhomedir_helper www-data does not create a home directory for www-data user.

@ltanase77
Copy link
Author

The home directory for www-data user seems to be /var/www where a .profile, .bashrc and bash_logout file exists

@ssada1975
Copy link

no way to make it works, even creating /var/www/.cache or .mozilla and giving rights to www-data

@ltanase77
Copy link
Author

In my case the www-data is set as nologin user and probably that's why I cannot create a home directory.

@ssada1975
Copy link

@ltanase77 in the world we are just you and me not being able to run geckodriver automatically from Php? 😭
It sounds crazy there is no solution

@ltanase77
Copy link
Author

I have somehow bypass the problem, by running geckodriver as background process with nohup geckodriver and then instead of $driver = Firefox\FirefoxDriver::start($desiredCapabilities); I am using $driver = RemoteWebDriver::create($serverUrl, $desiredCapabilities); In this way I was able to schedule a Laravel job that is running automatically daily at certain hours, using the php-webdriver for scraping info from a certain website.

@whimboo
Copy link
Collaborator

whimboo commented Jul 7, 2023

@ltanase77 thanks for checking. So there is indeed a problem in starting Firefox with the www-data user, and some missing permissions. Could you maybe check if that really only applies to headless? I assume that headful will also be affected the same way.

Do you actually see where geckodriver tries to create the temporary Firefox profile? Is it also under /tmp/firefox/...? I assume www-data doesn't have access to? Also you could start geckodriver with the --profile-root argument (which is new since version 0.32.0) and specify the /var/www/ folder. Does that work then?

@ltanase77
Copy link
Author

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 error geckodriver: 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.

@ssada1975
Copy link

@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
Copy link

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
Copy link
Collaborator

whimboo commented Aug 2, 2023

@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
Copy link
Collaborator

whimboo commented Aug 2, 2023

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 error geckodriver: 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
Copy link

@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
Copy link
Collaborator

whimboo commented Aug 3, 2023

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

@whimboo
Copy link
Collaborator

whimboo commented Aug 21, 2023

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

@ssada1975
Copy link

@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
Copy link

MatzFan commented Dec 7, 2023

[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
Copy link
Collaborator

whimboo commented Dec 12, 2023

@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
Copy link

MatzFan commented Dec 12, 2023

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
Copy link
Collaborator

whimboo commented Dec 12, 2023

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
Copy link

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

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

No branches or pull requests

8 participants