Examples

Screenshot of a particular quality with C# and Puppeteer

Install PuppeteerSharp

dotnet add package PuppeteerSharp

PuppeteerSharp is the .NET port of Puppeteer. BrowserFetcher.DownloadAsync() downloads a compatible Chrome on first run. The examples use C# top-level statements — put them in Program.cs of a console project (dotnet new console) and run with dotnet run.

Take a screenshot with the quality level set and save to file

using PuppeteerSharp;

await new BrowserFetcher().DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
await using var page = await browser.NewPageAsync();

await page.GoToAsync("https://www.htmltoimage.com/demo");
await page.ScreenshotAsync("quality.jpg", new ScreenshotOptions
{
    Type = ScreenshotType.Jpeg,
    Quality = 75,
});

Find out how to change the size of the viewport with C# and Puppeteer.

That was 12 lines of code — plus a browser to run in production

Keeping headless browsers fed, patched and scaled is a job in itself. We built Urlbox so the same screenshot is one API call:

curl "https://api.urlbox.com/v1/YOUR_API_KEY/png?url=https://example.com"

Try the Urlbox screenshot API — free trial, no browser babysitting.