User Agents

Web browsers and everyday web tech, explained

Why Puppeteer Shows Different Views Than Browsers

· 5 min read · Browsers

In this article
  1. Background: What Puppeteer Actually Is
  2. Key Differences That Change the View
  3. How to Diagnose the Difference
  4. How to Make Puppeteer Match a Regular Browser
  5. Common Problems and Misconceptions
  6. When the Difference Matters
  7. Alternatives and Related Tools
  8. Frequently Asked Questions

Websites often display differently in Puppeteer than in a regular browser because Puppeteer launches a separate, isolated Chromium instance with its own browser profile, viewport size, device settings, and automation flags—so the page receives different signals about your environment and renders accordingly. This is not a bug; it is the expected result of Puppeteer being a distinct browser context, and understanding the specific differences lets you control them.

Background: What Puppeteer Actually Is

Puppeteer is a Node.js library that controls a headless (or headful) Chromium browser via the DevTools Protocol. It does not modify the web itself—it simply starts a real Chromium binary, opens a tab, and lets you script navigation, clicks, and screenshots. Because it is a real browser engine, it renders HTML, CSS, and JavaScript almost identically to Chrome. The differences you see come from the environment Puppeteer creates by default, not from a different rendering engine.

Key Differences That Change the View

  • Viewport size: Puppeteer’s default viewport is 800×600 pixels, whereas a typical desktop browser window is much larger. Responsive layouts, media queries, and lazy-loading images react to this size.
  • Device scale factor and touch support: By default, Puppeteer reports a scale factor of 1 and no touch events. Mobile sites that detect touch or high-DPI screens will behave differently.
  • User agent string: Puppeteer’s default user agent includes “HeadlessChrome” (e.g., HeadlessChrome/120.0.0.0). Many sites serve different content or disable features for headless browsers.
  • Browser profile and cookies: Puppeteer starts with a fresh, empty profile—no extensions, no saved logins, no cookies. A regular browser has your history, cookies, and possibly ad-blockers that alter the page.
  • JavaScript timers and animations: Headless mode may throttle timers or skip animations depending on the page’s visibility state. Puppeteer’s default waitUntil setting can also stop before images or fonts finish loading.
  • GPU and hardware acceleration: Headless Chromium often disables GPU acceleration, which can change how certain CSS effects, videos, or canvas elements render.

How to Diagnose the Difference

  1. Open the same URL in your regular browser and in Puppeteer (with headless: false to see the window).
  2. Right-click in Puppeteer’s window and choose “Inspect” to open DevTools—check the device toolbar and the network tab.
  3. Compare the user agent string (in the Network tab’s request headers) and the viewport dimensions (in the console, run window.innerWidth and window.innerHeight).
  4. Look for console errors or failed network requests—Puppeteer may block or fail to load resources that your regular browser has cached.
  5. If the difference persists, screenshot both and compare the HTML DOM (e.g., document.documentElement.outerHTML) to see if the server sent different markup.

How to Make Puppeteer Match a Regular Browser

You can override most of the default differences with Puppeteer’s options:

  • Set a realistic viewport: Use page.setViewport({ width: 1920, height: 1080 }) or match your target device.
  • Set a custom user agent: page.setUserAgent('Mozilla/5.0 ... Chrome/120.0.0.0 Safari/537.36')—but be aware some sites still detect headless via other signals.
  • Enable touch and mobile emulation: Use page.emulate({ viewport, userAgent, hasTouch: true, isMobile: true }) for mobile views.
  • Use a persistent profile: Launch with userDataDir pointing to a folder with your cookies or logins.
  • Disable headless mode: Run with headless: false to see the actual window—this often fixes GPU and timer differences.
  • Wait for network idle: Use waitUntil: 'networkidle0' to ensure all resources load before screenshotting.

Common Problems and Misconceptions

A frequent misconception is that Puppeteer “breaks” websites. In reality, the site is responding to the environment Puppeteer presents. For example, a site might show a cookie consent banner only when it detects no existing cookies—Puppeteer’s fresh profile will always see that banner. Another common issue is that a site’s A/B testing or geolocation scripts may serve different variants based on IP or headers. Also, some sites intentionally block headless browsers by checking for navigator.webdriver (which is true in Puppeteer by default). You can’t fully hide this flag without patching Chromium, so some sites will always behave differently.

When the Difference Matters

If you are using Puppeteer for automated testing, you generally want it to match a real user’s environment—so set the viewport, user agent, and profile accordingly. For web scraping, you may actually want the headless default to avoid loading heavy assets. For screenshot services, you need to replicate the exact device you are targeting. The key is to know which differences are intentional (e.g., fresh profile) and which are accidental (e.g., viewport too small).

If Puppeteer’s differences are too troublesome, consider Playwright, which has similar automation but offers better default emulation options and a more consistent user agent. Selenium with ChromeDriver is another option, though it has its own quirks. For simple screenshots, you might use a headless browser directly via command line (e.g., chrome --headless --screenshot) but that gives you even less control. The underlying principle remains the same: any automated browser is a separate instance with its own context.

Frequently Asked Questions

Why does Puppeteer show a mobile version of a site when I’m on desktop?

This usually happens because Puppeteer’s default viewport is 800×600, which may trigger a responsive breakpoint that the site treats as “mobile.” Check your viewport size and set it to a desktop width.

Why are images missing in Puppeteer screenshots?

Images may not load if the page’s lazy-loading script waits for scroll events or if the network is still busy when you take the screenshot. Use waitUntil: 'networkidle0' and scroll through the page before capturing.

Can I make Puppeteer use my existing Chrome profile?

Yes, launch Puppeteer with userDataDir pointing to your Chrome profile folder, but note that Chrome may lock the profile if it’s already running. It’s safer to copy the profile or use a dedicated automation profile.

Why does a site show a “headless browser detected” error?

The site is likely checking for navigator.webdriver or the HeadlessChrome user agent. You can override the user agent, but the webdriver flag is not easily disabled without patching Chromium. Some sites also use more advanced fingerprinting.

Does Puppeteer support JavaScript and CSS the same as Chrome?

Yes, because it uses the same Chromium engine. The differences are environmental, not rendering-based. If a page looks completely broken, check for console errors or missing fonts.