mozilla / geckodriver

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

Connection attempts to Marionette fail due to missing configuration file for Firefox (Linux lepotato 6.1.50-current-meson64) #2167

Closed oliviernes closed 3 months ago

oliviernes commented 3 months ago

System

Testcase

Selenium returned a TimeoutException with the message "Failed to read marionette port" with a python script. Error at the line to start the webdriver.

Here is part of the script:

from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By

service = Service(executable_path='./geckodriver') options = webdriver.FirefoxOptions() options.add_argument("start-maximized"); options.add_argument("disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--headless") options.log.level = "trace"

driver = webdriver.Firefox(service=service, options=options)

Stacktrace

Here is the error output:

Traceback (most recent call last): File "/opt/folder/my_script.py", line 35, in driver = webdriver.Firefox(service=service, options=options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/folder/.venv/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver.py", line 69, in init super().init(command_executor=executor, options=options) File "/opt/folder/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 208, in init self.start_session(capabilities) File "/opt/folder/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session response = self.execute(Command.NEW_SESSION, caps)["value"] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/folder/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute self.error_handler.check_response(response) File "/opt/folder/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Failed to read marionette port

Trace-level log

No geckodriver.log file was found in the script’s current working directory.

whimboo commented 3 months ago

Do you use a snap or similar package of Firefox or geckodriver? This could give problems when the temporary profile as created by geckodriver is not accessible by Firefox. Maybe try with the --profile argument for moz:firefoxOptions and reference an existing profile that works manually with Firefox.

There has to be a geckodriver log somewhere. If it doesn't appear please talk to the Selenium folks in how to get it. Without the trace logs I'm not really able to help.

oliviernes commented 3 months ago

Thank you for your answer.

I used APT to install Firefox and I downloaded and unzipped geckodriver in my python script folder. Anyway, I think the problem is from Firefox because I removed the headless option and I noticed a window appeared before Firefox opened named Configuration Error and with the text Failed to read the configuration file. Please contact your system administrator. If I close the window, then Firefox opens and there is no more error.

I thought I could find a way to close automatically this window in non-headless mode but after a fresh new install of the OS when I now launch my script in non-headless mode, I get this error: selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

I also tried --profile and --safe-mode arguments for moz:firefoxOptions but with no improvements.

whimboo commented 3 months ago

Thank you for the details! So this failure message is raised when the autoconfig extension is not able to load the config file. Did that only happen once or all the time when you open Firefox?

Maybe you could check what's wrong with the file? Most likely the distro adds it for its own version of Firefox but might not do it correctly? Here are more details about that extension.

oliviernes commented 3 months ago

Yes, it happens all the time when I open Firefox but I know the reason now thanks to your link to the autoconfig file. I looked for the content of the file /usr/lib/firefox-esr/defaults/pref/local-settings.js and I noticed a line pref("general.config.filename", "mozilla.cfg");

I then found this symbolic link:

lrwxrwxrwx 1 root root 25 31 août 2023 /usr/lib/firefox-esr/mozilla.cfg -> /etc/armbian/firefox.conf

But the catch is that there is no firefox.conf file in the /etc/armbian directory on the Armbian images lepotato (I tried several other images with the same problem).

So I just asked an AI to build me a firefox.cfg file for Debian. Then I placed the file in the /etc/armbian folder and after changing a line pref("network.proxy.type", 1); to pref("network.proxy.type", 0); it worked and I didn't get the configuration file error anymore.

whimboo commented 3 months ago

That's great to hear. I would then suggest to file an issue for that problem for your distro as it sounds like there is a problem with the installation script at least for this platform. Feel free to drop a reference here when you did that.

But that also means there is nothing broken for geckodriver.

Thanks for your help figuring it out!

oliviernes commented 3 months ago

This issue seems to concern only Armbian lepotato images with Debian. The Ubuntu versions like Jammy have Firefox installed with Snap and they don't have this issue of missing configuration files. So there is even a simpler solution to fix the issue for Debian version images:

sudo apt purge firefox-esr sudo apt install snapd systemctl start snapd sudo systemctl enable snapd snap install firefox

This will install Firefox 123.0.1-1 and there are no more problems with missing conf files. I just had to use geckodriver from snap firefox install in my python script.

I replaced this line:

service = Service(executable_path='./geckodriver')

by:

service = Service(executable_path='/snap/bin/firefox.geckodriver')

I have just inform the Armbian forum about this issue (visible after approval by the moderator)

https://forum.armbian.com/topic/36276-missing-firefox-configuration-file-for-lepotato-images-derived-from-debian/

oliviernes commented 3 months ago

After checking with the new Armbian releases of Debian versions (Gnome desktop and Cinnamon interfaces), those images have the firefox .conf in the /etc/armbian directory and they don't have the error of configuration file. The images with XFCE interface that I was looking for was only present in the archives.

So this issue was corrected by Armbian for the new lepotato Debian versions release.

whimboo commented 3 months ago

That's great to know. Thanks a lot for checking that!