October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Press and Release the Mouse Button With Puppeteer

Use Puppeteer's page.mouse.down() and page.mouse.up() to hold and release a mouse button, or choose a click or locator API when that fits better.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use page.mouse.down() to press a mouse button and page.mouse.up() to release it. Await both calls. The button stays held between them, so you can run other actions during that interval.

Press and release a mouse button

Each Puppeteer Page has a mouse object. Call its down() and up() methods separately when you need explicit control over how long the button remains pressed:

As an Amazon Associate I earn from qualifying purchases.

await page.mouse.down();
// The left button remains held while intervening actions run.
await page.mouse.up();

The default button is left. To use another supported button, pass the same button choice to both calls:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.mouse.down({ button: 'right' });
// Run an action while the right button is held.
await page.mouse.up({ button: 'right' });

Puppeteer documents left, right, middle, back, and forward as button values. Use the same selection on release so the button you pressed is the one you release.

Choose the right interaction API

What you need Use Why
A click at a specific coordinate page.mouse.click(x, y) It is the coordinate-click shortcut for moving to the point, pressing, and releasing.
A press that remains held while other actions run page.mouse.down(), then page.mouse.up() Separate calls give you explicit control over the press and release.
Clicking a page element page.locator(selector).click() Puppeteer’s guide recommends locators; they check that the element is in the viewport, visible, enabled, and has a stable bounding box before clicking.

Use page.mouse when you need mouse events at a position rather than an element-directed click. For ordinary interaction with a known DOM element, a locator can handle the documented readiness checks for you.

Complete example with a reliable release

This example creates a page, presses the left button at a viewport coordinate, runs an intervening action, and releases the button even if that action throws an error. Replace the URL and coordinates with values appropriate to your page.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: true });

  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });

    const x = 200;
    const y = 150;
    await page.mouse.move(x, y);
    await page.mouse.down();

    try {
      // Perform the action that must happen while the button is held.
      await page.waitForTimeout(500);
    } finally {
      await page.mouse.up();
    }
  } finally {
    await browser.close();
  }
})();

The nested finally matters if an intervening operation can fail: without it, execution might skip mouse.up() and leave the input state pressed for later actions on that page. If your Puppeteer version does not provide page.waitForTimeout(), replace that illustrative delay with the real operation you need to perform while holding the button.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand coordinates and event limits

page.mouse coordinates are CSS pixels relative to the main frame’s viewport, with the origin at its top-left corner. They are not document coordinates for the full page. A point’s target can change after scrolling, resizing the viewport, or changing page layout, so establish the desired viewport and page state before choosing coordinates.

Puppeteer’s mouse operations trigger synthetic MouseEvents; they do not reproduce every behavior of a physical mouse. The API documentation specifically notes that page.mouse cannot perform dragging or text selection. If a task depends on those interactions, do not assume that a sequence of down(), movement, and up() will faithfully reproduce a user’s physical input.

Troubleshoot common problems

  • The button seems to remain pressed: Make sure the code reaches and awaits page.mouse.up(). Put the release in a finally block when intervening work may throw.
  • The wrong button is released: Pass the same button option to both down() and up(). If omitted, each call uses the default, left.
  • The action happens at the wrong place: Check that the coordinates are viewport-relative CSS pixels in the main frame, and that the viewport and page layout have not changed since you chose them.
  • A drag or text selection does not behave like a person’s: This is a limitation of Puppeteer’s synthetic mouse events; its documentation says these operations cannot perform dragging or selecting text.
  • An element click is unreliable: Prefer page.locator(selector).click() for a DOM element so Puppeteer can perform its documented visibility, enabled-state, viewport, and bounding-box checks.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to get a screenshot rather than control a held mouse button, ScreenshotNeo returns a page capture from one GET request. It does not replace Puppeteer’s mouse API for pressing and releasing a button.

For example, save a screenshot of Stripe as WebP with cURL:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.