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

Use Playwright’s page.screenshot({ path: 'thumbnail.png' }) after navigating to the page. The .png extension selects PNG output, and PNG is the documented default. For a thumbnail, set a viewport to match where the image will appear, then save the screenshot to a deliberate path.

Capture a website thumbnail as a PNG

Install Playwright and its browser binaries, then run this Node.js example. The 1200 × 630 viewport is an illustrative thumbnail size, not a Playwright requirement; set it to the dimensions or aspect ratio your publishing surface needs.

  1. In your project directory, install Playwright: npm install playwright.

  2. Install a browser for Playwright: npx playwright install chromium.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Save the following as capture.js, replacing the example URL with the page you want to capture.

  4. Run node capture.js. The script writes thumbnail.png in the current working directory.

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

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage({
      viewport: { width: 1200, height: 630 },
    });

    await page.goto('https://example.com');
    await page.screenshot({ path: 'thumbnail.png' });
  } finally {
    await browser.close();
  }
})();

The example closes the browser in a finally block so it is also closed if navigation or capture fails. Playwright documents this launch, page, navigation, screenshot, and close pattern in its Page API.

Rank #2
Free Fling File Transfer Software for Windows [PC Download]
  • Intuitive interface of a conventional FTP client
  • Easy and Reliable FTP Site Maintenance.
  • FTP Automation and Synchronization

Choose viewport or full-page capture

By default, page.screenshot() captures the visible viewport. That is usually the right starting point for a compact thumbnail: the viewport controls the composition and prevents the image from becoming as tall as the entire document.

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

Use fullPage: true only when the thumbnail is meant to show the full scrollable page. A full-page capture can be much taller than a typical thumbnail and may not fit the destination’s aspect ratio without cropping or resizing.

await page.screenshot({
  path: 'full-page.png',
  fullPage: true,
});

Playwright also supports clip for capturing a rectangle and locator screenshot methods for capturing a particular element. See the Screenshots guide for the relevant examples.

Set the output dimensions and pixel scale

The viewport is measured in CSS pixels; the screenshot’s pixel dimensions also depend on scale. Playwright’s screenshot scale defaults to 'device', which uses device pixels and can produce larger output on a high-DPI device. Set scale: 'css' to produce one output pixel per CSS pixel.

await page.screenshot({
  path: 'thumbnail.png',
  scale: 'css',
});

The browser context’s deviceScaleFactor defaults to 1. If exact output dimensions matter, choose the viewport and device scale deliberately and use a consistent configuration for each capture. For example, a 1200 × 630 CSS-pixel viewport with CSS scale yields a 1200 × 630-pixel image. With device scale, the result depends on the context’s device scale factor.

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

Make repeat captures more consistent

Pages can contain animations, blinking carets, rotating banners, or changing content. Playwright offers screenshot options to disable animations, hide the caret, mask selected locators, and apply a stylesheet during capture. Use these when they address a specific source of unwanted variation; disabling animation changes its behavior during capture, while masks visibly cover matching element bounds. The available options are documented in the Page API.

For visual comparisons, consistency also depends on the rendering environment. Playwright’s visual comparisons guide notes that host operating system, browser version, settings, hardware, power source, and headless mode can affect rendering. Keep the environment consistent with the one used to create the baseline.

Use screenshot assertions only for test workflows

page.screenshot() is the direct API for creating a thumbnail image file. Playwright Test’s toHaveScreenshot() is for screenshot assertions: it waits for two consecutive screenshots to match before comparing against an expected snapshot, and it requires the Playwright test runner. See the PageAssertions API if the goal is testing rather than saving a standalone thumbnail.

Common problems and fixes

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you do not want to install or manage a browser, ScreenshotNeo returns a screenshot with one GET request. This example saves the response as WebP; change the requested output format if you need PNG.

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

See the ScreenshotNeo documentation for API details. It removes known cookie-consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try it with 1,000 screenshots a month and 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.