Skip to content

feat(browser): make the Cloak browser locale configurable - #839

Open
Huy3ko wants to merge 1 commit into
Panniantong:mainfrom
Huy3ko:fix/browser-locale-configurable
Open

Huy3ko wants to merge 1 commit into
Panniantong:mainfrom
Huy3ko:fix/browser-locale-configurable

Conversation

@Huy3ko

@Huy3ko Huy3ko commented Oct 23, 2026

Copy link
Copy Markdown

Problem

The Cloak persistent context is launched with a hardcoded locale:

ctx = launch_persistent_context(
    str(browser.profile_dir()), headless=headless, locale="zh-CN",

Every page the browser renders therefore appears in Chinese — including
Reddit, where the login form and the whole UI came up in Chinese for a user
whose own language is not Chinese. There is no way to change it: the setting
is not exposed through the config file, the environment, or any CLI flag.

Change

The launch code already reads runtime settings from the Agent Reach config
(the proxy option is resolved the same way), so the locale belongs there too.

def _browser_locale() -> str:
    from agent_reach.config import Config

    value = Config(read_only=True).get("browser_locale")
    if isinstance(value, str) and value.strip():
        return value.strip()
    return "zh-CN"

Users set it with the browser_locale config key or the BROWSER_LOCALE
environment variable:

agent-reach config set browser_locale en-US   # or: export BROWSER_LOCALE=en-US

The default stays zh-CN, so existing setups keep their current
behaviour and nothing changes for current users.

Scope

This is the locale of the rendered web pages. It is separate from
AGENT_REACH_LANG, which selects the language of the CLI output
(see #595). The two are complementary and do not overlap.

Tests

tests/test_browser_locale.py covers the default, the config key, the env
var, and the blank-value case. The new tests fail against the unchanged
source (assert 'zh-CN' == 'en-US') and pass with the change.

Validation

$ ruff check agent_reach tests
All checks passed!

$ pytest -q
480 passed in 19.89s

Live check on this machine with browser_locale=en-US:

$ agent-reach check reddit --text
  PASS  reddit search [opencli] 8717ms
  PASS  reddit subreddit [opencli] 5390ms

  2/2 actions working

Measured in the running browser before and after the change:

before:  navigator.language = "zh-CN"   navigator.languages = ["zh-CN"]
after:   navigator.language = "en-US"   navigator.languages = ["en-US"]

Notes

  • The locale is passed to the Cloak launcher only. The legacy Chrome pipe
    path is untouched.
  • The change is additive: no existing key, flag or behaviour is renamed or
    removed.

The Cloak persistent context was launched with a hardcoded locale="zh-CN",
so every site the browser rendered appeared in Chinese regardless of the
user's own language. The launch code already reads other runtime settings
from the Agent Reach config (see the proxy option), so the locale belongs
there too.

The locale can now be set with the browser_locale config key or the
BROWSER_LOCALE environment variable, e.g. en-US or de-DE. The default
stays zh-CN, so existing setups keep their current behaviour.

Note this is the locale of the rendered web pages. It is separate from
AGENT_REACH_LANG, which selects the language of the CLI output.

Validation:
- pytest -q - 480 passed
- ruff check agent_reach tests - all checks passed
- live check on this machine: agent-reach check reddit --text passes 2/2
  with browser_locale=en-US
@anilonayy

Copy link
Copy Markdown

+1, hit the same thing on Linux: the Instagram login window came up entirely in Chinese for a Turkish-locale user.

Two things from trying this against 1.6.0:

  1. The documented setter doesn't exist yet. agent-reach config set ... is not a command (unknown command or channel: config), and agent-reach configure browser_locale en-US returns unknown key: browser_locale; valid: groq-key, openai-key, proxy, github-token. So today the only working route is the BROWSER_LOCALE env var (I confirmed Config(read_only=True).get("browser_locale") picks it up). Adding "browser-locale": "browser_locale" to CONFIG_KEYS in runtime/manage.py, or updating the PR description to point at the env var, would close that gap.

  2. Suggestion: fall back to the user's language before zh-CN. Most people who hit this never set anything, so the default is what matters. The skill already picks its language from AGENT_REACH_LANG / LC_ALL / LC_MESSAGES / LANG (_skill_lang in manage.py); the browser could use the same order when browser_locale is unset:

def _system_locale() -> str:
    for var in ("AGENT_REACH_LANG", "LC_ALL", "LC_MESSAGES", "LANG"):
        v = os.environ.get(var, "").split(".")[0].split("@")[0].strip()
        if v and v not in ("C", "POSIX"):
            return v.replace("_", "-")
    return "zh-CN"

tr_TR.UTF-8 → tr-TR, en_US.UTF-8 → en-US, de_DE@euro → de-DE, AGENT_REACH_LANG=en → en; unset, C.UTF-8 and POSIX keep zh-CN, so Chinese-locale setups behave exactly as before.

Happy to send this as a follow-up PR on top of this one if that's easier to review separately.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants