Skip to content
프로젝트

소개

헤드리스 Chrome용 .NET API

생산성 및 자동화

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
+1
in 1 month
+3

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Puppeteer Sharp

NuGet Build status Demo build status Backers

Puppeteer Sharp is a .NET port of the official Node.JS Puppeteer API.

Recent news

Test the latest Firefox versions using WebDriver BiDi! Check the PuppeteerSharp 21 release notes.

PuppeteerSharp now supports AOT compilation! Check the PuppeteerSharp 19 release notes!.

Useful links

Published Packages

Package Description
PuppeteerSharp Our full cross-browser automation tool
PuppeteerSharp.Cdp Ideal for Chrome-only AOT apps where binary size matters
PuppeteerSharp.AspNetFramework The companion library you need to run PuppeteerSharp in ASP.NET Classic

Prerequisites

  • Puppeteer-Sharp comes in two flavors: a NetStandard 2.0 library for .NET Framework 4.6.1 and .NET Core 2.0 or greater and a .NET 8 version.
  • If you have issues running Chrome on Linux, the Puppeteer repo has a great troubleshooting guide.
  • X-server is required on Linux.

How to Contribute and Provide Feedback

Some of the best ways to contribute are to try things out file bugs and fix issues.

If you have an issue or a question:

Contributing Guide

See this document for information on how to contribute.

Usage

Take screenshots

var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(
    new LaunchOptions { Headless = true }
);
await using var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com");
await page.ScreenshotAsync(outputFile);

snippet source | anchor

You can also change the view port before generating the screenshot

await Page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 });

snippet source | anchor

Generate PDF files

var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(
    new LaunchOptions { Headless = true }
);
await using var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com"); // In case of fonts being loaded from a CDN, use WaitUntilNavigation.Networkidle0 as a second param.
await page.EvaluateExpressionHandleAsync("document.fonts.ready"); // Wait for fonts to be loaded. Omitting this might result in no text rendered in pdf.
await page.PdfAsync(outputFile);

snippet source | anchor

Inject HTML

await using var page = await browser.NewPageAsync();
await page.SetContentAsync("<div>My Receipt</div>");
var result = await page.GetContentAsync();

snippet source | anchor

Evaluate Javascript

await using var page = await browser.NewPageAsync();
var seven = await page.EvaluateExpressionAsync<int>("4 + 3");
var someObject = await page.EvaluateFunctionAsync<JsonElement>(
    "(value) => ({a: value})",
    5
);
Console.WriteLine(someObject.GetProperty("a").GetString());

snippet source | anchor

Wait For Selector

using (var page = await browser.NewPageAsync())
{
    await page.GoToAsync("http://www.spapage.com");
    await page.WaitForSelectorAsync("div.main-content")
    await page.PdfAsync(outputFile));
}

Wait For Function

using (var page = await browser.NewPageAsync())
{
    await page.GoToAsync("http://www.spapage.com");
    var watchDog = page.WaitForFunctionAsync("()=> window.innerWidth < 100");
    await page.SetViewportAsync(new ViewPortOptions { Width = 50, Height = 50 });
    await watchDog;
}

Connect to a remote browser

var options = new ConnectOptions()
{
    BrowserWSEndpoint = $"wss://www.externalbrowser.io?token={apikey}"
};

var url = "https://www.google.com/";

using (var browser = await PuppeteerSharp.Puppeteer.ConnectAsync(options))
{
    using (var page = await browser.NewPageAsync())
    {
        await page.GoToAsync(url);
        await page.PdfAsync("wot.pdf");
    }
}

Sponsors

Supporters

Byteful logo.

Byteful supplies ethical residential, mobile, ISP, and datacenter proxies, plus scraping and AI automation tools. Use code PUPPETEERSHARP: 10% off residential proxies.

Byteful: the fastest proxies on the market. Use code PUPPETEERSHARP for 10% off.

SerpApi logo.

SerpApi is the world's leading provider of search data, pioneering APIs that turn search engine results into structured, developer-ready information.

IronPDF logo.

PuppeteerSharp is sponsored by IronPDF, a commercial C# .NET PDF library and HTML-to-PDF alternative with Chrome rendering, PDF editing, digital signatures, encryption, enterprise licensing, and 24/7 engineering support.

And a huge thanks to everyone who sponsors this project through Github sponsors:

User avatar: Tolga BalciUser avatar: Richard GarsideUser avatar: HTML/CSS to Image APIUser avatar: Iron SoftwareUser avatar: Alex-Byteful

관련 프로젝트 살펴보기

불러오는 중…