Puppeteer Sharp is a .NET port of the official Node.JS Puppeteer API.
await Downloader.CreateDefault().DownloadRevisionAsync(chromiumRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true
}, chromiumRevision);
var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.google.com");
await page.ScreenshotAsync(outputFile));
You can also change the view port before generating the screenshot
await page.SetViewport(new ViewPortOptions
{
Width = 500,
Height = 500
});
await Downloader.CreateDefault().DownloadRevisionAsync(chromiumRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true
}, chromiumRevision);
var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.google.com");
await page.PdfAsync(outputFile));
using(var page = await Browser.NewPageAsync())
{
await page.SetContentAsync("<div>My Receipt</div>");
var result = await page.GetContentAsync();
await page.PdfAsync(outputFile);
SaveHtmlToDB(result);
}
using (var page = await Browser.NewPageAsync())
{
var seven = await page.EvaluateFunctionAsync<int>(“4 + 3”);
var someObject = await page.EvaluateFunctionAsync<dynamic>("(value) => ({a: value})", 5);
Console.WriteLine(someObject.a);
}
Getting to all the 523 tests Puppeteer has, will be a long and fun journey. So, this will be the roadmap for Puppeteer Sharp 1.0:
The first 0.1 will include:
- Browser download
- Basic browser operations: create a browser, a page and navigate a page.
- Take screenshots.
- Print to PDF.
This version won't include a new version. It will be about improving the repository:
- Setup CI.
- Create basic documentation (Readme, contributing, code of conduct).
It will implement all Puppeteer related tests.
It will implement all Page tests except the ones testing the evaluate method. As this will be quite a big version, I think we will publish many 0.3.X versions before 0.4.
It will implement all Frame tests.
It will implement all the test related to setting values to inputs and clicking on elements.
At this point, We will have implemented most features, except the ones which are javascript related. I believe there will be many versions between 0.6 and 1.0.
The 1.0 version will have all (or most) Puppeteer features implemented. I don't know if we'll be able to cover 100% of Puppeteer features, due to differences between both technologies, but we'll do our best.
- Tests on Google's Puppeteer: 554.
- Tests on Puppeteer Sharp: 55.
- Passing tests: 55.