Use a browser engine such as Playwright for .NET: launch Chromium, load a URL or HTML string, then capture the page as an image. Playwright can save the screenshot to a file or return image bytes for an ASP.NET response. The key deployment detail is that adding the .NET package does not install Chromium; install the browser binaries and operating-system dependencies that match your Playwright version.
Choose the right input and output
There are two common inputs: a live website URL, or HTML markup supplied by your application. Both use the same browser-based rendering approach, but the loading step differs. For a URL, navigate to it. For markup, assign it to the page before taking the screenshot.
- Save a file: set the screenshot path when you capture.
- Return an HTTP response: capture to a byte array and stream those bytes from an ASP.NET endpoint.
- Capture the whole page: enable full-page capture so the image includes content beyond the current viewport.
- Capture one component: use a locator screenshot when only a visible element is needed.
The examples below use Playwright for .NET. The API and option set can change between package releases, so check the reference for the exact version installed in your project before depending on format-specific settings.
Install Playwright and its browser
Install the Microsoft.Playwright NuGet package, build the project, and then install the browser binaries using the Playwright script generated by the build. The browser executable is a separate runtime requirement; the NuGet dependency alone is not enough to launch Chromium.
#1 Best Overall
- Add the package:
dotnet add package Microsoft.Playwright. - Build the project:
dotnet build. - Run the generated Playwright install script from the build output and install Chromium. The script is under the project’s build output; use the target framework and configuration directory produced by your build. The precise path varies by project.
Keep the Playwright package and browser binaries aligned. Playwright versions are tied to specific browser builds, so after updating the package, rerun browser installation as needed. On Linux, install the operating-system dependencies required by the browser as well as the browser itself.
For containers, use a Playwright Docker image compatible with the application’s Playwright package version. The image includes browsers and system dependencies, but image support is version-sensitive; pin and update the image deliberately rather than assuming the latest image is a match.
Capture a live website in ASP.NET
This minimal ASP.NET Core endpoint creates a Chromium browser, navigates to a URL, and returns a PNG image response. It shows the essential flow; production applications should manage browser lifecycle and concurrency as described below.
using Microsoft.Playwright;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/screenshot", async (string url) =>
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync(url);
var imageBytes = await page.ScreenshotAsync();
return Results.File(imageBytes, "image/png");
});
app.Run();
Call the endpoint with a URL-encoded url query value, for example /screenshot?url=https%3A%2F%2Fexample.com. The sample uses the screenshot API’s documented PNG default. Navigation waits, timeouts, and readiness conditions should be chosen for the target site and your endpoint’s latency budget; a successful navigation does not necessarily mean a client-side application has finished rendering all of its content.
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Save the screenshot to disk
If the endpoint is not returning an image, set the screenshot path instead of returning bytes:
await page.ScreenshotAsync(new PageScreenshotOptions
{
Path = "website.png",
FullPage = true
});
With FullPage = true, Playwright captures the full scrollable page rather than only the current viewport. Ensure the destination directory exists and that the application identity has permission to write there.
Convert an HTML string to an image
For HTML generated by your application, call SetContentAsync instead of navigating to a URL. It assigns the markup to the page, internally using document.write(), then the screenshot captures the rendered result.
using Microsoft.Playwright;
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
var html = "<html><body><h1>Hello</h1><p>Rendered by Chromium</p></body></html>";
await page.SetContentAsync(html);
byte[] imageBytes = await page.ScreenshotAsync();
This is the minimal API shape for rendering markup and getting image bytes; it is not a claim that the snippet has been executed or tested. SetContentAsync defaults to waiting for the page’s load event and has a 30-second default timeout. If the HTML references external fonts, images, stylesheets, or scripts, rendering may depend on those resources loading. Provide suitable wait options for your page’s readiness needs, or render self-contained HTML when predictable output matters.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
For an ASP.NET endpoint, return the resulting bytes with the appropriate MIME type, such as image/png. If you choose JPEG, use the installed version’s screenshot options for format and quality. PNG is the documented default; the current API reference also lists WebP, but verify that option against your installed package version.
Capture only a selected element
When the output should contain a chart, card, or other component rather than the entire page, use a locator and take a screenshot of that element. For example:
var chart = page.Locator("#chart");
await chart.ScreenshotAsync(new LocatorScreenshotOptions
{
Path = "chart.png"
});
The locator must identify the intended element in the rendered page. If the selector matches nothing, matches an unintended element, or the element has not appeared yet, the capture may fail or produce the wrong result. Wait for the selector before taking the screenshot when the page renders it asynchronously.
Adjust viewport, full-page capture, and image format
The browser viewport affects page layout and responsive breakpoints. Set it to the dimensions you need before navigation or rendering. A full-page capture extends the screenshot to the page’s scrollable height, while a normal capture reflects the current viewport. Use a locator capture when the desired output is a particular visible element.
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 →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
Screenshot output can be written to a path or returned as bytes. PNG is the default; JPEG supports a quality option, and WebP is listed by the current API reference. Check the API documentation corresponding to your installed version for exact option names and supported formats before making them part of a public endpoint contract. Image format also affects response headers: return image/jpeg for JPEG and the relevant image MIME type for other formats.
Playwright or PuppeteerSharp?
Playwright for .NET is documented for Chromium, WebKit, and Firefox automation, including URL navigation, assigning HTML, and screenshots. PuppeteerSharp is another .NET browser-control option, with documented headless browser launch, viewport setup, and screenshot APIs. Neither option is established as universally faster, more reliable, or higher fidelity: the available documentation does not provide a controlled comparison.
| Option | Documented capabilities | What to evaluate |
|---|---|---|
| Playwright for .NET | Chromium, WebKit, and Firefox automation; navigation, HTML assignment, and screenshots. | Required browser engine, screenshot options, browser binary installation, OS or container dependencies, and project integration. |
| PuppeteerSharp | .NET port of Puppeteer, with headless launch, viewport setup, and screenshot APIs. | Whether Chrome/Chromium is sufficient, API requirements, browser setup, and deployment fit. |
Choose based on the engine you need, how the browser will be installed and updated in your deployment, and which API fits your application. Treat performance, image fidelity, reliability, and operating cost as things to measure in your own environment rather than assumptions about either library.
Production considerations for an ASP.NET screenshot endpoint
The short examples create a browser for each request because they make the API sequence easy to see. A production service should plan browser lifecycle and concurrent capture work deliberately. Browser processes consume resources; set request timeouts and concurrency limits appropriate to the host, and close pages and browser instances when work is complete. Confirm that your runtime has the matching browser binaries, system libraries, and fonts required by the pages you render.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Best Value
Do not expose an unrestricted endpoint that accepts arbitrary URLs or HTML. A URL-taking endpoint can be abused to make your server request internal network resources; validate destinations and restrict outbound access. Treat supplied HTML as untrusted input, apply suitable limits to request size and execution time, and avoid allowing hostile content to use your service as a general-purpose browser. These are application security and operations considerations, not guarantees provided by the browser automation library.
For repeat captures, decide whether caching is appropriate for your content and freshness requirements. A cache can reduce repeated browser work, but its key should account for all inputs that change rendering, such as URL, viewport, and relevant authentication or content state. Record failures and timeouts separately from successful captures so operational issues can be diagnosed rather than returned as ambiguous image output.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting common failures
- Browser executable is missing: the NuGet package is installed but the required browser binary is not. Build the project and run the generated Playwright install script for the browser you use.
- Browser fails to launch on Linux: install the OS libraries required by the browser, or use a compatible Playwright container image with matching package and browser versions.
- Failure begins after a package update: the installed browser binaries may not match the new Playwright version. Rerun browser installation and align the deployment image.
- Screenshot is blank or incomplete: the page may not have rendered its content when capture started, or external assets may not have loaded. Wait for a relevant selector or suitable readiness condition before capturing.
- HTML resources do not appear: check whether relative resource URLs resolve in the page context and whether the runtime can reach external resources. Consider using absolute URLs or embedding required assets.
- Element screenshot fails: confirm that the locator matches an element and wait for it to become available before capturing.
- Output cannot be written: check the output path, directory existence, and the service process’s filesystem permissions; alternatively return the screenshot byte array directly.
- Image differs between local and deployed environments: compare browser versions, installed fonts, OS dependencies, viewport, and page readiness behavior. Keep browser binaries and deployment images aligned.
Or skip the browser setup
ScreenshotNeo offers a website screenshot API and MCP server for developers. A single GET request can return PNG, JPEG, WebP, or PDF. Its capture flow accepts cookie or consent banners like a visitor 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, with response headers indicating the page verdict and billing status. AI agents can use its MCP tools, including take_screenshot, get_page_info, and capture_pdf.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for request details. ScreenshotNeo’s free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Every feature is available on every plan. Learn more at ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesFrequently Asked Questions
Can I return a screenshot from an ASP.NET endpoint without saving it first?
Yes. Capture to the screenshot API’s byte-array result and return those bytes with the matching image content type.
Does installing Microsoft.Playwright also install Chromium?
No. Install the browser binaries separately with the Playwright script generated by building the project.
Can Playwright capture more than Chromium?
Playwright for .NET documents automation for Chromium, WebKit, and Firefox; install the browser engine your application needs.
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.
Free tools Windows power users keep installed
One-click scans. No signup required.

