“Browser-based screenshot API” can mean either a screenshot method in a browser automation library or a hosted service that accepts a request and returns an image. This guide shows the do-it-yourself library workflow with Playwright and Puppeteer: open a page, capture the viewport, full document, or a particular element, then save the image or keep its bytes in memory. If you mean a hosted API and would rather not set up a browser, see the ScreenshotNeo option below.
What “browser-based screenshot API” means
Playwright and Puppeteer are libraries you call from your own code to control a browser. Their screenshot methods capture what that browser renders. You are responsible for installing and running the browser, navigating to the target, choosing capture settings, and deciding what to do with the resulting file or bytes.
A hosted screenshot API has a different shape: your application sends a request to a service, which performs the browser work and returns a result. The code below covers the library meaning first. For a hosted service, ScreenshotNeo accepts a GET request with a URL and returns a screenshot or PDF; its API details are documented at ScreenshotNeo’s documentation.
Choose Playwright or Puppeteer
Both libraries support the core pattern: navigate to a page and call a screenshot method. Choose based on the language, runtime, and browser automation setup your project already uses, then check the matching API reference for the version you have installed. The documentation supports comparing capture modes and options, but does not establish that one library is universally faster or better.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errors#1 Best Overall
- Playwright: Use it when it fits your existing project and you want its documented page and locator screenshot workflows. It can save to a path, capture the full page, capture an element, or return a buffer. See Playwright’s screenshot guide.
- Puppeteer: Use it when it fits your existing project’s browser automation stack. Its
page.screenshot()returns image bytes by default, with options for a file path, clipping, full-page capture, image type, and other behavior that depends on the installed version. See the Puppeteer Page screenshot API reference.
Capture a page with Playwright
After installing Playwright and the browser required by your setup, create a page, navigate to the target, and call page.screenshot(). This minimal JavaScript example saves a viewport screenshot. Replace the URL with a page you are permitted to access.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
} finally {
await browser.close();
}
})();
The path determines where the image is written. The example uses the browser’s default viewport; it does not request the entire scrollable document. Keep the try/finally structure in scripts so the browser closes even if navigation or capture fails.
Capture the full page
For a page-long image rather than just the visible viewport, pass fullPage: true. This captures the scrollable document, which can produce a much taller file than a viewport shot.
await page.screenshot({ path: 'full-page.png', fullPage: true });
Capture one element
When you only need a card, form, or other component, use a locator screenshot instead of capturing the entire page. The locator must match an element present on the page.
Rank #2
- Used Book in Good Condition
await page.locator('.product-card').screenshot({ path: 'product-card.png' });
Keep the image bytes in memory
If the next step is uploading, comparing, or processing the image, ask Playwright for a buffer instead of writing a file. A screenshot call without a path returns the image data.
const imageBytes = await page.screenshot();
// Pass imageBytes to your upload or image-processing code.
For more capture options and current details, consult the Playwright screenshot guide and the reference for your installed version.
Capture a page with Puppeteer
Puppeteer’s screenshot method follows the same broad workflow: navigate, then capture. This example uses CommonJS and saves a screenshot to a path. Install Puppeteer and its browser as required by your project before running it.
const puppeteer = require('puppeteer');
(async () => {
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();
}
})();
Puppeteer returns image bytes by default if you do not provide a path. Its API also documents options such as clipping a region, capturing a full page, selecting an image type, and setting quality for applicable formats. PNG is the documented default. The availability and exact behavior of options can depend on your Puppeteer version, so use the API reference that matches your installed package.
Recommended Free Tools
Rank #3
const imageBytes = await page.screenshot();
// Use imageBytes directly, or provide a path to save the screenshot.
For the supported options, including format and transparency behavior, check the Puppeteer screenshot API reference.
Choose the capture mode and output
| Need | Approach | What to account for |
|---|---|---|
| What is visible in the browser window | Capture the page without enabling full-page mode. | The image covers the viewport, not the rest of the scrollable document. |
| The scrollable document | Use Playwright’s fullPage: true or Puppeteer’s full-page option. |
The resulting image can be much taller than the viewport. |
| A single component | Use a Playwright locator screenshot or a library’s element or clipping option. | Make sure the selector identifies the intended element and that it is present before capture. |
| A file to inspect or archive | Pass a path to the screenshot method. | Use a path that the process can write to; consider where relative paths resolve in your runtime. |
| Bytes for further processing | Omit the path and retain the returned buffer or image bytes. | Pass the bytes to your next step rather than treating them as a filename. |
| Specific format or appearance | Set the relevant library-specific image options. | Supported types, quality, and transparent background behavior differ by library and version. |
Make screenshots repeatable
A screenshot is the rendered output of a browser environment, not just a copy of a URL. For reliable visual comparisons, keep the rendering setup consistent. Playwright notes that results can vary with the host operating system, browser version, settings, hardware, power source, and headless mode. See Playwright’s guidance on visual comparisons.
- Use the same browser version and operating system for baseline creation and later comparisons.
- Keep browser settings and headless mode consistent.
- Use the same viewport and capture mode each time.
- Wait for the page state your test actually needs before capturing; a screenshot taken while content is still changing may not match a later run.
These controls reduce avoidable differences; they do not guarantee identical pixels across different machines or changing page content.
Troubleshoot common failures
The browser does not launch
Likely cause: The required browser is missing, or the runtime cannot start it. Fix: Follow the installation instructions for the library and browser version in your project, then confirm the process can launch that browser in its runtime environment.
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 →Clear out junk files and repair common Windows errorsFree Scan →Rank #4
Navigation fails or the page is incomplete
Likely cause: The URL is unreachable from the running environment, navigation did not complete as expected, or the page was captured before the content you need appeared. Fix: Verify the URL and network access, inspect navigation errors, and wait for the specific page state needed by your capture rather than assuming every site is ready at the same moment.
The screenshot is only the visible portion
Likely cause: The call captured the viewport, which is the default pattern in the examples. Fix: Enable full-page capture using the option supported by your library and version.
The element screenshot fails or captures the wrong region
Likely cause: The selector did not match the intended element, or the element was not yet present. Fix: Check the selector against the rendered page and wait for the target element before calling its screenshot method.
No file appears
Likely cause: The destination path is not writable or is not where you expected. Fix: Check the process’s working directory, destination path, and write permissions. If you omitted the path, use the returned bytes instead of looking for a file.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
The image format or option is rejected
Likely cause: Screenshot option names and supported values are library- and version-specific. Fix: Consult the API reference for the version installed in your project; do not assume an option documented for one library applies to the other.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, reliability, and cost considerations
With a library, your application runs the browser and handles the output. That makes browser startup, navigation, and capture part of your own job’s execution and resource use. Reusing a browser or running work concurrently may affect resource use, but the appropriate design depends on your workload and runtime; the cited documentation does not establish a universal performance winner or benchmark.
For visual tests, environmental consistency matters more than choosing a supposedly faster library: differences in operating system, browser version, settings, hardware, power source, or headless mode can alter rendering. For operational reliability, handle navigation and capture errors, close browser processes on both success and failure, and avoid treating a file as valid until the screenshot call completes.
The library examples have no hosted-service per-shot price because they run in your environment. Your actual costs depend on the infrastructure and maintenance you choose; no cost estimate is established here. A hosted API moves browser execution to a service and has its own pricing and response behavior, which you should verify in that service’s documentation.
Or skip the browser setup
If you want a hosted screenshot API instead of installing and running Playwright or Puppeteer, ScreenshotNeo takes one GET request with a URL and returns a clean screenshot as PNG, JPEG, or WebP, or a PDF. Its documented API details are at ScreenshotNeo’s documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
Replace YOUR_API_KEY with your key and change the target URL as needed. ScreenshotNeo can accept cookie banners and remove 60+ known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and whether the shot was billed. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The free plan includes 1,000 screenshots 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 I use either library from Python?
The runnable library examples here use JavaScript. Check the official documentation for the language and runtime you plan to use; the screenshot method and setup are library-specific.
Does a screenshot API always mean a hosted service?
No. The phrase can also refer to a browser automation library’s screenshot method, which is the do-it-yourself approach explained here.
Windows 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 reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteQuick 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.




