Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 Now×
Skip to content
World desk3 min

Set the Browser User Agent with Puppeteer

Use Puppeteer’s page.setUserAgent options object to override a page’s user agent. Learn when device emulation is the better fit and how to avoid common setup errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a Puppeteer page’s user agent with await page.setUserAgent({ userAgent: '…' }), and do it before navigating if the page should receive the override from its first request. This changes the page’s user-agent settings; use device emulation when you also need a known device profile and viewport.

Set a user agent on a Puppeteer page

Use the options-object form of Page.setUserAgent:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.setUserAgent({
    userAgent: 'your user-agent string',
  });
  await page.goto('https://example.com');
  // Continue with page work.
} finally {
  await browser.close();
}

The call returns a promise, so await it before navigating or doing work that depends on the override. Replace the example string with one appropriate to the browser and scenario you intend to represent. The Puppeteer documentation does not specify a universally suitable current string, so avoid treating an arbitrary, hard-coded browser version as authoritative. See the Page.setUserAgent API documentation.

As an Amazon Associate I earn from qualifying purchases.

Optional metadata and platform

The options object can also include userAgentMetadata and platform. For example, add those fields only when you have the corresponding values for the browser scenario being represented:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.setUserAgent({
  userAgent: 'your user-agent string',
  userAgentMetadata: yourUserAgentMetadata,
  platform: 'your platform',
});

The user-agent string alone should not be assumed to reproduce every characteristic of a real browser or device. Consult the installed Puppeteer version’s API documentation for the exact types and supported options.

Choose between a page override and device emulation

Approach What it changes When to use it
page.setUserAgent() The page’s user-agent settings; the options form also supports metadata and platform. When the user-agent override itself is the goal.
page.emulate(device) A known device profile, including user agent and viewport. When you want to emulate a device rather than change only the user-agent settings.

Puppeteer describes page.emulate(device) as a shortcut for setting both the user agent and viewport. Set up emulation before navigation where possible: changing viewport dimensions can affect a page and may trigger a reload in some cases. Device definitions are available through Puppeteer’s KnownDevices list. See the page interaction guide for the emulation guidance.

Install Puppeteer or connect to a managed browser

The page-level user-agent call is the same idea whichever package you use; the difference is browser setup. The installation guide distinguishes the packages this way:

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
  • puppeteer downloads a compatible Chrome version as part of installation.
  • puppeteer-core does not download Chrome. Use it when connecting to a remote browser or managing browser binaries separately.

Choose the package that matches how Chrome is supplied in your environment, then apply the override to the page you will navigate.

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

Troubleshoot user-agent overrides

  • The page still sends its old user agent: Make sure you call and await page.setUserAgent() on the same page before navigation or other dependent work.
  • You need a mobile layout, not just a different user-agent string: A string override is not a complete device profile. Use page.emulate(device) when the viewport and known device settings matter, and configure it before navigation where possible.
  • An older example fails against your installed package: API signatures can change. Check the documentation for the Puppeteer version you installed; the current API uses an options object, and the Next documentation marks a legacy positional signature as obsolete.
  • Chrome does not launch with puppeteer-core: That package does not download a browser. Supply or connect to a browser separately, or use puppeteer if its bundled compatible Chrome setup fits your needs.
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 task is to capture a website rather than run a Puppeteer workflow, ScreenshotNeo offers a website screenshot API and MCP server. One GET request can return a screenshot or PDF; for example, the API call below requests a WebP shot:

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 and consent banners, newsletter popups, and chat widgets are handled before capture and can be disabled individually. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers indicate the page verdict and whether the capture was billed. Its MCP server gives AI agents screenshot, page-info, and PDF-capture tools. The free plan includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month with no card.

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 *

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.

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
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.