Skip to content

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

added listing functionality if no template is provided

Reagan Hsu536600678f8e
diff --git a/browser_use/cli.py b/browser_use/cli.py
index a7f87c79b..6c4020b71 100644
--- a/browser_use/cli.py
+++ b/browser_use/cli.py
@@ -37,8 +37,25 @@ if len(sys.argv) > 1 and sys.argv[1] == 'install':
# Check for init subcommand early to avoid loading TUI dependencies
if 'init' in sys.argv:
+ from browser_use.init_cmd import INIT_TEMPLATES
from browser_use.init_cmd import main as init_main
+ # Check if --template or -t flag is present without a value
+ # If so, just remove it and let init_main handle interactive mode
+ if '--template' in sys.argv or '-t' in sys.argv:
+ try:
+ template_idx = sys.argv.index('--template') if '--template' in sys.argv else sys.argv.index('-t')
+ template = sys.argv[template_idx + 1] if template_idx + 1 < len(sys.argv) else None
+
+ # If template is not provided or is another flag, remove the flag and use interactive mode
+ if not template or template.startswith('-'):
+ if '--template' in sys.argv:
+ sys.argv.remove('--template')
+ else:
+ sys.argv.remove('-t')
+ except (ValueError, IndexError):
+ pass
+
# Remove 'init' from sys.argv so click doesn't see it as an unexpected argument
sys.argv.remove('init')
init_main()
@@ -59,7 +76,18 @@ if '--template' in sys.argv:
except (ValueError, IndexError):
template = None
- if not template or template not in INIT_TEMPLATES:
+ # If template is not provided or is another flag, use interactive mode
+ if not template or template.startswith('-'):
+ # Redirect to init command with interactive template selection
+ from browser_use.init_cmd import main as init_main
+
+ # Remove --template from sys.argv
+ sys.argv.remove('--template')
+ init_main()
+ sys.exit(0)
+
+ # Validate template name
+ if template not in INIT_TEMPLATES:
click.echo(f'❌ Invalid template. Choose from: {", ".join(INIT_TEMPLATES.keys())}', err=True)
sys.exit(1)
diff --git a/browser_use/init_cmd.py b/browser_use/init_cmd.py
index 840d98972..137a383ec 100644
--- a/browser_use/init_cmd.py
+++ b/browser_use/init_cmd.py
@@ -108,6 +108,7 @@ def main(
\b
# Interactive mode - prompts for template selection
uvx browser-use init
+ uvx browser-use init --template
\b
# Generate default template
@@ -124,9 +125,10 @@ def main(
# Handle --list flag
if list_templates:
- click.echo('Available templates:\n')
+ console.print('\n[bold]Available templates:[/bold]\n')
for name, info in INIT_TEMPLATES.items():
- click.echo(f' {name:12} - {info["description"]}')
+ console.print(f' [#fe750e]{name:12}[/#fe750e] - {info["description"]}')
+ console.print()
return
# Interactive template selection if not provided