Puppeteer
Namespace: PuppeteerSharp
public static class PuppeteerProvides 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();Properties
Section titled “Properties”Devices
Section titled “Devices”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');}ExtraJsonSerializerContext
Section titled “ExtraJsonSerializerContext”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.
NetworkConditions
Section titled “NetworkConditions”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');}Methods
Section titled “Methods”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.
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.
GetDefaultArgs(LaunchOptions)
Section titled “GetDefaultArgs(LaunchOptions)”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.
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/">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">This article</a> describes some differences for Linux users.
Environment Variables Puppeteer looks for certain <a href=“https://en.wikipedia.org/wiki/Environment_variable">environment variables</a>() to aid its operations.
PUPPETEER_CHROMIUM_REVISION- specify a certain version of Chromium you’d like Puppeteer to use. SeeILoggerFactory)on how executable path is inferred. BEWARE: Puppeteer is only <a href=“https://github.com/GoogleChrome/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy">guaranteed to work</a> with the bundled Chromium, use at your own risk.PUPPETEER_EXECUTABLE_PATH- specify an executable path to be used inILoggerFactory). BEWARE: Puppeteer is only <a href=“https://github.com/GoogleChrome/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy">guaranteed to work</a> with the bundled Chromium, use at your own risk.
SetFollowSymlinks(bool)
Section titled “SetFollowSymlinks(bool)”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. |
Made with love by Dario Kondratiuk