A command-line interface for controlling a browser using slash commands with Stagehand.
- Node.js (v16 or higher)
- An API key for either OpenAI or Anthropic (set in
.envfile)
-
Make sure you have the required environment variables set in your
.envfile:OPENAI_API_KEY=your_openai_api_key # OR ANTHROPIC_API_KEY=your_anthropic_api_key -
Install dependencies:
npm install
npm run cli
For debugging mode with more verbose output:
./run-cli.sh
or
DEBUG=true npm run cli
This will start a browser and open a CLI interface where you can enter commands.
/goto <url>- Navigate to a URL/act <instruction>- Perform a complex action using AI/click <selector>- Click on an element/type <selector> <text>- Type text into an element/wait <ms>- Wait for specified milliseconds/screenshot- Take a screenshot/eval <js-code>- Evaluate JavaScript in the browser/info- Show current page info/help- Show available commands/exit- Exit the CLI
/goto https://www.google.com
/type input[name="q"] hello world
/click input[name="btnK"]
/act search for the weather in New York
/screenshot
/info
/exit
Screenshots are saved to the ./screenshots directory with timestamps in the filename.
If you encounter issues:
- Make sure your API keys are correctly set in the
.envfile - Check that you have the latest version of the dependencies
- Try running with
DEBUG=true npm run clifor more verbose output - Common errors:
TypeError: stagehand.goto is not a function- This means you're trying to use a method directly on the Stagehand instance that should be used on the page object. The correct usage isstagehand.page.goto().Error: Browser not initialized- Make sure the browser has been properly initialized before running commands.
This CLI tool uses the Stagehand library, which is built on top of Playwright. It provides a high-level API for browser automation with AI capabilities. The key components are:
- Stagehand Instance: The main entry point for browser automation
- Page Object: Used for most browser interactions like navigation, clicking, typing, etc.
- AI Actions: The
/actcommand uses AI to interpret and execute complex instructions
MIT