@aw1875/ghost-cursor

中文文档
1.1.10发布于 2022/02/16ISCTypeScriptCommonJS近 30 天下载 1704

Move your mouse like a human in puppeteer or generate realistic movements on any 2D plane

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. Puppeteer-specific behavior
  4. How does it work

Ghost Cursor

Generate realistic, human-like mouse movement data between coordinates or navigate between elements with puppeteer like the definitely-not-robot you are.

Oh yeah? Could a robot do this?

Code modifications based off of ghost-cursor package

Installation

yarn add @aw1875/ghost-cursor

or with npm

npm install @aw1875/ghost-cursor

Usage

Generating movement data between 2 coordinates with associated timestamps.

import { path } from "@aw1875/ghost-cursor";

const from = { x: 100, y: 100 };
const to = { x: 600, y: 700 };

const route = path(from, to);

/**
 * [
 *   { x: 100, y: 100, timestamp: 1640158937890 },
 *   { x: 126.70079722115054, y: 106.31184259284494, timestamp: 1640158939620 },
 *   { x: 151.74738386288035, y: 112.34993715686089, timestamp: 1640158939565 },
 *   { x: 175.33112687647585, y: 118.45478710608484, timestamp: 1640158939763 },
 *   { x: 197.6433932132232, y: 124.96689585455373, timestamp: 1640158939408 },
 *   ... and so on
 * ]
 */

Usage with puppeteer:

import { createCursor } from "@aw1875/ghost-cursor";
import puppeteer from "puppeteer";

const run = async (url) => {
  const selector = "#sign-up button";
  const browser = await puppeteer.launch({ headless: false });
  const page = browser.newPage();
  const cursor = createCursor(page);
  await page.goto(url);
  await page.waitForSelector(selector);
  await cursor.click(selector);
  // shorthand for
  // await cursor.move(selector)
  // await cursor.click()
};

Puppeteer-specific behavior

  • cursor.move() will automatically overshoot or slightly miss and re-adjust for elements that are too far away from the cursor's starting point.
  • When moving over objects, a random coordinate that's within the element will be selected instead of hovering over the exact center of the element.
  • The speed of the mouse will take the distance and the size of the element you're clicking on into account.

ghost-cursor in action

Ghost cursor in action on a form

How does it work

Bezier curves do almost all the work here. They let us create an infinite amount of curves between any 2 points we want and they look quite human-like. (At least moreso than alternatives like perlin or simplex noise)

The magic comes from being able to set multiple points for the curve to go through. This is done by picking 2 coordinates randomly in a limited area above and under the curve.

However, we don't want wonky looking cubic curves when using this method because nobody really moves their mouse that way, so only one side of the line is picked when generating random points.

When calculating how fast the mouse should be moving we use Fitts's Law to determine the amount of points we should be returning relative to the width of the element being clicked on and the distance between the mouse and the object.

版本与发布记录

@aw1875/ghost-cursor 共发布 3 个版本,首次发布于 2022/02/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.10latest2022/02/164 年前
1.1.92022/02/164 年前
1.1.82022/02/164 年前

关于 @aw1875/ghost-cursor 的常见问题

@aw1875/ghost-cursor 是什么?

Move your mouse like a human in puppeteer or generate realistic movements on any 2D plane

如何安装 @aw1875/ghost-cursor?

在项目目录运行 npm install @aw1875/ghost-cursor,或使用 pnpm add / yarn add / bun add。

@aw1875/ghost-cursor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aw1875/ghost-cursor 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aw1875/ghost-cursor 可以商用吗?

@aw1875/ghost-cursor 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aw1875/ghost-cursor 的下载量有多少?

根据 npm 官方下载统计,@aw1875/ghost-cursor 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,704 次,日均约 57 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aw1875/ghost-cursor 还在维护吗?

最新版本 1.1.10 发布于 2022/02/16(4 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/02/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。