A realistic, human-like virtual cursor for end-to-end testing, interactive tutorials, frontend automation, and demonstration purposes. Cursor.js mimics human cursor movements using mathematical Bezier curves (inspired by Fitts's Law) and executes synthetic native browser events (like mousedown, click, input, etc.) accurately to provide an experience close to Playwright and Cypress directly inside the DOM.
- Human-like Movements: Natural cursor sweeping and easing using Bezier curves.
- Native Event Dispatching: Accurately simulates real DOM events (
mouseenter,click,input). - Framework Agnostic: Works purely with vanilla JS, making it compatible with React, Vue, Angular, or plain HTML.
- Chainable API: Easy-to-use, robust, and async-friendly promise-based action queue.
- Visual Cursor: Seamlessly adapts to window scrolling and resizing with out-of-bounds indicators.
Install cursor.js via npm, yarn, or pnpm.
npm install cursor.jsImport the Cursor class and initialize it with your desired options:
import { Cursor } from 'cursor.js';
const cursor = new Cursor({
humanize: true,
showIndicator: true,
speed: 0.5,
});Cursor.js provides a robust, chainable, and async-friendly promise-based API. You can easily sequence actions like hovering, clicking, and typing.
// Chaining and async/await style support
await cursor
.hover('#submit-btn')
.wait(500)
.click('#submit-btn')
.type('.search-input', 'Hello World', { delay: 50 });We welcome contributions to cursor.js! Since this project is a Turborepo monorepo and uses Changesets for version management, please follow these steps when proposing changes:
- Fork the repo and create a new branch from
main(e.g.,feat/my-new-featureorfix/button-click). - Make your code changes and add your tests.
- Run
pnpm changesetin the root of the repository.- Select the package(s) you modified.
- Choose the bump type (major, minor, or patch).
- Write a short summary of your changes (this will appear in the
CHANGELOG.md).
- Commit your changes along with the generated
.changeset/*.mdfile. - Open a Pull Request! Our automated system will take care of the rest.
- Visual Layer (
packages/core/src/core/GhostCursor.ts): Renders a virtual mouse cursor (#virtual-cursor) on the DOM usingposition: absolute. It seamlessly adapts to window scrolling and resizing, matching absolute coordinates(pageX, pageY). Includes an "out of bounds" indicator for tracking the cursor when it scrolls outside the viewport. - Engine & Queue (
packages/core/src/Cursor.ts): A robust, chainable, and async-friendly promise-based action queue. Features declarative methods like.hover(),.click(), and.type(). Handles delays and humanized animation frames. - Event Dispatcher (
packages/core/src/core/EventDispatcher.ts): Directly interfaces with DOM to dispatch realMouseEventandEventclasses. It triggers syntheticmouseenter/mouseleaveto simulate hover states via CSS classes (.cursor-hover). Also overrides the React 16+ Native value setter hack to trigger robust input/change simulation. - Math Utilities (
packages/core/src/core/utils.ts): Contains algorithms (like Bezier curve logic) required for humanized sweeping and ease-out approximations.
MIT