Class Puppeteer
- Namespace
- PuppeteerSharp
- Assembly
- PuppeteerSharp.dll
Provides a method to launch a Chromium instance.
public static class Puppeteer
- Inheritance
-
Puppeteer
Examples
The following is a typical example of using a Puppeteer to drive automation:
var browser = await Puppeteer.LaunchAsync(new LaunchOptions());
var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.google.com");
await Browser.CloseAsync();
Properties
Devices
Returns a list of devices to be used with EmulateAsync(DeviceDescriptor).
public static IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor> Devices { get; }
Property Value
Examples
var iPhone = Puppeteer.Devices[DeviceDescriptorName.IPhone6];
using(var page = await browser.NewPageAsync())
{
await page.EmulateAsync(iPhone);
await page.goto('https://www.google.com');
}
ExtraJsonSerializerContext
Extra IJsonTypeInfoResolver used to serialize and deserialize objects on AOT environments.
public static IJsonTypeInfoResolver ExtraJsonSerializerContext { get; set; }
Property Value
Remarks
This property must be set before using any PuppeteerSharp API.
NetworkConditions
Returns a list of network conditions to be used with EmulateNetworkConditionsAsync(NetworkConditions). Actual list of conditions can be found in Conditions.
public static IReadOnlyDictionary<string, NetworkConditions> NetworkConditions { get; }
Property Value
Examples
var slow3G = Puppeteer.NetworkConditions["Slow 3G"];
using(var page = await browser.NewPageAsync())
{
await page.EmulateNetworkConditionsAsync(slow3G);
await page.goto('https://www.google.com');
}
Methods
ConnectAsync(ConnectOptions, ILoggerFactory)
Attaches Puppeteer to an existing Chromium instance. The browser will be closed when the Browser is disposed.
public static Task<IBrowser> ConnectAsync(ConnectOptions options, ILoggerFactory loggerFactory = null)
Parameters
optionsConnectOptionsOptions for connecting.
loggerFactoryILoggerFactoryThe logger factory.
Returns
CreateBrowserFetcher(BrowserFetcherOptions)
Creates the browser fetcher.
public static IBrowserFetcher CreateBrowserFetcher(BrowserFetcherOptions options)
Parameters
optionsBrowserFetcherOptionsOptions.
Returns
- IBrowserFetcher
The browser fetcher.
GetDefaultArgs(LaunchOptions)
Returns an array of argument based on the options provided and the platform where the library is running.
public static string[] GetDefaultArgs(LaunchOptions options = null)
Parameters
optionsLaunchOptionsOptions.
Returns
- string[]
Chromium arguments.
LaunchAsync(LaunchOptions, ILoggerFactory)
The method launches a browser instance with given arguments. The browser will be closed when the Browser is disposed.
public static Task<IBrowser> LaunchAsync(LaunchOptions options, ILoggerFactory loggerFactory = null)
Parameters
optionsLaunchOptionsOptions for launching Chrome.
loggerFactoryILoggerFactoryThe logger factory.
Returns
Remarks
See this article for a description of the differences between Chromium and Chrome. This article describes some differences for Linux users.
Environment Variables Puppeteer looks for certain environment variables() to aid its operations.
PUPPETEER_CHROMIUM_REVISION- specify a certain version of Chromium you'd like Puppeteer to use. See LaunchAsync(LaunchOptions, ILoggerFactory) on how executable path is inferred. BEWARE: Puppeteer is only guaranteed to work with the bundled Chromium, use at your own risk.PUPPETEER_EXECUTABLE_PATH- specify an executable path to be used in LaunchAsync(LaunchOptions, ILoggerFactory). BEWARE: Puppeteer is only guaranteed to work with the bundled Chromium, use at your own risk.
SetFollowSymlinks(bool)
Defines whether Puppeteer should follow symlinks for file operations.
public static void SetFollowSymlinks(bool followSymlinks)
Parameters
followSymlinksboolWhether Puppeteer should follow symlinks.