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

Language and locale not set to system default #2087

Open
carstenfuchs opened this issue Feb 20, 2023 · 9 comments
Open

Language and locale not set to system default #2087

carstenfuchs opened this issue Feb 20, 2023 · 9 comments

Comments

@carstenfuchs
Copy link

carstenfuchs commented Feb 20, 2023

System

  • Version: 0.32.0
  • Platform: Ubuntu 22.04 LTS
  • Firefox: 110.0
  • Selenium: 4.7.2

Testcase

#!/usr/bin/env python3
import sys
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By


if __name__ == "__main__":
    options = webdriver.firefox.options.Options()
    service = webdriver.firefox.service.Service(log_path="geckodriver.log")

    options.log.level = "trace"
    options.set_preference('intl.accept_languages', 'de-DE')
    options.set_preference('intl.locale.requested', 'de-DE')

    browser = webdriver.Firefox(options=options, service=service)
    browser.get("about:support")
    sleep(10)
    browser.quit()

Trace-level log

Please see attachment: geckodriver.log

Description

I recently upgraded from Ubuntu 20.04 LTS to Ubuntu 22.04 LTS, where Firefox is installed as a snap package. My system language and locale is german, and under Ubuntu 20.04 LTS, the above script had the "about:support" page displayed in german language. This used to work without the two lines options.set_preference(…).

Now with Ubuntu 22.04 LTS, the "about:support" page is always in english.
I tried adding the options.set_preference(…) lines, but they make no difference.

What is the proper way please to set the language and locale so that "about:support" and similar pages are displayed in the system default language?

@whimboo
Copy link
Collaborator

whimboo commented Mar 14, 2023

@carstenfuchs I assume the same is the case when you start Firefox manually? In such a case it would be an issue with the Firefox snap package but not geckodriver, and a bug should be filed similar to all the other ones that are listed as dependency for https://bugzilla.mozilla.org/show_bug.cgi?id=1665641.

Please let me know. Thanks!

@carstenfuchs
Copy link
Author

Hello @whimboo ,
sorry for not having mentioned this explicitly: The problem does not occur when I start Firefox manually. When started manually, about:support is in German. Only when started in a testcase as described above is about:support (and other locale-specific elements, such das the button labels of the built-in PDF viewer) in English.

@whimboo
Copy link
Collaborator

whimboo commented Mar 14, 2023

Ok, so the geckodriver that you are using here is the snap-packaged one as well, right?

@carstenfuchs
Copy link
Author

carstenfuchs commented Mar 15, 2023

Ok, so the geckodriver that you are using here is the snap-packaged one as well, right?

Yes.

After my upgrade to Ubuntu 22.04 LTS I removed the geckodriver that I used until then, so that the snap-packaged is the only one left on my system:

$ find / -iname "*geckodriver*" 2>/dev/null
/snap/firefox/2356/usr/lib/firefox/geckodriver
/snap/bin/geckodriver
/snap/bin/firefox.geckodriver
/home/carsten/Zeiterfassung/.geckodriver.log
/var/lib/snapd/apparmor/profiles/snap.firefox.geckodriver
/var/lib/snapd/seccomp/bpf/snap.firefox.geckodriver.bin
/var/lib/snapd/seccomp/bpf/snap.firefox.geckodriver.src
/run/udev/tags/snap_firefox_geckodriver

$ which geckodriver
/snap/bin/geckodriver

/snap/bin/geckodriver links to /snap/bin/firefox.geckodriver which links to /usr/bin/snap. I don't know how it proceeds from there.

@whimboo
Copy link
Collaborator

whimboo commented Mar 15, 2023

Would you mind doing me a favor and test a non-snap packaged geckodriver and Firefox? I only want to be sure that this combination still works. Thanks!

@carstenfuchs
Copy link
Author

This works:

  • I installed another Firefox as documented here and took the recent geckodriver from here.
  • If I change nothing else, then as expected the testcase picks up the snap-provided geckodriver (the only one in PATH) which in turn starts the snap-provided Firefox. The output is all in English.
  • If I change the testcase to use the separately loaded geckodriver (service = webdriver.firefox.service.Service("…/path/to/geckodriver", log_path=".geckodriver.log")), the newly installed Firefox (that precedes the snap-Firefox in PATH) is used. The output is in German.

@whimboo
Copy link
Collaborator

whimboo commented Mar 20, 2023

Ok, so it's indeed snap related. Could you also please check how it works when you use the non-snap packaged geckodriver but the Firefox binary from the Snap package? Note that you would have to pass the --profile-root argument to geckodriver so it creates the Firefox profile at a Snap accessible location in your home directly and not under /tmp.

I'm asking because I would like to know where exactly the language information is lost. Thanks!

@carstenfuchs
Copy link
Author

Hmmm. I have a bit of trouble confirming what geckodriver gets actually loaded. Is there a way to confirm this?

In the context of the testcase above, and with the custom Firefox installed alongside the snap Firefox, please consider this setupcode. It is essentially the same as above, with comments added:

        options = webdriver.firefox.options.Options()
        service = webdriver.firefox.service.Service(
            # executable_path="?????",
            # service_args=["--profile-root", "/home/carsten/tmp"],
            log_path=".geckodriver.log",
        )

        # binary = webdriver.firefox.firefox_binary.FirefoxBinary("/snap/bin/firefox")
        # cls.browser = webdriver.Firefox(firefox_binary=binary, options=options, service=service)
        cls.browser = webdriver.Firefox(options=options, service=service)

This is the original setup code with which the snap geckodriver and the snap Firefox is used. The output of about:support is in English. It appears that the profile is in /tmp/ where the snap-Firefox cannot access it:
grafik

Now if I comment in the executable_path=… line, even with the obviously wrong path ("?????"), then the custom(?) geckodriver and the custom Firefox is used and the output is in German. (Note that the about:support page confirms which Firefox binary is used, but I cannot be sure what geckodriver is used!)
grafik

Finally, switching explicitly back to the snap-Firefox:

        options = webdriver.firefox.options.Options()
        service = webdriver.firefox.service.Service(
            executable_path="?????",
            service_args=["--profile-root", "/home/carsten/tmp"],
            log_path=".geckodriver.log",
        )

        binary = webdriver.firefox.firefox_binary.FirefoxBinary("/snap/bin/firefox")
        cls.browser = webdriver.Firefox(firefox_binary=binary, options=options, service=service)
        # cls.browser = webdriver.Firefox(options=options, service=service)

yields:
grafik

@whimboo
Copy link
Collaborator

whimboo commented Jul 5, 2023

@carstenfuchs sorry for the long delay in my response. But I somehow missed your reply.

Ok, so this all is related to the snap packages for Firefox and geckodriver then. What's interesting is that it also happens when both binaries run from within the same snap, because that's how they are packaged.

Could you please check by running both geckodriver and Firefox from snap if the preferences that you set for localization are set when querying for those in about:config?

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

No branches or pull requests

2 participants