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

Use Playwright’s Chromium browser, open a page, then call page.screenshot(). Set path to save the image; add fullPage: true to capture beyond the visible viewport.

Install Playwright and launch Chromium

In a Node.js project, install Playwright and its Chromium browser:

npm install playwright
npx playwright install chromium

Save this as screenshot.js, then run node screenshot.js:

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

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await page.screenshot({ path: 'screenshot.png' });
  } finally {
    await browser.close();
  }
})();

The default screenshot is the visible viewport. The relative path screenshot.png is resolved from the process’s current working directory. See the Playwright Page.screenshot() API and migration guide.

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

Choose the screenshot area

Capture the visible viewport

The default is equivalent to:

await page.screenshot({ path: 'page.png' });

Set the viewport dimensions before navigating or capturing if you need a predictable viewport:

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

Capture the full page

Use fullPage: true to capture the entire scrollable page rather than only what is currently visible:

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

For pages that load content as you scroll, a full-page capture may not trigger every lazy-loaded asset. If content is missing, scroll through the page or otherwise wait for it to load before capturing.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Capture one element

Use a locator’s screenshot method to save the element matching a CSS selector:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.locator('.header').screenshot({ path: 'header.png' });

Choose a selector that identifies the intended element. If it does not match an element or the element is not ready to capture, wait for it or correct the selector.

Capture a clipped rectangle

Pass a rectangle to clip to capture a specific region of the page:

await page.screenshot({
  path: 'region.png',
  clip: { x: 100, y: 80, width: 600, height: 400 }
});

The coordinates and dimensions describe the clip rectangle; make sure its width and height are positive and that it covers the area you intend to save.

Save to a file or use the screenshot in memory

With path, Playwright writes the image to disk. Without path, page.screenshot() returns a buffer you can pass to another function or write yourself:

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.
const image = await page.screenshot();
// Use image as a Node.js Buffer, or write it with fs.writeFileSync().

Playwright can infer the image format from the path extension. To choose explicitly, set type to 'png', 'jpeg', or 'webp'. If you select JPEG, do not request an omitted background: JPEG does not support transparent output. For options such as scale, masks, animation handling, and stylesheets, consult the API reference.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Make captures more predictable

For repeatable screenshots, make the page state and capture options explicit. Wait for the content you need, set the viewport, and choose whether animations or the caret should appear. If an image depends on content that loads asynchronously, wait for a meaningful selector rather than relying on an arbitrary short delay.

Playwright also supports masking locators, disabling animations, hiding the caret, using CSS or device scale, omitting the background, and applying a stylesheet. Confirm the option’s behavior and compatibility in the screenshot API documentation.

Use screenshots for visual regression tests

When the goal is to detect visual changes in a test suite, use Playwright Test’s expect(page).toHaveScreenshot() rather than writing a one-off image comparison. The assertion waits for two consecutive screenshots to match before comparing the resulting capture with the expected baseline. This is a Playwright Test runner feature; see the visual comparisons guide.

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

Rendering can differ across operating systems, browser versions, settings, hardware, power sources, and headless mode. Generate and compare baselines in the same environment where possible to reduce unrelated visual differences.

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

Troubleshoot common screenshot problems

  • The image shows only the top portion of the page: fullPage defaults to false. Set fullPage: true for the full scrollable page.
  • The output file is missing: Check the process’s current working directory and the supplied path. Relative paths are resolved from that directory.
  • The screenshot is blank or content is missing: The page or its assets may not have finished loading. Wait for the relevant selector or content before taking the screenshot.
  • An element screenshot fails or captures the wrong thing: Verify the locator selector identifies the intended element and that the element exists before capture.
  • The screenshot has unexpected visual differences in tests: Keep the operating system, browser version, settings, hardware environment, and headless mode consistent between baseline creation and comparison.
  • Transparent output is not available: Omit the background only with a format that supports transparency; JPEG does not support omitted backgrounds.

Or skip the browser setup

ScreenshotNeo can return a website screenshot or PDF from one request. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; these steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status.

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 API documentation for request options. It also offers an MCP server with screenshot and page-information tools for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

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.