A Node.js Express API that allows controlling a browser with natural language commands.
- Natural language browser control
- Automatic website login handling
- Search on various search engines
- Navigate to URLs
- Click on elements
- Type text into forms
- Take screenshots
- Scroll pages
- Multiple browser sessions
- Input validation
- Configurable website selectors
- Node.js 14+
- npm or yarn
- Chrome browser installed
- Clone the repository
- Install dependencies:
npm install
- Update the .env file with your Chrome executable path and website credentials
- Start the server:
npm run dev
- POST /api/interact - Execute a natural language command
{ "command": "string", // Required: The natural language command to execute "sessionId": "string" // Optional: UUID v4 of an existing session }
-
POST /api/sessions - Create a new browser session
{ "options": { "headless": boolean, // Optional: Run in headless mode "incognito": boolean // Optional: Use incognito mode } }
-
GET /api/sessions - Get all active browser sessions
-
GET /api/sessions/:sessionId - Get details for a specific session
- Requires valid UUID v4 sessionId
-
DELETE /api/sessions/:sessionId - Close a specific browser session
- Requires valid UUID v4 sessionId
-
GET /api/sessions/:sessionId/screenshot - Take a screenshot of the current page
- Requires valid UUID v4 sessionId
-
Navigate and login to LinkedIn:
{ "command": "go to linkedin and login" }
-
Search on LinkedIn:
{ "command": "search for 'software engineer' on linkedin" }
-
Like the first post:
{ "command": "like the first post", "sessionId": "previously-created-session-id" }
The API uses a configuration file (config/websiteSelectors.json
) to manage selectors for different websites. This allows for:
- Consistent element targeting
- Easy maintenance when websites change
- Support for multiple websites
- Reusable selector definitions
The API includes comprehensive error handling:
- Input validation for all endpoints
- Session validation
- Detailed error messages
- HTTP status codes that accurately reflect the error type
To add support for new websites:
- Add selectors to
config/websiteSelectors.json
- Test the selectors with natural language commands
- Update documentation if adding new command patterns
- Uses helmet for security headers
- Input validation on all endpoints
- Environment variables for sensitive data
- CORS enabled
- Session-based browser management