Skip to content

Emulate browser locale (including Accept-Language header, Intl APIs, and Navigator.language) #774

@whimboo

Description

@whimboo

It would be useful if BiDi clients could fully emulate the browser’s locale, including key functionalities such as:

  1. Accept-Language HTTP Headers:

    • Allow the browser to send the appropriate Accept-Language header according to the emulated locale settings.
  2. JavaScript APIs (Date, Intl):

    • Ensure that JavaScript Date and Internationalization APIs (Intl) reflect the correct locale-based formats (e.g., date, currency, numbers).
  3. Navigator.language:

    • Properly simulate the navigator.language value in the emulated environment.

Expected Behavior:

The emulation should consistently apply the locale across:

  • HTTP Headers: Emulating Accept-Language based on the locale.
  • JS APIs: Reflecting the locale in Date formatting and Intl APIs for things like number and currency formatting.
  • Navigator Properties: Ensuring that navigator.language matches the emulated locale.

Use Case:

Many modern web applications use locale information for rendering content, formatting dates/numbers, and providing localized experiences to users. Having full locale emulation is critical for testing applications in different regions and languages to ensure proper functionality.

Potential Implementation:

  1. Accept-Language Header:

    • Similar to the ability to set custom HTTP headers via page.setExtraHTTPHeaders(), but tied to the locale setting of the browser.
  2. Intl and Date APIs:

    • Ensure that JavaScript's Date and Intl APIs automatically reflect the locale and language settings passed during browser initialization (e.g., page.setLocale()).
  3. Navigator.language:

    • Override the navigator.language property so that it correctly reflects the locale setting (e.g., en-US, fr-FR).

Impact:

Implementing this feature would significantly improve localization and internationalization (i18n) testing for web applications, as it would allow a more realistic and complete emulation of how the browser behaves with respect to different locales.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions