Posted 6 days ago. Visible to the public.

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

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)
  • Changing the request header in Capybara only works without Selenium.

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:

Copy
class ApplicationController OVERRIDE_HTTP_ACCEPT_LANGUAGE = nil def accept_language OVERRIDE_HTTP_ACCEPT_LANGUAGE || request.env['HTTP_ACCEPT_LANGUAGE'].to_s end end
Copy
# Override the Accept-Language header for all Cucumber scenarios Before do stub_const('ApplicationController::OVERRIDE_HTTP_ACCEPT_LANGUAGE', 'de') end

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Emanuel De
Last edit:
6 days ago
by Emanuel De
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more