Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

feat: add browser-use config command (set, get, list, unset)

ShawnPanac19a9a5b1b22
diff --git a/browser_use/skill_cli/config.py b/browser_use/skill_cli/config.py
index db2cbbefb..c57bbc968 100644
--- a/browser_use/skill_cli/config.py
+++ b/browser_use/skill_cli/config.py
@@ -83,6 +83,39 @@ def get_config_value(key: str) -> object:
return schema.get('default')
+def set_config_value(key: str, value: str) -> None:
+ """Set a config value. Validates key and coerces type."""
+ schema = CONFIG_KEYS.get(key)
+ if schema is None:
+ raise ValueError(f'Unknown config key: {key}. Valid keys: {", ".join(CONFIG_KEYS)}')
+
+ # Coerce type
+ expected_type = schema.get('type', str)
+ try:
+ if expected_type == int:
+ coerced = int(value)
+ else:
+ coerced = str(value)
+ except (ValueError, TypeError):
+ raise ValueError(f'Invalid value for {key}: expected {expected_type.__name__}, got {value!r}')
+
+ config = read_config()
+ config[key] = coerced
+ write_config(config)
+
+
+def unset_config_value(key: str) -> None:
+ """Remove a config key from the file."""
+ schema = CONFIG_KEYS.get(key)
+ if schema is None:
+ raise ValueError(f'Unknown config key: {key}. Valid keys: {", ".join(CONFIG_KEYS)}')
+
+ config = read_config()
+ if key in config:
+ del config[key]
+ write_config(config)
+
+
def get_config_display() -> list[dict]:
"""Return config state for display (doctor, setup).
diff --git a/browser_use/skill_cli/main.py b/browser_use/skill_cli/main.py
index 8e02a7e30..734201c8c 100755
--- a/browser_use/skill_cli/main.py
+++ b/browser_use/skill_cli/main.py
@@ -691,6 +691,18 @@ Setup:
# doctor
subparsers.add_parser('doctor', help='Check browser-use installation and dependencies')
+ # config
+ config_p = subparsers.add_parser('config', help='Manage CLI configuration')
+ config_sub = config_p.add_subparsers(dest='config_command')
+ p = config_sub.add_parser('set', help='Set a config value')
+ p.add_argument('key', help='Config key')
+ p.add_argument('value', help='Config value')
+ p = config_sub.add_parser('get', help='Get a config value')
+ p.add_argument('key', help='Config key')
+ config_sub.add_parser('list', help='List all config values')
+ p = config_sub.add_parser('unset', help='Remove a config value')
+ p.add_argument('key', help='Config key')
+
# -------------------------------------------------------------------------
# Browser Control Commands
# -------------------------------------------------------------------------
@@ -1261,6 +1273,50 @@ def main() -> int:
return 0
+ # Handle config command
+ if args.command == 'config':
+ from browser_use.skill_cli.config import CLI_DOCS_URL, get_config_display, get_config_value, set_config_value, unset_config_value
+
+ config_cmd = getattr(args, 'config_command', None)
+
+ if config_cmd == 'set':
+ try:
+ set_config_value(args.key, args.value)
+ print(f'{args.key} = {args.value}')
+ except ValueError as e:
+ print(f'Error: {e}', file=sys.stderr)
+ return 1
+
+ elif config_cmd == 'get':
+ val = get_config_value(args.key)
+ if val is not None:
+ print(val)
+ else:
+ print(f'{args.key}: not set', file=sys.stderr)
+
+ elif config_cmd == 'unset':
+ try:
+ unset_config_value(args.key)
+ print(f'{args.key} removed')
+ except ValueError as e:
+ print(f'Error: {e}', file=sys.stderr)
+ return 1
+
+ elif config_cmd == 'list' or config_cmd is None:
+ entries = get_config_display()
+ print(f'Config ({_get_home_dir() / "config.json"}):')
+ for entry in entries:
+ if entry['is_set']:
+ icon = '✓'
+ val = 'set' if entry['sensitive'] else entry['value']
+ else:
+ icon = '○'
+ val = entry['value'] if entry['value'] else 'not set'
+ print(f' {icon} {entry["key"]}: {val}')
+ print(f' Docs: {CLI_DOCS_URL}')
+
+ return 0
+
# Handle tunnel command - runs independently of browser session
if args.command == 'tunnel':
from browser_use.skill_cli import tunnel