1.0.0 • Published 2 years ago

puppeteer-realmouse v1.0.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
2 years ago

puppeteer-realmouse

Realistic mouse visualization and movement for Puppeteer.

Prerequisites

In order to use this plugin:

Installation

To install the plugin to your project please use:

npm install --save puppeteer-realmouse

Manual

Once Puppeteer video recorder is installed, you can require it in your project:

import { Mouse } from 'puppeteer-realmouse';

// Assuming Puppeteer's page object is `page`.
const mouse = new Mouse(page);
await mouse.install();
await page.goto('https://www.google.com');

const acceptButton = await mouse.moveTo('button[id=L2AGLb]', {
    waitAfter: 1000
});
await acceptButton.click();
const input = await mouse.moveTo('input[name=q]', {
    waitBefore: 1000,
    waitAfter: 1000
});

The moveTo method's first argument is a selector. The following selectors are supported:

  • (dict): x and y coordinates, e.g.: { x: 100, y: 200 }
  • (handle): HTML element handle
  • (string): Selector, e.g.: button[id=L2AGLb]
  • (string): XPath selector, e.g.: /html

The moveTo method's second argument an optional dictionary of options. The following options are supported:

  • immediate (optional): Set to true to move the mouse immediately. Realistic movement is not applied.
  • waitForSelector (optional): A number in milliseconds to wait for the item matching the selector to show up.
  • waitBefore (optional): A number representing how long to wait in milliseconds before starting to move the mouse.
  • waitAfter (optional): A number representing how long to wait in milliseconds after the mouse arrived to the destination.

The moveTo method returns:

  • The handle of the HTML element the mouse was moved to in case selector was a string and the element existed. OR,
  • The coordinates as a dictionary if the selector was a dictionary of coordinates.

FAQ

Does it support Chrome in headless mode?

Yes, it supports Chrome in both headless and headful mode.

Does it use the window object?

No, it doesn't use the window object.

Can I run this plugin with my own page/browser objects?

Yes.

Will it change my browser/page/window objects?

It injects some HTML elements and stylesheet into the page for mouse visualization.