Use Puppeteer’s Page.screenshot() to save a TypeScript screenshot: launch the browser, open a page, navigate to the target URL, and await the capture. The example below saves a PNG and closes the browser even if navigation or capture fails.
Take a page screenshot with Puppeteer in TypeScript
import puppeteer from 'puppeteer';
async function main(): Promise<void> {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
} finally {
await browser.close();
}
}
void main();
Save this as a TypeScript file in a project with Puppeteer installed, then run it using your TypeScript runner or build setup. On success, screenshot.png is written to the process’s current working directory. The try/finally ensures the browser is closed after the capture or if an awaited operation throws.
The capture is asynchronous: await page.screenshot() before using its result or relying on the saved file. This follows Puppeteer’s documented page workflow; see the Page API.
Choose what to capture
Current viewport
The basic example captures the page’s current viewport. Puppeteer’s default screenshot format is PNG. With path: 'screenshot.png', the file extension is used to infer the image type.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
Full page
Set fullPage: true to request a capture of the full page rather than only the viewport:
await page.screenshot({ path: 'full.png', fullPage: true });
fullPage defaults to false. Full-page capture does not, by itself, guarantee that content loaded only during scrolling or after application-specific events has appeared; handle those readiness needs separately.
One element
For a single element, locate it and call its screenshot method. For example:
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
const card = await page.$('.product-card');
if (!card) {
throw new Error('Could not find .product-card');
}
await card.screenshot({ path: 'product-card.png' });
ElementHandle.screenshot() attempts to scroll an element into view if it is hidden. See the Puppeteer Screenshots guide for page and element examples.
A selected region
Use clip to capture a specified region of the page or element, rather than the full viewport or a whole element. The region’s geometry must be appropriate for the page being captured; consult the ScreenshotOptions API for the option’s shape and details.
Wait for the page to be ready
page.goto() resolves according to its navigation wait condition. For pages where network activity is a useful readiness signal, Puppeteer’s guide demonstrates networkidle2:
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.screenshot({ path: 'screenshot.png' });
Do not treat that condition as proof that every page is visually complete. An application may fetch data later, animate elements, or reveal lazy-loaded images only after scrolling. If the target has a known readiness signal, wait for it explicitly—for example, a selector that appears when the relevant content is ready:
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.waitForSelector('.report-ready');
await page.screenshot({ path: 'report.png', fullPage: true });
Choose the navigation condition and any page-specific check for the site you are capturing. A network-idle wait is a navigation strategy, not a universal guarantee about application state.
Set format, quality, and output handling
The screenshot options include path, fullPage, clip, type, quality, omitBackground, and encoding. The default image type is PNG. Quality is a value from 0 to 100 and does not apply to PNG. The available formats and option constraints are documented in the ScreenshotOptions reference.
For example, save a JPEG with a quality setting:
await page.screenshot({
path: 'screenshot.jpg',
type: 'jpeg',
quality: 80
});
For a transparent background, use omitBackground: true where the page and chosen output format support the result:
await page.screenshot({ path: 'transparent.png', omitBackground: true });
Page.screenshot() returns image bytes as a Uint8Array by default, as well as writing to a path when one is provided. With encoding: 'base64', the documented overload returns a string:
const bytes = await page.screenshot();
const base64 = await page.screenshot({ encoding: 'base64' });
Use returned bytes when you want to send or process the image in code instead of saving it directly to a file. Refer to the Page.screenshot() API for return types and supported options.
Outdated 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 matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallBest Value
Common problems and fixes
- No output file: Check the process’s current working directory and ensure the awaited screenshot call completed without throwing. When specifying a relative path, it is relative to that working directory.
- Navigation hangs or fails: The target may not reach the chosen navigation condition, or the site may be unavailable to the browser. Choose an appropriate
waitUntilcondition for the page and handle navigation errors rather than assuming a screenshot was produced. - Screenshot is blank or missing content: The page may need an application-specific selector or another readiness check. A navigation wait alone does not establish that all visual content is ready.
- Full-page capture omits lazy content: Content may load only after scrolling or another interaction. Trigger the page behavior required to load it before capturing, and verify the target content exists.
- Element capture fails: Check that the selector matches an element after navigation. The example explicitly checks for a missing element before invoking its screenshot method.
- Quality setting has no effect: The quality option does not apply to PNG; choose a supported lossy type such as JPEG if you need a quality setting.
Browser setup, reliability, and cost
Puppeteer gives you control over Chromium and the page lifecycle, but your script must launch and manage that browser, choose readiness conditions, and handle site-specific behavior. Screenshot work also consumes the time and resources needed to run the browser and load the target page. The cited API documentation describes screenshot calls and options; it does not establish a universal runtime or cost figure, which depends on your environment and the pages you capture.
Or skip the browser setup
For a direct API capture, send one GET request with the URL and your API key. See the ScreenshotNeo documentation for request parameters and response details.
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 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, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf 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 screenshots.
Sign up free for 1,000 screenshots a month—no card required.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.




