Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon 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 NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › JavaScript

How to Take a Puppeteer Screenshot of an SVG Web Page

By Freedom251 Team · · 5 min read

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.

Use Puppeteer’s Page.screenshot() to save the rendered page, or select the SVG and call ElementHandle.screenshot() to capture just the graphic. Set the viewport and capture extent deliberately, and wait for the page’s actual render-ready condition; a network-idle state alone is not a universal guarantee that SVG-related assets or animations have finished.

Install Puppeteer and capture an SVG page

This example uses JavaScript modules and saves a PNG. Replace the URL and selector with those for your page. Puppeteer’s screenshot guide documents page and element captures: Puppeteer Screenshots guide.

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.setViewport({ width: 1200, height: 800 });

  await page.goto('https://example.com/chart', { waitUntil: 'networkidle2' });

  // Capture the SVG element only.
  const svg = await page.waitForSelector('svg');
  if (!svg) throw new Error('No SVG element found');
  await svg.screenshot({ path: 'svg-element.png' });

  // Alternatively, capture the page viewport.
  await page.screenshot({ path: 'svg-page.png' });
} finally {
  await browser.close();
}

For a local project, install Puppeteer with npm install puppeteer, save the code in an .mjs file, and run it with Node.js. The finally block closes the browser even if navigation or capture fails.

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

Choose what to capture

The whole viewport

page.screenshot() captures the current viewport by default. It is useful when the SVG is presented within a page layout and you want that surrounding context. The method and its options are documented in the Page.screenshot() API reference.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

The full page

For a page taller than the viewport, pass fullPage: true:

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

This expands the capture to the full page rather than only the visible viewport. For a precise region, use the clip option; the available screenshot settings, including fullPage, clip, and captureBeyondViewport, are listed in the ScreenshotOptions reference.

One SVG element

Use a selector that identifies the target graphic rather than the first generic svg if the page contains multiple SVGs:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
const chart = await page.waitForSelector('#sales-chart');
if (!chart) throw new Error('Chart SVG not found');
await chart.screenshot({ path: 'sales-chart.png' });

An element screenshot scrolls the element into view when needed and then captures it. If the element has been removed from the DOM before the screenshot call, Puppeteer throws; wait for the final element and avoid replacing it between selection and capture. See ElementHandle.screenshot().

Set the viewport and image background

Choose viewport dimensions to match the layout you intend to render. Responsive pages may draw a different SVG, change its size, or reflow surrounding content at different viewport widths. Set the viewport before navigation or before capturing the page:

await page.setViewport({ width: 1440, height: 900 });

To make the browser’s default page background transparent, use omitBackground: true:

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
await page.screenshot({ path: 'svg-transparent.png', omitBackground: true });

This removes the default background, not a background deliberately painted by the SVG or page CSS. If the result still has a solid background, inspect the SVG’s rect elements, its root-level styles, and the page’s CSS. PNG is the default screenshot type; Puppeteer can infer the type from the output file extension. Refer to the options reference for the supported settings.

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

Wait for the graphic to be ready

waitUntil: 'networkidle2' is a navigation wait choice shown in Puppeteer’s guide. It does not establish that every font, image, SVG animation, or application-specific rendering step is complete. Prefer a readiness signal that reflects the page you are capturing, such as a chart container becoming visible or an application setting a ready attribute:

await page.goto('https://example.com/chart', { waitUntil: 'networkidle2' });
await page.waitForSelector('#sales-chart[data-ready="true"]');
const chart = await page.waitForSelector('#sales-chart svg');
if (!chart) throw new Error('Ready chart SVG not found');
await chart.screenshot({ path: 'sales-chart.png' });

Use a selector or condition that the target application actually provides. A fixed delay can be a fallback for a known, controlled page, but it is not a general way to prove rendering is complete. Keep the viewport, browser version, fonts, source page, and relevant assets stable when comparing captures; Puppeteer’s cited documentation does not promise pixel-identical results across environments.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Use supplied HTML instead of navigating to a URL

If the script already has the page markup, use page.setContent() to assign HTML to the page, then capture the SVG as usual. For example, save this as an .mjs file:

import puppeteer from 'puppeteer';

const html = `
<!doctype html>
<html>
  <body>
    <svg xmlns="http://www.w3.org/2000/svg" width="400" height="200">
      <rect width="400" height="200" fill="#eef4ff" />
      <circle cx="100" cy="100" r="60" fill="#2463eb" />
      <text x="190" y="110" font-size="24">Example chart</text>
    </svg>
  </body>
</html>`;

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.setViewport({ width: 800, height: 400 });
  await page.setContent(html);
  const svg = await page.waitForSelector('svg');
  if (!svg) throw new Error('No SVG element found');
  await svg.screenshot({ path: 'inline-svg.png' });
} finally {
  await browser.close();
}

Use page.goto() for a hosted page and page.setContent() when supplying the markup directly. The API reference describes setContent() as assigning HTML markup to the page: Page.setContent().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a hosted page, ScreenshotNeo can return an image or PDF from one GET request. See the ScreenshotNeo API documentation for request options.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/chart -o shot.webp

ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Can Puppeteer save an SVG web page as JPEG or WebP instead of PNG?

Yes. Set the screenshot type to jpeg or webp in the screenshot options and use a matching file extension. PNG is the default.

Why is my transparent screenshot still showing a background?

omitBackground removes the default page background only. A background drawn by the SVG itself or by CSS remains visible.

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

Does networkidle2 guarantee that an SVG animation has stopped?

No. Use a page-specific readiness condition or capture state when the desired animation frame is ready.

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.

JavaScriptPuppeteerscreenshotsSVGWeb development

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.