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

Use a headless browser from your MVC application: PuppeteerSharp can navigate to a URL, set a viewport, capture the rendered page as image bytes, and return those bytes through an MVC file response. The approach works for pages rendered with HTML, CSS, and JavaScript; for production, validate the destination URL and configure timeouts and browser resources for your hosting environment.

Capture a webpage with PuppeteerSharp

PuppeteerSharp is a .NET port of Puppeteer that provides a C# API for controlling headless Chrome or Chromium. The basic flow is to launch the browser, create a page, navigate to the requested address, and capture the result. See the PuppeteerSharp documentation and its NuGet package page for package and API details.

Install the package

Add PuppeteerSharp to the ASP.NET MVC project using NuGet or the .NET CLI:

dotnet add package PuppeteerSharp

The package controls a Chromium-based browser. Make sure the browser runtime is available in the environment where the application runs; a local development setup does not guarantee that a production host has the same browser installation or dependencies.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Add an MVC action

This example downloads the browser, opens a page, sets a viewport, captures the entire document as PNG bytes, and returns the image as a downloadable file:

using PuppeteerSharp;

public async Task<ActionResult> Screenshot(string url)
{
    await new BrowserFetcher().DownloadAsync();
    await using var browser = await Puppeteer.LaunchAsync(
        new LaunchOptions { Headless = true });
    await using var page = await browser.NewPageAsync();
    await page.SetViewportAsync(new ViewPortOptions { Width = 1440, Height = 900 });
    await page.GoToAsync(url);
    var bytes = await page.ScreenshotDataAsync(
        new ScreenshotOptions { FullPage = true });
    return File(bytes, "image/png", "page.png");
}

The browser download inside the action keeps the example self-contained, but it is usually better to provision or cache the browser as part of application startup or deployment rather than download it for every request. Returning a file with the image MIME type lets MVC send the image bytes directly; no publicly accessible intermediate image file is necessary.

Use this pattern safely

A screenshot endpoint that accepts an arbitrary URL can become a server-side request forgery (SSRF) route: a caller may try to make your server access internal services or machine metadata endpoints. Do not expose the sample action unchanged. Apply controls appropriate to your application:

  • Allow only approved hosts or domains, and reject loopback, private-network, link-local, and otherwise disallowed destination addresses. Recheck redirects so an allowed URL cannot redirect the browser to a prohibited host.
  • Require authentication or authorization if captures are not intended to be public.
  • Set navigation and overall request timeouts, limit concurrent browser work, and cap the maximum page dimensions or output size your service will accept.
  • Run the browser with only the permissions it needs and consider network egress restrictions for the capture process.
  • Decide whether captures may access pages that require credentials. Avoid accepting arbitrary user-supplied cookies or authorization headers without a clear access policy.

These are application and deployment responsibilities; a browser library does not make an unrestricted URL endpoint safe by itself.

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

Choose the capture size and output

Viewport screenshot or full page

Set the viewport before navigation when the page layout must match a known screen size. In the example, 1440 by 900 pixels defines the browser’s visible viewport. Without full-page capture, the screenshot represents the visible browser area. Set FullPage = true when the output should extend through the scrollable document. Very long pages can produce large images and consume more memory, so decide whether a viewport image or full-document image is actually needed.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Capture a region or element

For a selected region rather than the whole page, PuppeteerSharp provides screenshot clipping options. Use coordinates and dimensions that correspond to the rendered page and confirm the desired output when responsive layouts change. If the goal is to capture a particular element by its selector, locate the element and use an element-focused capture approach supported by your PuppeteerSharp version. Selenium also documents screenshots of a selected WebElement; that may be convenient in a project already built around WebDriver.

Select an image format

PuppeteerSharp’s screenshot options support PNG, JPEG, and WebP through the Type setting. JPEG and WebP can use a Quality value; quality is relevant to those lossy formats, not PNG. Match the response MIME type and filename to the format you request—for example, use image/jpeg with a .jpg filename. PNG is a straightforward default when you want lossless output.

Choose how to receive the bytes

Use ScreenshotDataAsync when the MVC action should return a byte array, as in the example. PuppeteerSharp also provides ScreenshotStreamAsync for stream-based handling and ScreenshotBase64Async when a Base64 representation is specifically needed. A file response is generally simpler than converting image data to Base64 for an ordinary browser download or display.

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

Wait for the page you actually need

A successful navigation does not guarantee that every part of a modern page is ready for capture. JavaScript may continue rendering after the initial document loads; images, ads, and other resources can arrive later. Choose a wait condition based on the target site and the content you need, then capture only after that condition is met. A fixed delay is simple but can waste time on fast pages and still be too short on slow ones. Waiting for a specific selector can be more meaningful when the element signals that the required content is ready.

The exact wait condition is application-specific. Test it against pages with delayed content, errors, and varying network speed rather than assuming one generic navigation setting fits every site. Set finite timeouts and decide how the action should respond when the target never reaches the expected state.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Return the screenshot from an MVC controller

The example returns File(bytes, "image/png", "page.png"), which sends the bytes with an image content type and a filename. If the intended experience is to show the image inline rather than prompt a download, use an MVC response pattern appropriate to the project’s framework version and omit or adjust the download filename as needed. Keep the MIME type consistent with the actual encoding.

For large results or higher-throughput workflows, a stream or object-storage pipeline may be more appropriate than holding every image in memory until an MVC response completes. The right choice depends on output size, request concurrency, and whether the application needs to retain captures after returning the response.

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

When Selenium is the better fit

Selenium’s .NET Screenshot represents an image of the page currently loaded in a browser, and its API includes SaveAsFile for PNG output. Its documentation also covers element screenshots and headless Chrome configuration. See the Selenium .NET API reference and Selenium documentation.

Choose Selenium when your application already has WebDriver setup, browser-driver infrastructure, or test automation that you want to reuse. PuppeteerSharp is a direct Chromium-first option when you need a compact C# screenshot flow and its full-page or clipping controls. Neither choice removes the need to provision the browser and test behavior in the actual hosting environment.

Performance, reliability, and cost considerations

  • Browser startup: Launching a fresh browser for every MVC request adds work. Reusing browser processes can reduce repeated startup costs, but requires lifecycle management, limits on concurrent pages, and recovery when a browser process fails.
  • Memory and output size: Full-page captures of tall documents and high-resolution viewports can produce large buffers. Bound concurrency and reject impractical dimensions or targets to protect application resources.
  • Timeout behavior: Navigation, page readiness, and screenshot generation can each fail or stall. Set deadlines, handle exceptions, and return an appropriate HTTP error rather than leaving requests open indefinitely.
  • Browser compatibility: PuppeteerSharp’s documented API is Chromium-focused. If your application needs a different browser engine, validate that requirement before choosing the implementation.
  • Deployment: The host must support the browser runtime and its operating-system dependencies. Test the deployed image or server configuration, not only a developer workstation.
  • Cost: Self-hosting means accounting for compute, memory, storage if captures are retained, and operational maintenance. There is no benchmark or universal per-capture cost established here; measure against your own page mix and hosting setup.

Or skip the browser setup

If you want an HTTP screenshot service instead of provisioning Chromium in your MVC application, ScreenshotNeo accepts one GET request with a URL and returns an image or PDF. Its API supports PNG, JPEG, and WebP output, along with full-page capture, element selection, device and viewport settings, custom CSS and JavaScript, and other capture controls. See the ScreenshotNeo API documentation for request parameters.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; these steps can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides screenshot and page-information tools for AI agents. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.

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

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

Browser launch fails on the server

Likely cause: Chromium was not downloaded, is incompatible with the host, or a required operating-system dependency is missing. Fix: Provision the browser during deployment, confirm the runtime can execute it, and inspect the host’s browser launch error. Avoid relying on a development machine’s cached browser.

The action times out while navigating

Likely cause: The site is slow, never reaches the selected readiness condition, or waits on resources that do not finish. Fix: Use a finite navigation timeout and a readiness condition aligned with the content you need. For dynamic pages, wait for a meaningful selector or application state rather than assuming that the initial response means rendering is complete.

The screenshot is blank or missing content

Likely cause: The capture happened before client-side rendering or delayed images completed, or the target blocks automated traffic. Fix: Verify that the page is reachable from the server, wait for the relevant content, and inspect the page’s rendered state before capture. Do not treat a successful browser navigation as proof that the desired content appeared.

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.

The returned file does not open correctly

Likely cause: The requested screenshot type, response MIME type, and file extension do not match. Fix: Set the screenshot format explicitly and use the corresponding response content type and filename. Check that the response contains image bytes rather than an HTML error page.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Captures work locally but fail in production

Likely cause: Different browser binaries, host permissions, runtime dependencies, network rules, or memory limits. Fix: reproduce the production deployment configuration, verify outbound access to the allowed target, and review process permissions and resource limits.

Frequently asked questions

Can an ASP.NET MVC action return a screenshot without saving it first?

Yes. Capture bytes with ScreenshotDataAsync and return them with MVC’s File response, as shown above.

Does a screenshot include JavaScript-rendered content?

A headless browser renders the page rather than merely downloading its HTML, so it can capture client-rendered content once that content has appeared. Your code still needs to wait for the page state it requires.

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

Can PuppeteerSharp capture a full webpage?

Yes. Set FullPage = true in ScreenshotOptions to capture the scrollable document rather than only the viewport.

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.