Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer screenshot with cursor icon

We are using puppeteers page.screenshot function (https://devdocs.io/puppeteer/index#pagescreenshotoptions) but the resulting captured image doesn't show the current mouse cursor icon. Is there a way to tell puppeteer to include the mouse cursor icon in the captured screenshot?

like image 526
Marek Krzeminski Avatar asked Nov 18 '25 08:11

Marek Krzeminski


1 Answers

install-mouse-helper.js

You can use install-mouse-helper.js to inject a box in the page that moves with the mouse in Puppeteer and is visible in screenshots:

const puppeteer = require('puppeteer');
const {installMouseHelper} = require('./install-mouse-helper');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await installMouseHelper(page); // Install Mouse Helper

  await page.goto('https://example.com/');

  await page.mouse.move(100, 200);
  await page.mouse.down();
  await page.mouse.move(500, 250);

  await page.screenshot({
    path: 'example.png',
  });

  await browser.close();
})();
like image 114
Grant Miller Avatar answered Nov 20 '25 03:11

Grant Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!