Move your mouse like a human in puppeteer or generate realistic movements on any 2D plane, this version has support for iframes
npm install ghost-cursor-frames
sh
yarn add ghost-cursor-frames
`
or with npm
`sh
npm install ghost-cursor-frames
`
Usage
Generating movement data between 2 coordinates.
`js
import { path } from "ghost-cursor-frames"
const from = { x: 100, y: 100 }
const to = { x: 600, y: 700 }
const route = path(from, to)
/**
* [
* { x: 100, y: 100 },
* { x: 108.75573501957051, y: 102.83608396351725 },
* { x: 117.54686481838543, y: 106.20019239793275 },
* { x: 126.3749821408895, y: 110.08364505509256 },
* { x: 135.24167973152743, y: 114.47776168684264 }
* ... and so on
* ]
*/
`
Usage with puppeteer:
`js
import { createCursor } from "ghost-cursor-frames"
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()
}
`
Usage with iframes:
`js
import { createCursor } from "ghost-cursor-frames"
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)
const elementHandle = await page.$("frameSelector");
const frame = await elementHandle.contentFrame();
await cursor.click(selector, {}, frame)
}
`
$3
* cursor.move()` will automatically overshoot or slightly miss and re-adjust for elements that are too far away