Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog › browser automation

How to Take Screenshots of a Website That Requires Login with Chrome Headless

By Freedom251 Team · · 6 min read

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

Use Puppeteer with current Headless Chrome: authenticate through the site’s normal login flow or a dedicated signed-in browser profile, verify that the protected content has rendered, then save it with page.screenshot(). Headless mode does not log you in by itself. For a one-off capture without interactive login, Chrome’s --headless --screenshot command can capture a URL, but Puppeteer is better suited to form logins, session handling, and checking that the right page is visible.

Capture an authenticated page with Puppeteer

The login fields, submit button, and content selector vary by site. Replace the example URL and selectors below with the ones for the site you are authorized to access. Store credentials in environment variables or another secret store, not in source code.

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

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

try {
  const page = await browser.newPage();
  await page.setViewport({ width: 1440, height: 1000 });

  await page.goto('https://example.com/login', {
    waitUntil: 'domcontentloaded',
  });

  await page.locator('input[name="username"]').fill(process.env.SITE_USER);
  await page.locator('input[name="password"]').fill(process.env.SITE_PASSWORD);
  await page.locator('button[type="submit"]').click();

  // Wait for a site-specific indication that login succeeded.
  await page.waitForSelector('[data-testid="signed-in-marker"]');

  await page.goto('https://example.com/account/report', {
    waitUntil: 'domcontentloaded',
  });
  await page.waitForSelector('[data-testid="report-content"]');

  await page.screenshot({ path: 'authenticated-page.png', fullPage: true });
} finally {
  await browser.close();
}

This example uses Puppeteer’s locator API and modern JavaScript modules. Install Puppeteer in your project using its current installation instructions, and run the script in an environment where Chrome can launch. The selectors are illustrative, not a universal login recipe: the site may use different fields, additional redirects, multi-factor authentication, or an identity provider.

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

Choose how the browser gets its session

Perform the site’s normal login flow

Use the intended form or identity-provider flow, then wait for a marker that appears only after successful sign-in. MFA and SSO behavior is site-specific; do not assume that filling a username and password completes those flows.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Reuse a dedicated persistent profile

Puppeteer’s userDataDir launch option lets Chrome use a browser user-data directory that can retain session state between runs. For unattended capture, use a dedicated profile with restricted file permissions; do not point an automation job at your everyday Chrome profile. A profile can contain reusable session data, so protect it like a credential.

const browser = await puppeteer.launch({
  headless: true,
  userDataDir: '/secure/path/to/screenshot-profile',
});

With a valid session already in that profile, navigate directly to the protected page and still wait for a signed-in content marker before capturing.

Use an isolated browser context for a one-off job

Browser contexts separate storage, including cookies and local storage, from other contexts. Use one when jobs should not share sessions, and close it after the capture. A fresh context does not inherit another context’s login automatically.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Supply cookies only when you have authorized session data

Current Puppeteer supports cookies through browser or browser-context methods. Preserve the cookie’s scope and attributes—such as domain, expiry, httpOnly, secure, and sameSite—when using session state legitimately provided for the task. Avoid putting raw session values in source code, logs, or screenshots. Puppeteer’s page-level cookie API is deprecated in favor of browser or context methods.

Use HTTP authentication only for browser-level challenges

page.authenticate({ username, password }) supplies credentials for HTTP authentication challenges. It does not fill an HTML login form or complete an SSO flow. Puppeteer notes that this method enables request interception behind the scenes, which can affect performance.

Wait for the right page, not just a finished navigation

A navigation event only tells you that a navigation reached a particular loading condition. It does not prove the browser is displaying the authenticated content. The more reliable check is a site-specific element, such as an account heading or report container:

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
await page.goto('https://example.com/account/report', {
  waitUntil: 'domcontentloaded',
});
await page.waitForSelector('[data-testid="report-content"]');
await page.screenshot({ path: 'report.png' });

Puppeteer’s screenshot guide also demonstrates waiting for networkidle2, but pages with ongoing background requests or delayed application rendering can make network-idle conditions less useful than a meaningful content marker. Set the viewport before navigation if the site’s responsive layout must render at a specific size.

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.

Choose what to capture

  • Viewport screenshot: omit fullPage or set it to false to capture the visible browser viewport.
  • Full-page screenshot: set fullPage: true to include content beyond the viewport, as in the example script.
  • One element: locate the target element and use its element-handle screenshot method when the artifact should contain only that element.

For content that loads after the initial render, wait for the relevant element or a site-specific ready condition before capture. A screenshot of an empty app shell or spinner is usually a timing or session problem, not something fixed by changing the image format.

Use Chrome’s command line for a simple capture

For a straightforward URL that does not require an interactive website login, Chrome’s CLI can save a screenshot in the current working directory:

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
chrome --headless --screenshot --window-size=1280,900 https://example.com

The documented flags include --screenshot and --window-size; the saved file is screenshot.png. This approach is less convenient when you must complete a login form, manage a session, or wait for a signed-in page marker. Use Puppeteer for those cases.

Current Headless Chrome and headless shell

Puppeteer 25.12.0 documentation describes regular Headless Chrome as the default when headless: true is set. Puppeteer also supports headless: 'shell' to select the separate chrome-headless-shell, which it says does not fully match regular Chrome behavior but can be faster for automation that does not need the full browser feature set.

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

Chromium’s Headless README states that, as of M132, headless shell is no longer part of the Chrome binary and --headless=old has no effect. For ordinary current Chrome behavior, use current Headless; select the separate shell only when its limitations fit the task.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common capture failures

  • The screenshot shows the login page: check the final URL after redirects, confirm the session is present in the page’s browser context, and verify the login-success marker before navigating to the target.
  • The page is blank or shows a spinner: wait for the protected content element rather than relying only on navigation completion. Check browser console errors, failed network requests, and whether the application’s delayed rendering finished.
  • Login works manually but not in automation: the site may require MFA, SSO, or another site-specific step. Use the authorized normal flow or a dedicated profile/session; generic HTTP authentication is not a substitute for a web form.
  • A session disappears between runs: a newly created page or isolated context does not necessarily share another run’s storage. Use a dedicated persistent userDataDir when reuse is intended, or arrange authorized session state for each isolated job.
  • The layout differs from the expected image: set the viewport before navigation and confirm the intended responsive breakpoint and page state before saving.
  • The capture takes too long or slows other requests: check for unnecessary network-idle waits and note that page.authenticate() enables request interception. Prefer a site-specific readiness marker when it is reliable.

Protect the account and the screenshot

Use only accounts and pages you are permitted to access. Keep credentials, cookie data, and persistent browser profiles private; screenshots can expose personal or confidential information, so keep them out of public artifacts unless that disclosure is intended.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. For authenticated pages, use its documented custom headers, cookies, or Authorization options where appropriate for your authorized access. A basic one-call capture looks like this; replace the URL with the page you want to capture:

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 parameters, including supported authentication inputs. ScreenshotNeo accepts cookie banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

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

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Does Chrome Headless log into a website automatically?

No. It uses the browser session available to it; the site’s normal login flow or authorized session state must establish that session.

Does `page.authenticate()` log in to a website form?

No. It handles HTTP authentication challenges, not HTML forms or identity-provider flows.

Should I use `–headless=old` with current Chrome?

No. Chromium says that as of M132 the old mode flag has no effect; current Headless and the separate headless shell are distinct choices.

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

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.

browser automationChrome HeadlessPuppeteerWeb developmentwebsite screenshots

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.

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.