Skip to content

Puppeteer

Namespace: PuppeteerSharp

public static class Puppeteer

Provides a method to launch a Chromium instance.

Inheritance: object

Example

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();

View source

public static IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor> Devices { get; }

Returns a list of devices to be used with EmulateAsync(DeviceDescriptor).

Value: IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>

Example

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

View source

public static IJsonTypeInfoResolver ExtraJsonSerializerContext { get; set; }

Extra IJsonTypeInfoResolver used to serialize and deserialize objects on AOT environments.

Value: IJsonTypeInfoResolver

This property must be set before using any PuppeteerSharp API.

View source

public static IReadOnlyDictionary<string, NetworkConditions> NetworkConditions { get; }

Returns a list of network conditions to be used with EmulateNetworkConditionsAsync(NetworkConditions). Actual list of conditions can be found in Conditions.

Value: IReadOnlyDictionary<string, NetworkConditions>

Example

var slow3G = Puppeteer.NetworkConditions["Slow 3G"];
using(var page = await browser.NewPageAsync())
{
await page.EmulateNetworkConditionsAsync(slow3G);
await page.goto('https://www.google.com');
}

View source

ConnectAsync(ConnectOptions, ILoggerFactory)

Section titled “ConnectAsync(ConnectOptions, ILoggerFactory)”
public static Task<IBrowser> ConnectAsync(ConnectOptions options, ILoggerFactory loggerFactory = null)

Attaches Puppeteer to an existing Chromium instance. The browser will be closed when the Browser is disposed.

Parameters

Name Type Description
options ConnectOptions Options for connecting.
loggerFactory ILoggerFactory The logger factory.

Returns: Task<IBrowser> — A connected browser.

View source

CreateBrowserFetcher(BrowserFetcherOptions)

Section titled “CreateBrowserFetcher(BrowserFetcherOptions)”
public static IBrowserFetcher CreateBrowserFetcher(BrowserFetcherOptions options)

Creates the browser fetcher.

Parameters

Name Type Description
options BrowserFetcherOptions Options.

Returns: IBrowserFetcher — The browser fetcher.

View source

public static string[] GetDefaultArgs(LaunchOptions options = null)

Returns an array of argument based on the options provided and the platform where the library is running.

Parameters

Name Type Description
options LaunchOptions Options.

Returns: string[] — Chromium arguments.

View source

LaunchAsync(LaunchOptions, ILoggerFactory)

Section titled “LaunchAsync(LaunchOptions, ILoggerFactory)”
public static Task<IBrowser> LaunchAsync(LaunchOptions options, ILoggerFactory loggerFactory = null)

The method launches a browser instance with given arguments. The browser will be closed when the Browser is disposed.

Parameters

Name Type Description
options LaunchOptions Options for launching Chrome.
loggerFactory ILoggerFactory The logger factory.

Returns: Task<IBrowser> — A connected browser.

See <a href=“https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/"&gt;this article</a> for a description of the differences between Chromium and Chrome. <a href=“https://chromium.googlesource.com/chromium/src/+/lkcr/docs/chromium_browser_vs_google_chrome.md"&gt;This article</a> describes some differences for Linux users.

Environment Variables Puppeteer looks for certain <a href=“https://en.wikipedia.org/wiki/Environment_variable"&gt;environment variables</a>() to aid its operations.

View source

public static void SetFollowSymlinks(bool followSymlinks)

Defines whether Puppeteer should follow symlinks for file operations.

Parameters

Name Type Description
followSymlinks bool Whether Puppeteer should follow symlinks.

View source

Made with love by Dario Kondratiuk