Puppeteer Sharp
Drive the browser from C#.
A .NET port of the Node.js Puppeteer API. Launch Chrome or Firefox, open a page, and click, type, screenshot, or print a PDF.
dotnet add package PuppeteerSharpThe package targets netstandard2.0, net8.0, and net10.0.PuppeteerSharp on NuGet.
using var browser = await Puppeteer.LaunchAsync(
new LaunchOptions { Headless = true });
var page = await browser.NewPageAsync();
await page.GoToAsync("https://example.com");
await page.ScreenshotAsync("screenshot.png");Targets
netstandard2.0
Plus net8.0 and net10.0
Browsers
Chrome
And Firefox, headless or headful
License
MIT
Free for commercial use
Why Puppeteer Sharp
The Puppeteer API, on the runtimes you already ship.
Navigation, input, network interception, screenshots, and PDFs. Headless or headful, on Windows, macOS, and Linux.
Chrome and Firefox
Launch a browser, open a page, and drive navigation, input, and network interception. Headless and headful both work.
Browser automationScreenshots and PDFs
Take a screenshotScreenshotAsyncwrites a file. Full-page capture, custom viewports, and clipping are in the screenshot guide.PdfAsyncprints the page.Locators that wait
Locators guidePage.Locatorre-finds the element on every action and retries until it is visible, enabled, and in view.CDP and WebDriver BiDi
Chrome DevTools Protocol and WebDriver BiDi are both first-class. Pick the protocol that fits the browser.
Dual protocol
Get started
From an empty project to a screenshot, in three steps.
Install the package, open a page, then screenshot it or click with a locator. Each step links to the page that has the rest.
Read the docsInstall the package
Add
PuppeteerSharp. It targetsnetstandard2.0,net8.0, andnet10.0.
Quick startdotnet add package PuppeteerSharpOpen a page and save a screenshot
LaunchAsyncstarts Chrome.GoToAsyncloads the URL.ScreenshotAsyncwrites the file.
Screenshot guideawait page.GoToAsync("https://example.com"); await page.ScreenshotAsync("screenshot.png");Click with a locator
A locator waits until the element is enabled and in the viewport, then clicks it.
Locators guideawait page.Locator("button.submit") .SetWaitForEnabled(true) .SetEnsureElementIsInTheViewport(true) .ClickAsync();