agent-cursor
Version:
A programmatic cursor control library for AI agents and browser automation to interact with web pages
238 lines (160 loc) โข 5.91 kB
Markdown
//badge.fury.io/js/agent-cursor.svg)](https://www.npmjs.com/package/agent-cursor)
[](https://opensource.org/licenses/MIT)
A programmatic cursor control library that enables AI agents and automation scripts to visually interact with web pages. Perfect for building browser automation tools, AI agents, and demonstrating automated workflows.
- ๐ค **AI Agent Control**: Programmatic cursor control for AI agents to interact with web UIs
- ๐ฏ **Complete Form Automation**: Type text, select dropdowns, check boxes, select radios
- ๐ฑ๏ธ **Visual Cursor**: SVG cursor with smooth transitions for visual feedback
- ๐จ **Customizable**: Color, size, speed, and movement behavior
- ๐ฆ **TypeScript support** with full type definitions
- ๐ **Zero dependencies** (pure TypeScript)
- ๐ซ **Real DOM events** for genuine browser interaction
```bash
npm install agent-cursor
```
```typescript
import { AgentCursor } from 'agent-cursor';
// Create cursor instance
const cursor = new AgentCursor({
color: '#646cff',
size: 24,
speed: 400,
});
// Move to an element
const button = document.getElementById('myButton');
await cursor.moveToElement(button);
// Click it
await cursor.click(button);
// Type into an input
const input = document.getElementById('email');
await cursor.type(input, 'user@example.com');
// Clean up when done
cursor.destroy();
```
```typescript
interface AgentCursorOptions {
speed?: number; // Movement speed in pixels/second (default: 300)
size?: number; // Cursor size in pixels (default: 20)
color?: string; // Cursor color (default: '#646cff')
jitter?: number; // Random movement jitter in pixels (default: 2)
}
```
Move cursor to specific coordinates.
```typescript
await cursor.moveTo(100, 200);
```
Move cursor to the center of an element.
```typescript
const button = document.querySelector('button');
await cursor.moveToElement(button);
```
Click at current position or on a specific element.
```typescript
await cursor.click(button);
```
Type text character-by-character into an input field.
```typescript
const emailInput = document.querySelector('#email');
await cursor.type(emailInput, 'user@example.com');
```
Select a dropdown option by index.
```typescript
const countrySelect = document.querySelector('#country');
await cursor.selectByIndex(countrySelect, 3); // Select 4th option
```
Check or uncheck a checkbox.
```typescript
const terms = document.querySelector('#terms');
await cursor.selectCheckbox(terms, true);
```
Select a radio button.
```typescript
const option = document.querySelector('input[name="plan"][value="premium"]');
await cursor.selectRadio(option);
```
Remove the cursor and clean up resources.
```typescript
cursor.destroy();
```
```typescript
import { AgentCursor } from 'agent-cursor';
const cursor = new AgentCursor({ color: '#646cff' });
// Fill login form
const emailInput = document.querySelector('#email');
await cursor.type(emailInput, 'user@example.com');
const passwordInput = document.querySelector('#password');
await cursor.type(passwordInput, 'password123');
const rememberMe = document.querySelector('#remember');
await cursor.selectCheckbox(rememberMe, true);
const loginButton = document.querySelector('#login-btn');
await cursor.click(loginButton);
cursor.destroy();
```
```typescript
const cursor = new AgentCursor();
await cursor.type(document.querySelector('#name'), 'John Doe');
await cursor.type(document.querySelector('#email'), 'john@example.com');
await cursor.selectByIndex(document.querySelector('#country'), 2);
await cursor.selectCheckbox(document.querySelector('#terms'), true);
await cursor.click(document.querySelector('#submit'));
cursor.destroy();
```
**Live Demo:** [https://rajasekarm.github.io/agent-cursor/](https://rajasekarm.github.io/agent-cursor/)
Run the demo locally:
```bash
git clone https://github.com/rajasekarm/agent-cursor.git
cd agent-cursor
npm install
npm run dev
```
Visit `http://localhost:5173/demo/index.html` to see the demo in action.
- ๐ค **AI Agents**: Enable AI agents to visually interact with web interfaces
- ๐ **Browser Automation**: Automate repetitive browser tasks with visual feedback
- ๐งช **Testing**: Visualize automated test flows and UI interactions
- ๐น **Demo & Training**: Create visual demonstrations of user workflows
- ๐ฏ **Web Scraping**: Interact with dynamic web pages that require user actions
- ๐ง **RPA (Robotic Process Automation)**: Automate business processes in web applications
Works in all modern browsers that support:
- ES2020
- CSS Transitions
- SVG
MIT ยฉ Rajasekarm
Contributions are welcome! Please feel free to submit a Pull Request.
```bash
git clone https://github.com/rajasekarm/agent-cursor.git
cd agent-cursor
npm install
npm run dev
```
```bash
npm run build
```
See [PUBLISHING.md](PUBLISHING.md) for detailed publishing instructions using GitHub Actions.
[ ](https://github.com/rajasekarm/agent-cursor)
[![npm version](https: