DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

How to Set a Custom User Agent for Website Screenshots in Puppeteer

Use Puppeteer’s page.setUserAgent() before navigation, then capture with page.screenshot(). Learn when device emulation is a better fit and how screenshot options affect the result.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call and await page.setUserAgent() before navigating, then capture the page with page.screenshot(). That changes the user-agent value sent by the page; it does not by itself reproduce a real device’s viewport or full fingerprint.

Set the user agent before navigation

This ES module example launches Puppeteer, overrides the page’s user agent, waits for the page to reach networkidle2, and saves a full-page PNG:

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

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

  await page.setUserAgent('ExampleBot/1.0 (+https://example.com/bot)');
  await page.goto('https://example.com', { waitUntil: 'networkidle2' });
  await page.screenshot({ path: 'screenshot.png', fullPage: true });
} finally {
  await browser.close();
}

The user-agent string is illustrative, not an identity for a real crawler or browser. Replace it with the exact value appropriate to your test or documented client. Await the setter so the override is applied before the request to the site. See Puppeteer’s Page.setUserAgent() reference and screenshots guide.

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

Use the signature supported by your installed version

The current API reference documents an options-object form, with userAgent and optional userAgentMetadata and platform. The reference also exposes a positional signature and marks a warning obsolete, so older code and current documentation may differ. Check the reference matching your installed Puppeteer version; do not combine signatures from different versions. The API reference lists versioned documentation at pptr.dev/api.

Choose between a user-agent override and device emulation

Use setUserAgent() when the only change you need is the page’s user-agent value. If you want a known mobile or other device layout, use Puppeteer’s KnownDevices entry and page.emulate(device) instead. The documented emulation shortcut sets both the device user agent and viewport. Apply emulation before navigating, since resizing can affect a site’s layout. It is not a guarantee of complete real-device fingerprint simulation. See the Page class reference.

Control the screenshot independently

The user-agent override determines the value sent for the page; screenshot options determine the image output. Puppeteer documents these useful options:

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
  • path saves the image. If you do not set an explicit type, Puppeteer infers it from the filename extension.
  • fullPage: true requests a full-page capture; the documented default is false.
  • clip captures a selected region instead of the whole page.
  • type selects an output format. quality applies where supported, but not to PNG.

These settings are independent of the user-agent override. Consult Puppeteer’s ScreenshotOptions reference for the installed version’s available settings.

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.

Troubleshoot unexpected results

  • The site still sees the previous user agent: Make sure you call and await page.setUserAgent() before page.goto(). The setter is asynchronous.
  • The mobile screenshot still has a desktop layout: A user-agent override alone does not set a mobile viewport. Use page.emulate(device) with a Puppeteer KnownDevices entry before navigation when you need the documented device user agent and viewport together.
  • Your code rejects or the method signature does not match: Check the API reference for the Puppeteer version installed in your project. The current reference’s options form and older positional signatures should not be mixed.
  • The saved image is not the expected size or format: Check the filename extension, type, fullPage, and clip. Output controls do not change the page’s user agent.
  • networkidle2 does not suit the page: Some pages keep network connections open or load content after navigation. Choose a navigation wait condition appropriate to the page, then capture only after the content you need is present; Puppeteer’s screenshots guide covers the capture workflow.

Or skip the browser setup

ScreenshotNeo takes a screenshot with one GET request. Its API accepts a URL and returns an image or PDF; use the custom user_agent option if you need to send a particular user-agent value. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://example.com 
  -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture, with each step configurable. Bot checks, blank pages, and failed loads are never billed; response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

FAQ

Does Browser.userAgent() return the override?

Puppeteer documents Browser.userAgent() as reporting the browser’s original user agent; pages can override it with Page.setUserAgent(). See the Browser.userAgent() reference.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

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.

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

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.