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 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 URL List and Create an HTML Gallery

By Freedom251 Team · · 8 min read

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

Use Playwright to open each URL in a real browser, save a consistently named screenshot, and generate an HTML page that displays the images with captions and source links. Keep each original URL in a manifest beside its image so redirects, duplicate page titles, or repeated domains do not break the association.

What you need

  • Node.js and a text file containing one URL per line, with each address including a scheme such as https://.
  • Playwright and its browser runtime. The official Playwright Page API documents navigation, response information, and screenshot options.
  • A local output folder where the screenshots and gallery HTML file will live together.

This example captures one viewport-sized PNG for each URL and creates gallery/index.html. It records navigation failures rather than stopping the whole batch. The gallery escapes URL text before inserting it into HTML.

As an Amazon Associate I earn from qualifying purchases.

Set up the batch capture script

  1. Create a project and install Playwright: npm init -y, then npm install playwright.
  2. Install the Chromium browser runtime with npx playwright install chromium.
  3. Save one URL per line in urls.txt, for example:
    https://example.com
    https://www.wikipedia.org
  4. Save the following as capture-gallery.js in the same directory.
const fs = require('node:fs/promises');
const path = require('node:path');
const { chromium } = require('playwright');

const inputPath = 'urls.txt';
const outputDir = 'gallery';
const width = 1365;
const height = 900;
const fullPage = false;

function escapeHtml(value) {
  return String(value).replace(/[<>&"']/g, (char) => ({
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#39;'
  })[char]);
}

function safeUrl(line) {
  const url = new URL(line);
  if (!['http:', 'https:'].includes(url.protocol)) {
    throw new Error('Only http and https URLs are supported');
  }
  return url;
}

async function main() {
  const lines = (await fs.readFile(inputPath, 'utf8'))
    .split(/r?n/)
    .map((line) => line.trim())
    .filter(Boolean);

  await fs.mkdir(outputDir, { recursive: true });
  const browser = await chromium.launch();
  const records = [];

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

    for (const [index, input] of lines.entries()) {
      const filename = `page-${String(index + 1).padStart(3, '0')}.png`;
      const record = { input, filename, finalUrl: null, status: null, error: null };

      try {
        const url = safeUrl(input);
        const response = await page.goto(url.href, {
          waitUntil: 'domcontentloaded',
          timeout: 30000
        });
        record.finalUrl = page.url();
        record.status = response ? response.status() : null;

        // Add a task-specific readiness check here if the page has delayed content.
        await page.screenshot({
          path: path.join(outputDir, filename),
          fullPage
        });
      } catch (error) {
        record.error = error.message;
      }
      records.push(record);
    }
  } finally {
    await browser.close();
  }

  await fs.writeFile(path.join(outputDir, 'manifest.json'), JSON.stringify(records, null, 2));

  const cards = records.map((record) => {
    const source = escapeHtml(record.input);
    const finalUrl = record.finalUrl ? escapeHtml(record.finalUrl) : '';
    const status = record.status === null ? 'No response status recorded' : `HTTP ${record.status}`;

    if (record.error) {
      return `<article class="card failure"><h2>${source}</h2><p>Capture failed: ${escapeHtml(record.error)}</p></article>`;
    }

    return `<article class="card"><a href="${source}"><img src="${escapeHtml(record.filename)}" alt="Screenshot of ${source}" loading="lazy"></a><h2><a href="${source}">${source}</a></h2><p>${escapeHtml(status)}${finalUrl && finalUrl !== source ? ` · Final page: ${finalUrl}` : ''}</p></article>`;
  }).join('n');

  const html = `<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Screenshot gallery</title>
  <style>
    body { margin: 0; padding: 1.5rem; font: 16px/1.5 system-ui, sans-serif; color: #222; }
    h1 { margin-top: 0; }
    .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
    .card { min-width: 0; padding: 1rem; border: 1px solid #ddd; border-radius: .5rem; }
    .card img { display: block; width: 100%; height: auto; border: 1px solid #eee; }
    .card h2 { overflow-wrap: anywhere; font-size: 1rem; }
    .card p { overflow-wrap: anywhere; color: #555; font-size: .9rem; }
    .failure { border-color: #b42318; }
  </style>
</head>
<body>
  <h1>Screenshot gallery</h1>
  <main class="grid">${cards}</main>
</body>
</html>`;

  await fs.writeFile(path.join(outputDir, 'index.html'), html);
  console.log(`Created ${path.join(outputDir, 'index.html')} for ${records.length} URL(s).`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run it with node capture-gallery.js. Open gallery/index.html in a browser. Keep the HTML, manifest.json, and image files together when sharing the gallery; image references are relative paths.

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

Choose when the page is ready to capture

The sample waits for domcontentloaded, which indicates the initial document has been parsed; it does not guarantee every image, font, or delayed widget is ready. If a particular page needs time or a visible component to appear, add a targeted wait after navigation:

#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner | For Computers including PC and Mac Receipt and Document Scanner USB Powered
  • PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
  • QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
  • VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
  • INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
  • EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0
await page.locator('.results-panel').waitFor({ state: 'visible', timeout: 10000 });

Replace .results-panel with a selector that identifies the content relevant to your task. A fixed delay can work for a known site-specific delay, but it may waste time on fast pages and still be too short on slow ones. Playwright describes networkidle as 500 milliseconds without network connections and discourages using it as a general testing readiness signal; some pages keep connections active or render content later. See the Playwright Page API.

Pick viewport, full-page, and image settings

Viewport screenshots for comparison

The sample uses a 1365-by-900 CSS-pixel viewport and fullPage: false. A consistent viewport makes above-the-fold content easier to compare across sites and keeps gallery thumbnails a manageable shape.

Full-page screenshots for complete pages

Set fullPage to true in the script to capture the full scrollable page as if it fit on one very tall screen. Long screenshots can be unwieldy in a grid, so use them when the complete page matters rather than when side-by-side comparison is the priority. Playwright documents this behavior in its screenshot guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
  • READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
  • WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
  • OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)

Output format and scale

The example writes PNG files. Playwright also supports JPEG and WebP screenshots, with quality settings available for lossy formats; choose them when smaller files matter more than lossless output. Device scale settings can produce higher-resolution, larger files. Consult the current Playwright screenshot guide for option names and supported formats.

Keep records reliable across failures and redirects

The script assigns each input a numbered filename instead of using a page title or domain, avoiding collisions when titles repeat or several URLs share a host. The manifest stores the submitted address, resulting page URL when navigation succeeds, HTTP response status when available, and any error.

A navigation that returns HTTP 404 or 500 may still complete and yield a screenshot. Playwright’s Page API says The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 “Not Found” and 500 “Internal Server Error”. Check record.status if only successful responses should count as usable captures. A redirect can also mean the final page URL differs from the input, which is why both are retained.

Rank #3
Sale
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
  • STAY ORGANIZED – Easily convert your paper documents into digital formats like searchable PDF files, JPEGs, and more.Power Consumption : 2.5W or less (Energy Saving Mode: 0.7W). Suggested Daily Volume : 500 scans..Does it contain liquid: no
  • CONVENIENT AND PORTABLE –lightweight and small in size, you can take the scanner anywhere from home offices, classrooms, remote offices, and anywhere in between
  • HANDLES VARIOUS MEDIA TYPES – Digitize receipts, business cards, plastic or embossed cards, reports, legal documents, and more
  • FAST AND EFFICIENT – No technical hurdles or complicated setups here; easily scan both sides of a document at the same time, in color or black-and-white, at up to 12 pages-per-minute, and with a 20 sheet automatic feeder
  • BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer

Invalid addresses, SSL problems, unreachable hosts, and navigation timeouts can throw. In the example, those rows become visible failure cards and later URLs still run. Browser shutdown is in a finally block, so a capture error does not leave the launched browser open.

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

Security and sharing

  • Use only URLs you are permitted to access. Treat authenticated pages and private content as sensitive, especially if the gallery will be shared publicly.
  • Escape titles and URLs before inserting them into generated HTML. Do not place page-provided content into markup as trusted HTML.
  • Keep the local gallery files together: the page uses relative image paths and will not contain the images themselves.

Or skip the browser setup

ScreenshotNeo can capture a URL with one request; its API documentation describes the available parameters and response behavior.

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

For a URL list, call the endpoint once per address and save each response under a distinct filename before building the same kind of HTML gallery. ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server includes screenshot tools for AI agents, and every plan includes the available features. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month, with no card required.

Rank #4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
  • IRIScan Express, portable scanner : scans color and black and white documents a blazing speed up to 8ppm simplex. Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • IRIScan Express mobile scanner is powered via an included micro USB 2. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan. USB cable provided. AC Adapter not provided and not needed.
  • IRIScan flatbed scanner uses a simplex scanning mode allows for quick and straightforward scanning of single-sided documents. IRIScan with its full portable features is the ideal document scanners for computers.
  • IRIScan document scanner : Versatile scanning capabilities, including scanning to Word, PDF, and Excel formats with companion software provided Readiris OCR
  • Receipt scanner and card scanner with Additional features include scanning business cards directly to Outlook, photo scanning, and receipt scanning for efficient document management
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

The script rejects a URL

Each nonblank line must be a complete HTTP or HTTPS address, including the scheme. Check for missing https://, stray CSV separators, or text that is not a URL.

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

A page looks incomplete

domcontentloaded is only the initial document readiness point. Wait for a relevant selector or a site-specific condition before taking the screenshot. Avoid assuming that a generic network-idle wait guarantees that delayed visual content has rendered.

A screenshot is missing but the run continued

Open gallery/index.html to see the failure card and inspect gallery/manifest.json for the recorded error. Check whether the site is reachable from the machine running the script, whether the address is valid, and whether the navigation timeout needs adjustment.

Best Value
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images

The capture shows an error page or a not-found page

A valid HTTP error status does not necessarily throw from page.goto. Check the recorded HTTP status and decide whether to keep such screenshots or mark them as unsuccessful in your gallery.

The gallery image is broken after moving files

Keep each PNG beside index.html in the gallery directory, or update the relative paths generated by the script if you reorganize the output.

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

Performance and batch size

This script captures URLs sequentially using one page, which keeps the workflow simple and avoids opening many browser tabs at once. It does not establish a speed benchmark or an ideal concurrency level. For large lists, expect the run to depend on how quickly each site navigates and renders; use an explicit timeout and preserve per-URL records so one slow or unavailable site does not erase the rest of the batch. If you add parallel pages, limit concurrency deliberately and verify that your machine and target sites can handle it.

When to use Playwright or Puppeteer

Both libraries document navigating to a page and saving a screenshot. Choose based on the browser automation already used by your project, supported language and browser requirements, and dependencies you already maintain. The official Puppeteer screenshot guide provides its own screenshot workflow. The sources establish the core capture methods, not a performance winner.

Frequently Asked Questions

Can I use a CSV file instead of one URL per line?

Yes. Parse the CSV into URL records before the loop, retaining each row’s URL and any caption fields; keep the same escaping and unique filename approach when generating cards.

Can the gallery be opened offline?

Yes, if the HTML and screenshot image files are available locally together. The source links still require an internet connection to open their original pages.

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

Quick Recap

SaleBestseller No. 3
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer; This product is not intended for scanning photographs on photo paper / photographic media
$153.00
Bestseller No. 4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
Find our Software here : irislink.com/start; IRIScan Express is only compatible Windows platform and not macintosh
$129.00
Bestseller No. 5
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

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 automationHTML galleryPlaywrightPuppeteerscreenshotsWeb 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.