Fork me on GitHub
#etaoin
<
2023-09-09
>
Martynas Maciulevičius10:09:00

Hey. I'm trying out this library and I'm trying to set a locale for my webdriver. But if I want to change it to German then it doesn't do that at all. What's the way to do it? All I want to do is to make Chromium to send the Accept-Language header with my value. This is what I tried:

(defn start-driver! []
  (e/chrome-headless
   {:capabilities {:prefs {:intl.accept_languages "de,de-DE"
                           :intl {:accept_languages "de,de-DE"}
                           "intl.accept_languages" "de"
                           :accept_languages "de,de-DE"}
                   :accept_languages "de,de-DE"
                   :intl {:accept_languages "de,de-DE"}}
    :intl {:accept_languages "de,de-DE"}
    :accept_languages "de,de-DE"
    :args ["lang=de,de-DE" "--lang=de,de-DE"]
    :args-driver ["lang=de,de-DE" "--lang=de,de-DE"]
    :env {"LANGUAGE" "de"
          "LANG" "de"}}))
I also tried to set LANGUAGE and LANG env vars by hand but this doesn't work too. This doesn't work with Firefox too :thinking_face:

lread12:09:24

Hi Martynas! I'm not sure, but I'll take a look sometime today.

lread13:09:54

So, I searched around, and for Chrome using https://peter.sh/experiments/chromium-command-line-switches/#accept-lang worked for me:

(require '[etaoin.api :as e])

(def driver (e/chrome {:args ["--accept-lang=de"]}))

(e/go driver "")
;; page came up in German

(e/quit driver)
The solution will be different for Firefox. Do you need to get that working as well?

Martynas Maciulevičius13:09:12

I want any. Chromium is faster so I'll prefer that. Can you add this to docs? This would be helpful for other people. What I'm trying to do is to crawl in en_US but my server is in Germany. And it's messed up. It works. It's great.

🎉 2
lread14:09:35

These underlying details tend to change in the webdriver/browser world, so I'm kind of hesitant to add it to the Etaoin docs. But, yeah, I agree this kind of tip would be helpful... so I could add a note with a caveat. After you've tried it for a bit longer, and you've found it still works for you, let me know and I'll add that note.

👍 2
Martynas Maciulevičius14:09:58

> so I'm kind of hesitant to add it to the Etaoin docs Also it's a good idea to NOT add it as a special plugin syntax and instead point into the location of these switches. But then maybe that makes sense if the switches are too weird for each browser... :thinking_face: I don't like how headless is a switch but then I can't simply edit the command line into xvfb firefox --headless easily. And then there is capabilities too... too many switches for little value. The customized API hides flexibility. And then somebody needs to maintain it, which is not good.

lread14:09:29

Yeah, Etaoin is a thin wrapper over https://www.w3.org/TR/webdriver/. So it inherits much of WebDriver's design choices and philosophy. There are many different evolving/changing browser vendor-specific details that WebDriver does not cover.