Visual Studio Code does not have a built-in command that converts an arbitrary HTML file to PNG. Instead, use VS Code to install and edit a browser-automation library such as Playwright, open the HTML in a real browser page, and call page.screenshot(). A filename ending in .png makes Playwright write a PNG image.
This workflow works for local development pages and deployed URLs. You can capture the visible viewport, the entire scrollable page, or one selected element. The browser, page-loading method, fonts, assets and viewport determine what appears in the image.
What you need
- Node.js installed and available on your PATH.
- Visual Studio Code.
- The official Playwright extension, installed from the VS Code Extensions view.
- An HTML page that can be opened by a browser, either through a local development server or a suitable
file://URL.
The Playwright VS Code guide documents editor integration for installing, running and debugging tests. The screenshot itself is produced by Playwright’s Page API, not by a VS Code export command.
Set up Playwright in VS Code
- Open your project folder in VS Code.
- Open Extensions (
Ctrl+Shift+Xon Windows/Linux orCmd+Shift+Xon macOS), search for Playwright Test for VS Code, and install the official extension. - Open the Command Palette with
Ctrl+Shift+PorCmd+Shift+P. - Run Test: Install Playwright. Follow the prompts to add Playwright to the project and install the browser binaries.
- Create a JavaScript file such as
capture.jsin the project root.
The extension is useful for test discovery, debugging and test generation; you can run the standalone script below from VS Code’s integrated terminal.
#1 Best Overall
Convert a local or hosted HTML page to PNG
Use a local development server (recommended)
Serving the project through its normal development server gives relative CSS, JavaScript, fonts and images the same URL behavior they have in the browser. Start your server (for example, the command your framework documents), note its URL, and use that URL in page.goto().
Save this runnable script as capture.js:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage({
viewport: { width: 1280, height: 800 }
});
await page.goto('http://localhost:3000', {
waitUntil: 'networkidle'
});
await page.screenshot({
path: 'screenshot.png',
fullPage: true
});
await browser.close();
})();
Run it in the integrated terminal:
node capture.js
Playwright writes screenshot.png beside the script. Change the URL to your development server or a public page. The viewport in this example is an illustrative choice, not a required setting.
Open a standalone HTML file
A local file can be opened with a file URL, but browser security rules and relative paths can prevent scripts, modules, fonts or images from loading as expected. Build the URL from an absolute path:
const path = require('path');
const { pathToFileURL } = require('url');
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
const htmlUrl = pathToFileURL(path.resolve(__dirname, 'index.html')).href;
await page.goto(htmlUrl, { waitUntil: 'load' });
await page.screenshot({ path: 'local-page.png', fullPage: true });
await browser.close();
})();
If assets fail to load, run a small local server instead and navigate to its HTTP address. That usually avoids file-origin restrictions and mirrors production behavior more closely.
Recommended Free Tools
Choose the capture area
Visible viewport
await page.screenshot({ path: 'viewport.png' });
This captures only the current browser viewport.
Entire scrollable page
await page.screenshot({
path: 'full-page.png',
fullPage: true
});
fullPage: true extends the capture to the page’s full scrollable height. Very long pages create correspondingly tall images and may require more memory.
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
One element
await page.locator('.header').screenshot({ path: 'header.png' });
Replace .header with a stable CSS selector. If the locator matches multiple elements, refine it or use a locator method that identifies one element unambiguously.
Make dynamic pages render correctly
Navigation completion does not guarantee that every visual dependency is ready. Wait for the content that matters rather than relying on an arbitrary fixed delay.
Wait for a selector
await page.goto('http://localhost:3000');
await page.locator('.report').waitFor({ state: 'visible' });
await page.screenshot({ path: 'report.png', fullPage: true });
Wait for fonts and images
await page.goto('http://localhost:3000');
await page.evaluate(async () => {
await document.fonts.ready;
await Promise.all(
Array.from(document.images)
.filter(img => !img.complete)
.map(img => new Promise(resolve => {
img.addEventListener('load', resolve, { once: true });
img.addEventListener('error', resolve, { once: true });
}))
);
});
await page.screenshot({ path: 'ready.png', fullPage: true });
For application-specific rendering, wait for the selector or network request that signals completion. A fixed timeout can be either too short on a slow run or unnecessarily long on a fast one.
Free tools Windows power users keep installed
One-click scans. No signup required.
Control visual conditions
Set a deterministic viewport and, when needed, choose a color scheme or device scale factor:
const context = await browser.newContext({
viewport: { width: 1440, height: 900 },
deviceScaleFactor: 1,
colorScheme: 'light'
});
const page = await context.newPage();
Keep browser version, operating system, fonts, viewport and headless settings stable when comparing images. Rendering can vary across those conditions.
Rank #3
Useful Playwright options
| Need | Example | Result |
|---|---|---|
| PNG output | path: 'page.png' |
Writes a PNG based on the extension. |
| JPEG output | path: 'page.jpg', quality: 85 |
Writes JPEG; quality applies to JPEG. |
| Transparent background | omitBackground: true |
Leaves transparent pixels where the page background is transparent. |
| Selected element | page.locator('#invoice').screenshot(...) |
Captures the element’s bounds. |
| Full page | fullPage: true |
Captures the complete scrollable page. |
You can also use page.addStyleTag() or page.evaluate() before capture to apply print-specific CSS, hide an element, or set test data. Keep those changes in the script so the conversion is repeatable.
Using Puppeteer instead
Puppeteer offers the same basic browser-rendering workflow. It is a reasonable choice when the project already uses Puppeteer or when you prefer its API; it is not a VS Code feature.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 800 });
await page.goto('http://localhost:3000', { waitUntil: 'networkidle0' });
await page.screenshot({ path: 'puppeteer.png', fullPage: true });
await browser.close();
})();
Choose between Playwright and Puppeteer based on the library already in your project, the editor and testing workflow you want, and whether you need a viewport, full-page or element capture. The available documentation does not establish a universal image-quality winner.
Troubleshooting
“Cannot find module ‘playwright’”
Run npm install -D playwright in the project directory, then install the browsers with npx playwright install. Confirm that VS Code’s terminal is using the same Node.js project.
The page is blank or missing styles
Check the URL, start the local server, and inspect relative asset paths. A file:// page may be blocked from loading modules or cross-origin resources; use the development server route instead.
Rank #4
- 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
The screenshot is taken before content appears
Wait for a meaningful selector, a specific application-ready signal, or the required images and fonts. Do not assume that a universal delay works for every machine or page.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchFonts or layout differ from the browser
Install the same fonts, use the same viewport and browser version, and avoid changing device scale factor between runs. Web fonts that have not loaded at capture time will change text metrics.
Full-page capture is unexpectedly huge
Use a viewport screenshot or capture a specific locator. For long documents, split the page into sections if downstream tooling cannot handle a very tall bitmap.
A selector screenshot fails
Verify the selector in DevTools, wait for the element to become visible, and make sure it is not inside a closed shadow root or an iframe that you have not addressed through the appropriate frame.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup:
ScreenshotNeo is a website screenshot API and MCP server. One GET request renders a URL and returns PNG, JPEG, WebP or PDF. It removes cookie and consent banners, newsletter popups and chat widgets before capture; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Use the API documentation at https://screenshotneo.com/docs/ for all options, including full-page capture, selectors, device presets, custom CSS and JavaScript, waits, headers, cookies, geolocation, caching, signed links, asynchronous jobs and bulk capture.
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
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}`);
Get a free key at ScreenshotNeo’s sign-up page: 1,000 screenshots a month, no card required.
Which method should you use?
| Situation | Best fit |
|---|---|
| You need local files, custom test data or pixel-controlled automation. | Playwright in VS Code. |
| Your project already depends on Puppeteer. | Puppeteer script. |
| You need repeatable URL capture without installing browsers. | ScreenshotNeo API. |
| An AI agent should request captures through MCP. | ScreenshotNeo MCP server. |
Frequently Asked Questions
Does VS Code convert HTML to PNG by itself?
No. VS Code hosts the code and Playwright extension; a browser automation library performs rendering and writes the PNG.
What does the .png extension do in Playwright?
When the screenshot path ends in .png, Playwright saves PNG output at that path.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Can I capture only one HTML element?
Yes. Use a locator such as page.locator(‘.header’).screenshot({ path: ‘header.png’ }).
Quick Recap
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.

