October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Convert a URL to a WebP Image with Playwright

Capture a rendered web page as a WebP image with Playwright, with runnable Node.js code and guidance on full-page screenshots, quality, buffers, and test snapshots.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To save a rendered web page as WebP, open the URL in a Playwright page and call page.screenshot({ type: 'webp', path: 'output.webp' }). This captures what the browser renders; it does not download and transcode an image file found at the URL.

Save a web page as a WebP screenshot

Install Playwright and its browser first. For example, in a Node.js project, install the package and Chromium:

As an Amazon Associate I earn from qualifying purchases.

npm install playwright
npx playwright install chromium

Then save this as capture.js and run it with node capture.js https://example.com:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const { chromium } = require('playwright');

(async () => {
  const url = process.argv[2];
  if (!url) {
    throw new Error('Usage: node capture.js <url>');
  }

  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto(url);
    await page.screenshot({ path: 'output.webp', type: 'webp' });
    console.log('Saved output.webp');
  } finally {
    await browser.close();
  }
})();

The script navigates to the supplied URL, captures the visible viewport, and writes output.webp in the current directory. Playwright documents the screenshot options, including WebP output, on its Page API.

Choose viewport, full-page, quality, or buffer output

Capture the full scrollable page

By default, a screenshot covers the visible viewport. Add fullPage: true to capture the full scrollable page:

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

Set WebP quality

WebP quality defaults to 100. Playwright documents this default as lossless; lower quality values use lossy compression. Set a lower value when you want lossy output:

await page.screenshot({ path: 'compressed.webp', type: 'webp', quality: 80 });

Quality does not apply to PNG. Check the resulting image for the visual detail you need before choosing a lower quality setting.

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

Return the image bytes instead of writing a file

page.screenshot() returns a Node.js Buffer. Omit path to keep the bytes in memory, for example to send them to storage or another processing step:

const image = await page.screenshot({ type: 'webp' });
// image is a Buffer containing the WebP screenshot.

The Playwright Screenshots guide describes using the returned buffer for post-processing or passing it to another tool.

Use WebP in Playwright Test visual snapshots

If the goal is a visual regression baseline rather than an image generated by an application script, Playwright Test supports naming the snapshot with a .webp extension:

await expect(page).toHaveScreenshot('homepage.webp');

Use page.screenshot() when your code needs a screenshot file or buffer. Use toHaveScreenshot() when the image is part of a Playwright Test assertion. The visual comparisons guide documents WebP snapshots as lossless.

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.

When the URL points to an image file

This workflow screenshots a browser-rendered page. It is not a general-purpose image converter that fetches an image asset from a URL and transcodes it into WebP. If you mean an image file rather than a web page, download that asset and use an image-processing workflow to convert it; page.screenshot() captures the browser view instead.

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

Troubleshooting and reliability

  • No output file: Confirm the script reached the screenshot call and that the current directory is writable. If you omit path, Playwright returns a buffer rather than saving a file.
  • Browser launch fails: Install the browser corresponding to your Playwright setup; the example command installs Chromium. Check the installation output for errors.
  • The capture is incomplete: Navigation and page rendering can vary by destination. Verify that the URL loads in the browser and that the content you need has rendered before taking the screenshot. The documented API does not guarantee access to every destination or consistent rendering.
  • Only part of the page appears: The default is the viewport; set fullPage: true for the full scrollable page.
  • Output is not WebP: Set type: 'webp' explicitly or use a .webp output path. Playwright also supports PNG and JPEG, and its documented default format is PNG.
  • Unexpected image size or detail: WebP quality 100 is lossless according to Playwright; lower quality is lossy. Adjust quality only if lossy compression is acceptable.

Or skip the browser setup

ScreenshotNeo can return a WebP screenshot through one GET request. Its API accepts a URL and supports options for full-page capture and quality alongside other capture controls. See the ScreenshotNeo API documentation for request parameters.

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

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides screenshot tools for AI agents, including Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo free to get 1,000 screenshots a month without a 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.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
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.