Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon 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×
FREEDOM251

Freedom251 › Blog › JavaScript

Take Screenshots of a Password-Protected Staging Website with Puppeteer

By Freedom251 Team · · 4 min read

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.

For a staging site protected by HTTP authentication, call Puppeteer’s page.authenticate() with the credentials before navigating, then capture the page with page.screenshot(). This does not cover a site that asks you to sign in through an application login form; that is a separate authentication flow.

Use Puppeteer for HTTP-authenticated staging sites

Puppeteer’s Page.authenticate() is specifically for HTTP authentication. Set the credentials before page.goto() so they are available when the browser requests the protected page. The method enables request interception behind the scenes, which may affect performance. See the Puppeteer authentication API.

As an Amazon Associate I earn from qualifying purchases.

Runnable example

Install Puppeteer in your project with npm install puppeteer, set the two environment variables to your staging credentials, and save this as an ES module such as screenshot.mjs:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.authenticate({
    username: process.env.STAGING_USERNAME,
    password: process.env.STAGING_PASSWORD,
  });
  await page.goto('https://staging.example.com', {
    waitUntil: 'networkidle2',
  });
  await page.screenshot({ path: 'staging.png', fullPage: true });
} finally {
  await browser.close();
}

Replace the example URL with your staging URL. Keep credentials outside source code and source control; provide them through your shell, deployment environment or secret manager. Puppeteer’s documented sequence is to launch a browser, create a page, navigate, capture and close the browser. The example combines those documented calls; its readiness condition and target state should be adjusted for your site.

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Choose when the page is ready

waitUntil: 'networkidle2' is one possible navigation condition, not a guarantee that every application is ready for a screenshot. A page may continue making background requests, or it may finish navigation before a client-rendered component or image reaches its final state. Choose a wait condition and, where needed, wait for a page-specific selector or state before capturing. Verify the resulting image against the state you need.

Choose a page, viewport or element capture

page.screenshot() captures the page. Its options include a destination path, output type, clipping rectangle and full-page capture; fullPage defaults to false and the documented image type default is PNG. Check the ScreenshotOptions reference for current option behavior. Puppeteer’s screenshots guide also documents capturing a particular element.

Rank #2
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
  • Viewport: omit fullPage or set it to false to capture the current viewport.
  • Full page: set fullPage: true to capture the full page rather than only the visible viewport.
  • Element: find the element, then call its screenshot() method. Puppeteer scrolls it into view if necessary; the call throws if the element has detached from the DOM. Capture only after the element exists and is stable.
  • Other output choices: consult the current API options for type, clip and output encoding rather than assuming a default that may not fit your installed Puppeteer version.

Capture a specific element

For example, after navigation, locate a stable selector and capture it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const element = await page.waitForSelector('[data-testid="deployment-summary"]');
if (!element) throw new Error('Deployment summary was not found');
await element.screenshot({ path: 'deployment-summary.png' });

Use a selector that identifies the intended element on your staging site. Element capture is distinct from a page screenshot: it targets that element, and can fail if the element is removed before the capture finishes. See ElementHandle.screenshot().

Rank #3
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

If the site uses a login form instead

An application-level login page is not the HTTP-authentication case handled by page.authenticate(). The source documentation here does not establish a universal recipe for signing into arbitrary applications: form fields, redirects, multifactor checks and session handling vary by site. Use the application’s supported test-login method or site-specific flow, and do not assume that passing HTTP credentials will submit a web form.

page.setExtraHTTPHeaders() can send configured headers with page requests, but it is not a universal authentication replacement. Whether a header is appropriate depends on the server’s authentication scheme. See Puppeteer’s extra-HTTP-headers API.

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common capture failures

  • The browser still shows an authentication prompt or an error: check that the site uses HTTP authentication, the credentials are correct, and page.authenticate() runs before navigation. A form-based login requires a different, site-specific flow.
  • The screenshot is blank or shows a loading state: navigation completion may not mean the content you need is ready. Wait for a relevant selector or application state, then inspect the image.
  • An element screenshot throws: confirm the selector resolved and the element remains attached and stable until capture. Puppeteer documents an error when the element has detached.
  • The script is slower than expected: HTTP authentication enables request interception behind the scenes, which Puppeteer notes may affect performance. Keep the authenticated flow limited to what the capture needs.
  • The file is not where expected: check the process’s working directory when using a relative path, or provide an explicit output path. Use the screenshot options reference for supported formats and options.

Or skip the browser setup

ScreenshotNeo is a screenshot API and MCP server. It captures URLs with a single GET request, and supports PNG, JPEG, WebP or PDF output. It is suited to URL capture; do not assume it signs in to an application form or a protected staging site without first confirming the authentication method supported for your setup.

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

For an accessible URL, this cURL example saves a WebP screenshot. See the ScreenshotNeo documentation for API details:

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

ScreenshotNeo can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and responses identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info and capture_pdf for AI agents and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Frequently Asked Questions

Which Puppeteer documentation version describes these APIs?

The documentation results identify version 25.12.0; check the current reference alongside the version installed in your project.

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.

JavaScriptPuppeteerscreenshotsStaging websitesWeb development

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.