Skip to content

LaunchOptions

Namespace: PuppeteerSharp

public class LaunchOptions : IBrowserOptions, IConnectionOptions

Options for launching the Chrome/ium browser.

Inheritance: object

Implements: IBrowserOptions, IConnectionOptions

View source

public bool AcceptInsecureCerts { get; set; }

Whether to ignore HTTPS errors during navigation. Defaults to false.

Value: bool

View source

public string[] Allowlist { get; set; }

A list of URL patterns to allow. When set, the browser can only access URLs matching these patterns.

Value: string[]

<p> Requires Chrome 149+. </p> <p> This option allows you to restrict the browser from accessing any URLs except for those that match the patterns in the allowlist. It uses the standard <a href=“https://urlpattern.spec.whatwg.org/"&gt;URLPattern&lt;/a> API to match URLs. </p> <p> For any network requests made by the browser (including navigations and subresources like images or scripts), the request will fail with an error if the URL does not match any pattern in the allowlist. </p> <p> Currently only supported for CDP connections. </p> <p> Cannot be used along with BlockList. </p>

Example

Pattern to allow a specific domain: *://example.com/* Pattern to allow all subdomains: *://*.example.com/*.

View source

public string[] Args { get; set; }

Additional arguments to pass to the browser instance. List of Chromium flags can be found <a href=“http://peter.sh/experiments/chromium-command-line-switches/"&gt;here&lt;/a>.

Value: string[]

View source

public string[] BlockList { get; set; }

A list of URL patterns to block.

Value: string[]

<p> This option allows you to restrict the browser from accessing specific URLs or origins. It uses the standard <a href=“https://urlpattern.spec.whatwg.org/"&gt;URLPattern&lt;/a> API to match URLs. </p> <p> For any network requests made by the browser (including navigations and subresources like images or scripts), the request will fail with an error if the URL matches a blocked pattern. </p> <p> Currently only supported for CDP connections. </p> <p> Cannot be used along with Allowlist. </p>

Example

Pattern to block a specific domain: *://example.com/* Pattern to block all subdomains: *://*.evil.com/*.

View source

public SupportedBrowser Browser { get; set; }

The browser to be used (Chrome, Chromium, Firefox).

Value: SupportedBrowser

View source

public ChromeReleaseChannel? Channel { get; set; }

Chrome Release Channel.

Value: ChromeReleaseChannel?

View source

public ViewPortOptions DefaultViewport { get; set; }

Gets or sets the default Viewport.

Value: ViewPortOptions — The default Viewport.

View source

public bool Devtools { get; set; }

Whether to auto-open DevTools panel for each tab. If this option is true, the headless option will be set false.

Value: bool

View source

public bool DumpIO { get; set; }

Whether to pipe browser process stdout and stderr into process stdout and process stderr. Defaults to false.

Value: bool

View source

public EnableExtensionsOption EnableExtensions { get; set; }

If true, avoids passing default arguments to the browser that would prevent extensions from being enabled. Passing a list of strings will load the provided paths as unpacked extensions.

Value: EnableExtensionsOption

<p>In Chrome, setting this to true or a string[] replaces the --disable-extensions flag with --enable-unsafe-extension-debugging.</p> <p>Passing a string[] is only supported with Firefox (BiDi) at this time.</p> <p>In Firefox, there is no known command line flag to disable addons so they are always enabled.</p>

View source

public bool EnqueueAsyncMessages { get; set; }

Affects how responses to CommandOptions) are returned to the caller. If true (default), the response is delivered to the caller on its own thread; otherwise, the response is delivered the same way MessageReceived events are raised.

Value: bool

This should normally be set to true to support applications that aren’t async “all the way up”; i.e., the application has legacy code that is not async which makes calls into PuppeteerSharp. If you experience issues, or your application is not mixed sync/async use, you can set this to false (default).

View source

public bool EnqueueTransportMessages { get; set; }

If not PuppeteerSharp.Transport is set this will be use to determine is the default WebSocketTransport will enqueue messages.

Value: bool

It’s set to true by default because it’s the safest way to send commands to Chromium. Setting this to false proved to work in .NET Core, but it tends to fail on .NET Framework.

View source

public IDictionary<string, string> Env { get; }

Specify environment variables that will be visible to browser. Defaults to Environment variables.

Value: IDictionary<string, string>

View source

public string ExecutablePath { get; set; }

Path to a Chromium or Chrome executable to run instead of bundled Chromium. If executablePath is a relative path, then it is resolved relative to current working directory.

Value: string

View source

public string[] ExtensionsEnabledInIncognito { get; set; }

Gets or sets the list of extension paths that will be enabled in Incognito and off-the-record profiles.

Value: string[]

View source

public Dictionary<string, object> ExtraPrefsFirefox { get; set; }

Additional preferences that can be passed when launching with Firefox. <see fref=“https://searchfox.org/mozilla-release/source/modules/libpref/init/all.js"&gt;See&lt;/see>.

Value: Dictionary<string, object>

View source

public bool HandleDevToolsAsPage { get; set; }

Whether to handle the DevTools windows as pages in Puppeteer. Supported only in Chrome with CDP.

Value: bool

View source

[Obsolete("Use WsOptions.Headers via LaunchOptions.WsOptions instead. When both are set, WsOptions.Headers wins.")]
public Dictionary<string, string> Headers { get; set; }

Headers that should be sent with connection-related HTTP and WebSocket requests.

Value: Dictionary<string, string>

View source

public bool Headless { get; set; }

Whether to run browser in headless mode. Defaults to true unless the devtools option is true. If you need to run using the old headless mode, set HeadlessMode this to Shell.

Value: bool

View source

public HeadlessMode HeadlessMode { get; set; }

Whether to run browser in headless mode. Defaults to true unless the devtools option is true.

Value: HeadlessMode

View source

public bool IgnoreDefaultArgs { get; set; }

If true, then do not use GetDefaultArgs(LaunchOptions). Dangerous option; use with care. Defaults to false.

Value: bool

View source

public string[] IgnoredDefaultArgs { get; set; }

if IgnoreDefaultArgs is set to false this list will be used to filter GetDefaultArgs(LaunchOptions).

Value: string[]

View source

public bool IssuesEnabled { get; set; }

Experimental setting to disable monitoring issue events by default.

Value: bool

View source

[Obsolete("This property has no effect and will be removed in a future version.")]
public bool LogProcess { get; set; }

Logs process counts after launching chrome and after exiting.

Value: bool

This property is obsolete and has no effect. It will be removed in a future version.

View source

public bool NetworkEnabled { get; set; }

Experimental setting to disable monitoring network events by default. When set to false, parts of Puppeteer that depend on network events would not work such as IRequest and IResponse.

Value: bool

View source

public bool Pipe { get; set; }

Connects to the browser over a pipe instead of a WebSocket. Only supported for Chrome/Chromium with CDP protocol.

Value: bool

View source

public ProtocolType Protocol { get; set; }

The protocol to use for browser communication. Defaults to Cdp. Set to WebdriverBiDi to use WebDriver BiDi. Firefox always uses WebDriver BiDi regardless of this setting.

Value: ProtocolType

View source

public int ProtocolTimeout { get; set; }

Timeout setting for individual protocol (CDP) calls. Defaults to 180_000.

Value: int

View source

public int SlowMo { get; set; }

Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on.

Value: int

View source

public Func<Target, bool> TargetFilter { get; set; }

Callback to decide if Puppeteer should connect to a given target or not.

Value: Func<Target, bool>

View source

public int Timeout { get; set; }

Maximum time in milliseconds to wait for the browser instance to start. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

Value: int

View source

public TransportFactory TransportFactory { get; set; }

Optional factory for IConnectionTransport implementations.

Value: TransportFactory

View source

public string UserDataDir { get; set; }

Path to a User Data Directory.

Value: string

View source

public bool WaitForInitialPage { get; set; }

Wait for the initial page before initializing.

Value: bool

View source

public WebSocketFactory WebSocketFactory { get; set; }

Optional factory for WebSocket implementations. If PuppeteerSharp.Transport is set this property will be ignored.

Value: WebSocketFactory

If you need to run Puppeteer-Sharp on Windows 7, you can use WebSocketFactory to inject <a href=“https://www.nuget.org/packages/System.Net.WebSockets.Client.Managed/"&gt;System.Net.WebSockets.Client.Managed&lt;/a>.

<example>

WebSocketFactory = async (uri, socketOptions, cancellationToken) => { var client = SystemClientWebSocket.CreateClientWebSocket(); if (client is System.Net.WebSockets.Managed.ClientWebSocket managed) { managed.Options.KeepAliveInterval = TimeSpan.FromSeconds(0); await managed.ConnectAsync(uri, cancellationToken); } else { var coreSocket = client as ClientWebSocket; coreSocket.Options.KeepAliveInterval = TimeSpan.FromSeconds(0); await coreSocket.ConnectAsync(uri, cancellationToken); }

return client;

},

</example>

View source

public WsOptions WsOptions { get; set; }

Options for the WebSocket connection to the browser.

Value: WsOptions

View source

Made with love by Dario Kondratiuk