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 DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
FREEDOM251

Freedom251 › Blog › browser automation

How to Take Screenshots of Many URLs With Custom Headers in Playwright

By Freedom251 Team · · 5 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.

Set shared headers with browserContext.setExtraHTTPHeaders(), then open each URL in a page, wait for the content you need, and save a screenshot. Context headers apply to every request from every page in that context, so use separate contexts when URL groups need different credentials or trust boundaries.

Capture a batch with shared headers

This JavaScript example uses one browser context for a batch, applies the custom headers before opening pages, and captures each URL sequentially. It is a usage pattern based on Playwright’s documented APIs, not a report of executed testing. Create the screenshots directory before running it.

As an Amazon Associate I earn from qualifying purchases.

const { chromium } = require('playwright');

async function captureUrls(urls, headers) {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    viewport: { width: 1440, height: 900 },
  });

  try {
    await context.setExtraHTTPHeaders(headers);

    for (const [index, url] of urls.entries()) {
      const page = await context.newPage();
      try {
        const response = await page.goto(url, { waitUntil: 'load' });
        console.log(`${url}: ${response?.status() ?? 'no response'}`);
        await page.screenshot({
          path: `screenshots/page-${index + 1}.png`,
          fullPage: true,
        });
      } finally {
        await page.close();
      }
    }
  } finally {
    await context.close();
    await browser.close();
  }
}

captureUrls(
  ['https://example.com', 'https://playwright.dev'],
  { 'X-Custom-Header': 'example-value' }
).catch(error => {
  console.error(error);
  process.exitCode = 1;
});

Install Playwright in your project and use its documented BrowserContext API, Page API, and pages guide for the version you have installed. Header values must be strings. The viewport in the example is 1440 × 900; fullPage: true captures beyond that viewport.

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

Choose the right header scope

Use context headers for a shared batch

Call context.setExtraHTTPHeaders(headers) before navigation when the same headers should apply throughout that context. Playwright documents that these headers are sent with every request initiated by any page in the context, not only the top-level document. That can include requests for page resources. Header order in outgoing requests is not guaranteed.

#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

Separate contexts for separate credentials

If batches use different credentials or have different trust boundaries, put them in separate contexts. Context-level settings, including headers, are shared by pages in that context. This keeps one batch’s context-wide configuration from being applied to another batch.

Override for an individual page when appropriate

Page-specific page.setExtraHTTPHeaders() values take precedence when they override a matching context-level header. Use this when one page needs a targeted override; keep in mind that the context headers still form the shared baseline.

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

Control navigation and screenshot readiness

Pick a navigation condition

page.goto() supports load, domcontentloaded, networkidle, and commit; its default is load. These conditions describe navigation progress, not necessarily whether the particular content you want to capture is ready.

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

Wait for the content that matters

For pages that populate important content after navigation, wait for a meaningful locator or page-specific signal before capturing. Playwright discourages using networkidle as a testing readiness strategy and recommends assessing readiness with assertions instead. A page can continue making background requests even when the main visual content is already present.

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.

Choose viewport or full-page output deliberately

Use the default viewport screenshot when the deliverable should show only the visible area. Set fullPage: true when the output should extend across the page’s scrollable height. Full-page images can be substantially taller than viewport captures, so select based on how the screenshots will be reviewed or processed.

Scale batches without losing control

Start sequentially, then evaluate bounded concurrency

The example processes one URL at a time. If throughput matters, bounded concurrency is an implementation choice to evaluate against the target sites, available resources, and their rate limits. Playwright’s cited documentation does not establish a universally safe concurrency level. Avoid launching an unbounded number of pages simply because the input list is large.

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

Keep filenames unique

The example assigns sequential filenames, which are unique within one run. If you run multiple batches into the same directory, include a batch identifier or another unique component in output paths so captures do not overwrite one another.

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.

Check response status explicitly

A navigation that receives a valid HTTP error response, such as 404 or 500, does not necessarily throw from page.goto(). The example logs the response status so you can decide whether to retain, flag, or skip such captures. If your workflow accepts only successful pages, check the returned response and handle non-success statuses explicitly.

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

Make visual captures reproducible

Rendering can vary with the host operating system, browser version, hardware, headless mode, and other environment details. For repeatable visual comparisons, keep the environment that generates the baseline and the later captures consistent. Also keep viewport and browser settings fixed across the batch. See Playwright’s visual comparison guidance.

Troubleshooting

  • The custom header is missing on requests: Confirm that setExtraHTTPHeaders() ran on the context before navigation, that each target page belongs to that context, and that header values are strings.
  • A page receives credentials it should not: Context headers reach requests from every page in that context. Split URL groups into separate contexts or use a page-level override where suitable.
  • The screenshot is blank or incomplete: Navigation completion may precede the page’s meaningful content. Wait for a locator or page-specific readiness signal before calling screenshot().
  • A 404 or 500 still produced an image: A valid HTTP error status is not necessarily a navigation exception. Inspect the response status and apply your own acceptance rule.
  • Files overwrite each other: Ensure output paths are unique across pages and across batch runs.
  • Visual output differs between runs: Rendering may vary across operating systems, browser versions, hardware, and headless settings. Keep the capture environment, viewport, and browser configuration consistent.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request can return an image or PDF; its API supports custom headers and cookies as well as viewport, full-page capture, and other capture controls. Cookie banners are accepted like a visitor and 60+ known consent platforms, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses report page verdict and billing headers. An MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.

cURL example (replace the URL as needed):

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

For parameter details, see the ScreenshotNeo documentation. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card.

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 automationJavaScriptPlaywrightscreenshotsWeb 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
Windows Errors? Fix Them Before They SpreadFree repair scan
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.