Read more

Headless Chrome: Changing the Accept-Language header is not possible

Emanuel De
July 19, 2021Software engineer at makandra GmbH

It seems like changing the HTTP_ACCEPT_LANGUAGE is not possible for a headless chrome.

  • On Ubuntu the headless Chrome derives the Accept-Language from the operation system
  • Adding the option options.add_argument('--lang=de') to the Capybara::Selenium::Driver has no effect
  • Adding the preference options.add_preference('intl.accept_languages', 'de') to the Capybara::Selenium::Driver has only effects if the --headless option is skipped (see bug ticket #775911 Show snapshot )
  • Changing the request header in Capybara only works without Selenium
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show snapshot

You still can add logic to your application code that helps to modify the Accept-Language in tests. Here is an example for a Rails application with Cucumber integration tests:

class ApplicationController


  def accept_language

# Override the Accept-Language header for all Cucumber scenarios

Before do
  stub_const('ApplicationController::OVERRIDE_HTTP_ACCEPT_LANGUAGE', 'de')
Posted by Emanuel De to makandra dev (2021-07-19 14:10)