Examples

Screenshot of a particular area with C# and Playwright

Install Playwright for .NET and Chromium

dotnet add package Microsoft.Playwright
dotnet build
pwsh bin/Debug/net8.0/playwright.ps1 install chromium

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 of the clip and save to file

using Microsoft.Playwright;

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();

await page.GotoAsync("https://www.htmltoimage.com/demo");
await page.ScreenshotAsync(new()
{
    Path = "clip.png",
    Clip = new() { X = 0, Y = 0, Width = 480, Height = 240 },
});

Find out how to take a full-page screenshot with C# and Playwright.

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.