Yes, Puppeteer-Sharp is compatible with both .NET Core and .NET Framework. Puppeteer-Sharp is a .NET port of the Node library Puppeteer which provides a high-level API over the Chrome DevTools Protocol. Puppeteer-Sharp is intended to be used for headless Chrome automation purposes, such as generating PDFs, taking screenshots, or automating form submissions.
Puppeteer-Sharp targets .NET Standard 2.0, which makes it compatible with a wide range of .NET implementations, including:
- .NET Core 2.0 and above
- .NET Framework 4.6.1 and above
- Mono 5.4 and above
- Xamarin.iOS 10.14 and above
- Xamarin.Mac 3.8 and above
- Xamarin.Android 8.0 and above
- Universal Windows Platform (UWP) 10.0.16299 and above
To use Puppeteer-Sharp in a .NET Core or .NET Framework project, you can install it via NuGet Package Manager. Here's how you can do it using the NuGet Package Manager Console:
Install-Package PuppeteerSharp
Or you can use the .NET CLI to add Puppeteer-Sharp to your project:
dotnet add package PuppeteerSharp
Here's a simple example of how to use Puppeteer-Sharp in a C# project:
using System;
using System.Threading.Tasks;
using PuppeteerSharp;
class Program
{
public static async Task Main(string[] args)
{
// Download the Chromium revision if it does not already exist
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
// Launch the browser
using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true // Launch in headless mode
});
// Create a new page
using var page = await browser.NewPageAsync();
// Navigate to a website
await page.GoToAsync("https://example.com");
// Take a screenshot of the page
await page.ScreenshotAsync("example.png");
Console.WriteLine("Screenshot taken.");
// Always close the browser explicitly
await browser.CloseAsync();
}
}
In this example, Puppeteer-Sharp is used to launch a headless browser, navigate to "https://example.com", and take a screenshot of the page.
Puppeteer-Sharp provides a wide range of features that enable .NET developers to control headless Chrome browsers programmatically. If you are working with .NET Core or .NET Framework, Puppeteer-Sharp is a solid choice for web automation and scraping tasks.