Table of Contents

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

IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>

Examples

var iPhone = Puppeteer.Devices[DeviceDescriptorName.IPhone6];
using(var page = await browser.NewPageAsync())
{
    await page.EmulateAsync(iPhone);
    await page.goto('https://www.google.com');
}

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

IReadOnlyDictionary<string, NetworkConditions>

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

options ConnectOptions

Options for connecting.

loggerFactory ILoggerFactory

The logger factory.

Returns

Task<IBrowser>

A connected browser.

CreateBrowserFetcher(BrowserFetcherOptions)

Creates the browser fetcher.

public static IBrowserFetcher CreateBrowserFetcher(BrowserFetcherOptions options)

Parameters

options BrowserFetcherOptions

Options.

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

options LaunchOptions

Options.

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

options LaunchOptions

Options for launching Chrome.

loggerFactory ILoggerFactory

The logger factory.

Returns

Task<IBrowser>

A connected browser.

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.