October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Take a Playwright Screenshot of a Page Protected by HTTP Basic Authentication

Set HTTP Basic Authentication credentials on a Playwright browser context, navigate to the protected page, and save a screenshot safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For HTTP Basic Authentication, configure httpCredentials on a Playwright browser context before navigating. Create the page from that context, open the protected URL, then capture it with page.screenshot().

Capture a page protected by HTTP Basic Authentication

This standalone Node.js example uses Playwright’s Chromium browser. Set the credentials in environment variables so they are not committed to your source code.

As an Amazon Associate I earn from qualifying purchases.

import { chromium } from 'playwright';

const username = process.env.BASIC_AUTH_USERNAME;
const password = process.env.BASIC_AUTH_PASSWORD;

if (!username || !password) {
  throw new Error('Set BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD');
}

const browser = await chromium.launch();
try {
  const context = await browser.newContext({
    httpCredentials: {
      username,
      password,
      // Optional: limit credentials to this scheme, host, and port.
      origin: 'https://example.com',
    },
  });

  try {
    const page = await context.newPage();
    await page.goto('https://example.com/protected-page');
    await page.screenshot({ path: 'protected-page.png', fullPage: true });
  } finally {
    await context.close();
  }
} finally {
  await browser.close();
}

Install Playwright and its browser if needed with npm install playwright and npx playwright install chromium. Run the script with the variables set in your shell, for example BASIC_AUTH_USERNAME='your-user' BASIC_AUTH_PASSWORD='your-password' node screenshot.mjs. The screenshot is written to protected-page.png. Set fullPage: false, or omit it, for a viewport-sized capture.

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

Why the browser context must hold the credentials

httpCredentials belongs to the browser context: configure it when calling browser.newContext(), then create the page with context.newPage(). The page navigation then uses that authenticated browser context. See the Playwright BrowserContext API and its HTTP Authentication examples. The latter is a next-version documentation page; check the API against your installed Playwright version.

#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

The optional origin scopes credentials to a scheme, host, and port, such as https://example.com. This is useful when the browser session may navigate to other origins. Playwright notes that browsers can cache credentials per origin after successful authentication, so changing credentials for an origin that has already authenticated may not take effect as expected. Use a fresh context when testing different credentials for the same origin.

Use the configuration that fits your script or test suite

Standalone browser script

Use browser.newContext({ httpCredentials: { username, password } }) for a script-specific session. Pages created from that context inherit its authentication configuration.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • 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

Playwright Test

For a test suite, set httpCredentials under the Playwright Test configuration’s use options. Tests using that configured setup navigate through an authenticated browser context. The official Network guide shows this pattern; because it is a next-version page, confirm details against the documentation for your installed release.

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

Choose the right authentication method

httpCredentials handles an HTTP Basic Authentication challenge. It does not fill in a website’s HTML login form or create a cookie-based session. For those flows, perform the appropriate login steps or use Playwright’s storage-state approach to reuse an authenticated session. Storage-state files can contain sensitive cookies and headers; keep them out of source control. See Playwright’s Authentication guide.

Rank #3
Sale
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.

Do not substitute an API request setting for browser authentication. The BrowserType API’s send option applies to associated API requests and does not configure requests made by browser navigation. Set credentials on the browser context for this screenshot workflow; see the BrowserType API.

Adjust the screenshot capture

  • Full page: Use fullPage: true to capture the full scrollable page rather than only the viewport.
  • File output: Pass a path such as protected-page.png to write the image to disk. Playwright documents additional screenshot settings in the Page API.
  • Credential scope: Set origin when you want the credentials restricted to the intended origin.

Troubleshoot common failures

  • The screenshot shows an authentication prompt or an error page: Confirm that the username and password are correct, that the target actually uses HTTP Basic Authentication, and that httpCredentials is set on the same context that created the page.
  • Changed credentials appear to be ignored: The browser may have cached credentials for that origin. Close the context and create a fresh one before retrying.
  • The target is a login form, not a Basic Auth challenge: Context HTTP credentials do not submit form fields. Use the site’s login flow or an authenticated storage state instead.
  • Credentials are missing at runtime: Check that both environment variables are set in the process that runs the script. Avoid logging or hard-coding their values.
  • Navigation works but the screenshot is incomplete: Use fullPage: true if the goal is the whole scrollable document; the default capture is the visible page area.

Keep authentication data private

Read credentials from environment variables or a secret store rather than committing them in code. Treat saved authentication state as sensitive too: it may contain cookies or headers that grant access. Playwright’s Codegen guide cautions against exposing credentials in generated code, and its Authentication guide explains the sensitivity of saved state.

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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a simple URL-based capture, ScreenshotNeo provides a screenshot API and MCP server. A single request looks like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/protected-page -o shot.webp

See the ScreenshotNeo documentation for request options. ScreenshotNeo’s stated features include removing cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does this work with Firefox or WebKit?

The example launches Chromium. The same context-credential approach is documented for Playwright browser contexts; use the browser engine configured for your project.

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.

Can I use this for a website’s ordinary username-and-password form?

No. HTTP Basic Authentication is a browser-level credential challenge; an HTML login form needs its own login flow or an authenticated storage state.

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.