PuppeteerSharp alternatives and similar packages
Based on the "UI Automation" category.
Alternatively, view PuppeteerSharp alternatives based on common mentions on social networks and blogs.
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of PuppeteerSharp or a related project?
README
Puppeteer Sharp
Puppeteer Sharp is a .NET port of the official Node.JS Puppeteer API.
Puppeteer-Sharp 3 is here!
Check out the blog post!
Useful links
- API Documentation
- Slack channel #puppeteer-sharp
- StackOverflow
- Issues
Prerequisites
- As Puppeteer-Sharp is a NetStandard 2.0 library, the minimum platform versions are .NET Framework 4.6.1 and .NET Core 2.0. Read more.
- The minimum Windows versions supporting the WebSocket library are Windows 8 and Windows Server 2012. Read more. If you need to run Puppeteer-Sharp on Windows 7 you can use System.Net.WebSockets.Client.Managed through the LaunchOptions.WebSocketFactory property.
- 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:
- Ask a question on Stack Overflow.
- File a new issue.
Contributing Guide
See this document for information on how to contribute.
Usage
Take screenshots
<!-- snippet: ScreenshotAsync -->
using 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 <!-- endSnippet -->
You can also change the view port before generating the screenshot
<!-- snippet: SetViewportAsync -->
await Page.SetViewportAsync(new ViewPortOptions
{
Width = 500,
Height = 500
});
snippet source | anchor <!-- endSnippet -->
Generate PDF files
<!-- snippet: PdfAsync -->
using 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 <!-- endSnippet -->
Inject HTML
<!-- snippet: SetContentAsync -->
await using var page = await browser.NewPageAsync();
await page.SetContentAsync("<div>My Receipt</div>");
var result = await page.GetContentAsync();
snippet source | anchor <!-- endSnippet -->
Evaluate Javascript
<!-- snippet: Evaluate -->
await using var page = await browser.NewPageAsync();
var seven = await page.EvaluateExpressionAsync<int>("4 + 3");
var someObject = await page.EvaluateFunctionAsync<dynamic>("(value) => ({a: value})", 5);
Console.WriteLine(someObject.a);
snippet source | anchor <!-- endSnippet -->
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");
}
}
Monthly reports
Backers
Support us with a monthly donation and help us continue our activities. Become a backer.
Thanks
Thanks to JetBrains for a community Resharper license to use on this project.
*Note that all licence references and agreements mentioned in the PuppeteerSharp README section above
are relevant to that project's source code only.