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

Use Playwright’s page.screenshot() with type: 'jpeg'. The method returns a Promise<Buffer>, so you can either save the JPEG directly with path or keep the bytes for an upload, transformation, or HTTP response. Add fullPage: true for the entire scrollable document, and choose a quality from 0 to 100 (the documented default is 80).

Install Playwright in a TypeScript project

Create a Node.js project, install Playwright, and install at least one browser binary:

npm install playwright
npx playwright install chromium

The example below uses Chromium. Playwright can automate supported browser engines, but this guide does not claim that one engine produces better JPEG fidelity or performance than another.

Save a webpage as a JPEG file

This complete function navigates to a URL, captures the full page, writes page.jpeg, and returns the same image bytes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import { chromium } from 'playwright';

async function capturePageAsJpeg(url: string): Promise<Buffer> {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto(url);
    return await page.screenshot({
      path: 'page.jpeg',
      type: 'jpeg',
      quality: 80,
      fullPage: true,
    });
  } finally {
    await browser.close();
  }
}

capturePageAsJpeg('https://example.com')
  .then(() => console.log('Saved page.jpeg'))
  .catch(console.error);

type: 'jpeg' explicitly requests JPEG output. When writing to a path, Playwright can also infer the screenshot type from the file extension, so a filename ending in .jpeg or .jpg is meaningful. Explicitly setting the type is clearer when the returned buffer is passed elsewhere.

Why keep the returned Buffer?

page.screenshot() returns image bytes even when a path is supplied. Keeping the Buffer lets you upload the image to object storage, attach it to an email, send it from an API route, or run another image-processing step without reading the file again.

Control JPEG quality and file size

JPEG quality is an integer from 0 through 100. The documented default is 80. Higher values generally preserve more visual detail while producing larger files; lower values trade some fidelity for a smaller transfer. There is no universal best setting, so choose it according to whether the image is destined for a visual review, a thumbnail, a report, or a bandwidth-constrained endpoint.

const jpeg = await page.screenshot({
  type: 'jpeg',
  quality: 70,
  fullPage: true,
});

The quality option applies to JPEG, not PNG. PNG is lossless and does not use this quality control. JPEG also cannot carry an alpha-transparent background: omitBackground is not applicable to JPEG. Use PNG when transparency is a requirement.

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

Choose the capture area

Viewport screenshot

Without fullPage, Playwright captures the visible viewport:

const viewportJpeg = await page.screenshot({
  type: 'jpeg',
  quality: 80,
});

Set the viewport before navigation when you need a predictable layout:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
const page = await browser.newPage({
  viewport: { width: 1440, height: 900 },
});
await page.goto('https://example.com');
const jpeg = await page.screenshot({ type: 'jpeg', quality: 80 });

Full-page screenshot

Use fullPage: true to capture the page’s full scrollable height rather than only what is currently visible:

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

Long pages can create very large images. Consider a smaller viewport width, a lower JPEG quality, or an element capture when a single giant document is not needed.

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

Capture one element

For a component, locate it and call the locator’s screenshot method:

const card = page.locator('.pricing-card').first();
await card.screenshot({
  path: 'pricing-card.jpeg',
  type: 'jpeg',
  quality: 85,
});

Element capture is useful for charts, product cards, invoices, and regression-test fixtures. Make the selector specific enough to identify exactly one intended element.

Control pixel density with scale

Playwright supports two scale modes:

  • scale: 'css' produces one image pixel per CSS pixel.
  • scale: 'device' captures device pixels and can produce larger output on high-density displays; device scale is the documented default.
const predictableSize = await page.screenshot({
  type: 'jpeg',
  quality: 80,
  scale: 'css',
});

Use CSS scale when downstream systems expect dimensions tied to the declared viewport. Use device scale when preserving high-density detail matters more than predictable file size.

Wait for the page before capturing

A screenshot taken immediately after navigation may precede client-side rendering, font loading, or image loading. Choose a wait condition that matches the page:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.locator('main').waitFor();
await page.waitForTimeout(500);

await page.screenshot({
  path: 'ready.jpeg',
  type: 'jpeg',
  quality: 80,
  fullPage: true,
});

Prefer waiting for a meaningful selector over an arbitrary long delay when the application exposes a stable readiness element. A short delay can still be useful for animations or late layout changes, but it increases capture time on every request.

Handle navigation, timeouts, and cleanup

Always close the browser in a finally block, especially in a server process. Set an explicit timeout for pages that may be slow:

import { chromium } from 'playwright';

export async function screenshot(url: string): Promise<Buffer> {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    page.setDefaultNavigationTimeout(60_000);
    await page.goto(url, { waitUntil: 'domcontentloaded' });
    await page.locator('body').waitFor();
    return await page.screenshot({
      type: 'jpeg',
      quality: 80,
      fullPage: true,
      scale: 'css',
    });
  } finally {
    await browser.close();
  }
}

For repeated captures, launching one browser per request is simple but expensive. A service can keep a browser process alive and create a fresh context or page per job, then close idle resources. Do not share mutable page state between unrelated URLs.

Send the JPEG instead of saving it

Because the result is a Buffer, an HTTP handler can return it directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const jpeg = await screenshot('https://example.com');

res.setHeader('Content-Type', 'image/jpeg');
res.setHeader('Content-Length', jpeg.length);
res.end(jpeg);

If you upload the bytes, set the object’s content type to image/jpeg. If you save locally, ensure the destination directory exists and use a filename whose extension matches the requested format.

Common problems and fixes

The output is PNG

Playwright defaults to PNG. Set type: 'jpeg', or write to a JPEG extension when relying on extension inference. Check the response metadata or open the file with an image tool rather than trusting only its name.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The screenshot shows only the top of the page

The default capture is the viewport. Add fullPage: true for the complete scrollable document, or capture a specific locator if the page is intentionally larger than the desired image.

Images or content are missing

Wait for a stable selector, use an appropriate waitUntil value, and allow time for application rendering. If content appears only after scrolling, verify that the page’s lazy-loading behavior is triggered before capture.

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

JPEG transparency does not work

JPEG does not support an alpha-transparent output in this API. Choose PNG when the background must remain transparent.

The file is unexpectedly large

Lower the quality, use scale: 'css', capture the viewport or a component instead of the full page, and avoid an unnecessarily wide viewport. Large, high-density full-page captures naturally contain more pixels.

Navigation times out

Confirm that the URL is reachable from the machine running Chromium, raise the navigation timeout only when the site is legitimately slow, and wait for a less demanding event such as domcontentloaded if network activity never becomes idle.

Chromium cannot launch in deployment

Install the Playwright browser binary during the build or deployment process and use an environment that permits the required sandbox or launch configuration. A missing executable is an installation problem, not a JPEG option problem.

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.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a hosted screenshot API is easier

Playwright gives you control, but your application must provide browser binaries, navigation isolation, waiting logic, retries, storage, and scaling. For a one-request capture, a hosted API can remove that browser setup.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. A GET request returns PNG, JPEG, WebP, or PDF, and the API accepts the URL plus capture options. The same endpoint can handle full-page captures, element selectors, custom viewports, dark mode, retina scale, waits, custom JavaScript and CSS, cookies, headers, geolocation, request blocking, resizing, caching, signed links, asynchronous webhooks, and bulk capture.

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

For JPEG output, add the format parameter supported by your ScreenshotNeo account configuration; see the ScreenshotNeo documentation for the current parameter names. The service also accepts the parameter names used by other screenshot APIs, which can simplify migration.

Python

import requests

r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const bytes = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', bytes));

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and whether the request was billed. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Plan Included shots Price
Free 1,000 per month $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing provides two months free, and every feature is available on every plan. Sign up for ScreenshotNeo to get 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000 shots.

Frequently Asked Questions

Can TypeScript save a screenshot without writing a file first?

Yes. page.screenshot() returns a Promise<Buffer>; omit path and pass the buffer to an upload, response, or image-processing function.

What is the difference between CSS and device scale?

CSS scale maps one output pixel to one CSS pixel. Device scale captures device pixels and can create larger images on high-density displays.

Can JPEG screenshots have transparent backgrounds?

No. Use PNG when an alpha-transparent background is required.

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.

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.