Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Make init command work without [cli] extras by adding core dependencies
Reagan Hsuc653d21284c7
diff --git a/browser_use/init_cmd.py b/browser_use/init_cmd.pyindex a57504189..92b5a0054 100644--- a/browser_use/init_cmd.py+++ b/browser_use/init_cmd.py@@ -9,6 +9,12 @@ import sysfrom pathlib import Pathimport click+from InquirerPy.base.control import Choice+from InquirerPy.prompts.list import ListPrompt+from InquirerPy.utils import InquirerPyStyle+from rich.console import Console+from rich.panel import Panel+from rich.text import Text# Template metadataINIT_TEMPLATES = {@@ -26,14 +32,28 @@ INIT_TEMPLATES = {},}+# Rich console for styled output+console = Console()++# InquirerPy style for template selection (browser-use orange theme)+inquirer_style = InquirerPyStyle(+ {+ 'pointer': '#fe750e bold',+ 'highlighted': '#fe750e bold',+ 'question': 'bold',+ 'answer': '#fe750e bold',+ 'questionmark': '#fe750e bold',+ }+)+def _write_init_file(output_path: Path, content: str, force: bool = False) -> bool:"""Write content to a file, with safety checks."""# Check if file already existsif output_path.exists() and not force:- click.echo(f'⚠️ File already exists: {output_path}')+ console.print(f'[yellow]⚠[/yellow] File already exists: [cyan]{output_path}[/cyan]')if not click.confirm('Overwrite?', default=False):- click.echo('❌ Cancelled')+ console.print('[red]✗[/red] Cancelled')return False# Ensure parent directory exists@@ -44,7 +64,7 @@ def _write_init_file(output_path: Path, content: str, force: bool = False) -> booutput_path.write_text(content, encoding='utf-8')return Trueexcept Exception as e:- click.echo(f'❌ Error writing file: {e}', err=True)+ console.print(f'[red]✗[/red] Error writing file: {e}')return False@@ -111,16 +131,28 @@ def main(# Interactive template selection if not providedif not template:- click.echo('Available templates:\n')- for name, info in INIT_TEMPLATES.items():- click.echo(f' {name:12} - {info["description"]}')- click.echo()-- template = click.prompt(- 'Which template would you like to use?',- type=click.Choice(['default', 'advanced', 'tools'], case_sensitive=False),+ # Create choices with descriptions+ choices = [+ Choice(+ name=f'{name:12} - {info["description"]}',+ value=name,+ )+ for name, info in INIT_TEMPLATES.items()+ ]++ template = ListPrompt(+ message='Select a template:',+ choices=choices,default='default',- )+ pointer='❯',+ style=inquirer_style,+ instruction='(Use arrow keys)',+ ).execute()++ # Handle user cancellation (Ctrl+C)+ if template is None:+ console.print('\n[red]✗[/red] Cancelled')+ sys.exit(1)# Template is guaranteed to be set at this point (either from option or prompt)assert template is not None@@ -138,20 +170,31 @@ def main(template_path = templates_dir / template_filecontent = template_path.read_text(encoding='utf-8')except Exception as e:- click.echo(f'❌ Error reading template: {e}', err=True)+ console.print(f'[red]✗[/red] Error reading template: {e}')sys.exit(1)# Write fileif _write_init_file(output_path, content, force):- click.echo(f'✅ Created {output_path}')- click.echo('\nNext steps:')- click.echo(' 1. Install browser-use:')- click.echo(' uv pip install browser-use')- click.echo(' 2. Set up your API key in .env file or environment:')- click.echo(' BROWSER_USE_API_KEY=your-key')- click.echo(' (Get your key at https://cloud.browser-use.com/dashboard/api)')- click.echo(' 3. Run your script:')- click.echo(f' python {output_path.name}')+ console.print(f'\n[green]✓[/green] Created [cyan]{output_path}[/cyan]')++ # Create a nice panel for next steps+ next_steps = Text()+ next_steps.append('\n1. Install browser-use:\n', style='bold')+ next_steps.append(' uv pip install browser-use\n\n', style='dim')+ next_steps.append('2. Set up your API key in .env file or environment:\n', style='bold')+ next_steps.append(' BROWSER_USE_API_KEY=your-key\n', style='dim')+ next_steps.append(' (Get your key at https://cloud.browser-use.com/dashboard/api)\n\n', style='dim italic')+ next_steps.append('3. Run your script:\n', style='bold')+ next_steps.append(f' python {output_path.name}\n', style='dim')++ console.print(+ Panel(+ next_steps,+ title='[bold]Next steps[/bold]',+ border_style='#fe750e',+ padding=(1, 2),+ )+ )else:sys.exit(1)diff --git a/pyproject.toml b/pyproject.tomlindex 76c2cd111..a49722e27 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -15,6 +15,8 @@ dependencies = ["anyio>=4.9.0","bubus>=1.5.6","click>=8.1.8",+ "InquirerPy>=0.3.4",+ "rich>=14.0.0","google-api-core>=2.25.0","httpx>=0.28.1","portalocker>=2.7.0,<3.0.0",@@ -58,7 +60,6 @@ dependencies = [[project.optional-dependencies]cli = [- "rich>=14.0.0","textual>=3.2.0",]code = [