Class BrowserNewContextOptions
- Namespace
- Microsoft.Playwright
- Assembly
- Microsoft.Playwright.dll
public class BrowserNewContextOptions
- Inheritance
-
BrowserNewContextOptions
- Inherited Members
Constructors
BrowserNewContextOptions()
public BrowserNewContextOptions()
BrowserNewContextOptions(BrowserNewContextOptions)
public BrowserNewContextOptions(BrowserNewContextOptions clone)
Parameters
clone
BrowserNewContextOptions
Properties
AcceptDownloads
Whether to automatically download all the attachments. Defaults to true
where
all the downloads are accepted.
[JsonPropertyName("acceptDownloads")]
public bool? AcceptDownloads { get; set; }
Property Value
- bool?
BaseURL
When using GotoAsync(string, PageGotoOptions?), RouteAsync(string, Action<IRoute>, PageRouteOptions?), WaitForURLAsync(string, PageWaitForURLOptions?),
RunAndWaitForRequestAsync(Func<Task>, string, PageRunAndWaitForRequestOptions?), or RunAndWaitForResponseAsync(Func<Task>, string, PageRunAndWaitForResponseOptions?)
it takes the base URL in consideration by using the URL()
constructor for building the corresponding URL. Unset by default. Examples:
-
baseURL:
http://localhost:3000
and navigating to/bar.html
results inhttp://localhost:3000/bar.html
-
baseURL:
http://localhost:3000/foo/
and navigating to./bar.html
results inhttp://localhost:3000/foo/bar.html
-
baseURL:
http://localhost:3000/foo
(without trailing slash) and navigating to./bar.html
results inhttp://localhost:3000/bar.html
[JsonPropertyName("baseURL")]
public string? BaseURL { get; set; }
Property Value
BypassCSP
Toggles bypassing page's Content-Security-Policy. Defaults to false
.
[JsonPropertyName("bypassCSP")]
public bool? BypassCSP { get; set; }
Property Value
- bool?
ColorScheme
Emulates 'prefers-colors-scheme'
media feature, supported values are 'light'
,
'dark'
, 'no-preference'
. See EmulateMediaAsync(PageEmulateMediaOptions?)
for more details. Passing 'null'
resets emulation to system defaults. Defaults
to 'light'
.
[JsonPropertyName("colorScheme")]
public ColorScheme? ColorScheme { get; set; }
Property Value
DeviceScaleFactor
Specify device scale factor (can be thought of as dpr). Defaults to 1
. Learn
more about emulating
devices with device scale factor.
[JsonPropertyName("deviceScaleFactor")]
public float? DeviceScaleFactor { get; set; }
Property Value
ExtraHTTPHeaders
An object containing additional HTTP headers to be sent with every request. Defaults to none.
[JsonPropertyName("extraHTTPHeaders")]
public IEnumerable<KeyValuePair<string, string>>? ExtraHTTPHeaders { get; set; }
Property Value
ForcedColors
Emulates 'forced-colors'
media feature, supported values are 'active'
,
'none'
. See EmulateMediaAsync(PageEmulateMediaOptions?) for more details. Passing
'null'
resets emulation to system defaults. Defaults to 'none'
.
[JsonPropertyName("forcedColors")]
public ForcedColors? ForcedColors { get; set; }
Property Value
Geolocation
[JsonPropertyName("geolocation")]
public Geolocation? Geolocation { get; set; }
Property Value
HasTouch
Specifies if viewport supports touch events. Defaults to false. Learn more about mobile emulation.
[JsonPropertyName("hasTouch")]
public bool? HasTouch { get; set; }
Property Value
- bool?
HttpCredentials
Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.
[JsonPropertyName("httpCredentials")]
public HttpCredentials? HttpCredentials { get; set; }
Property Value
IgnoreHTTPSErrors
Whether to ignore HTTPS errors when sending network requests. Defaults to false
.
[JsonPropertyName("ignoreHTTPSErrors")]
public bool? IgnoreHTTPSErrors { get; set; }
Property Value
- bool?
IsMobile
Whether the meta viewport
tag is taken into account and touch events are
enabled. isMobile is a part of device, so you don't actually need to set it manually.
Defaults to false
and is not supported in Firefox. Learn more about mobile
emulation.
[JsonPropertyName("isMobile")]
public bool? IsMobile { get; set; }
Property Value
- bool?
JavaScriptEnabled
Whether or not to enable JavaScript in the context. Defaults to true
. Learn
more about disabling
JavaScript.
[JsonPropertyName("javaScriptEnabled")]
public bool? JavaScriptEnabled { get; set; }
Property Value
- bool?
Locale
Specify user locale, for example en-GB
, de-DE
, etc. Locale will affect
navigator.language
value, Accept-Language
request header value as
well as number and date formatting rules. Defaults to the system default locale.
Learn more about emulation in our emulation
guide.
[JsonPropertyName("locale")]
public string? Locale { get; set; }
Property Value
Offline
Whether to emulate network being offline. Defaults to false
. Learn more about
network emulation.
[JsonPropertyName("offline")]
public bool? Offline { get; set; }
Property Value
- bool?
Permissions
A list of permissions to grant to all pages in this context. See GrantPermissionsAsync(IEnumerable<string>, BrowserContextGrantPermissionsOptions?) for more details. Defaults to none.
[JsonPropertyName("permissions")]
public IEnumerable<string>? Permissions { get; set; }
Property Value
Proxy
Network proxy settings to use with this context. Defaults to none.
[JsonPropertyName("proxy")]
public Proxy? Proxy { get; set; }
Property Value
Remarks
For Chromium on Windows the browser needs to be launched with the global proxy for
this option to work. If all contexts override the proxy, global proxy will be never
used and can be any string, for example launch({ proxy: { server: 'http://per-context'
} })
.
RecordHarContent
Optional setting to control resource content management. If omit
is specified,
content is not persisted. If attach
is specified, resources are persisted
as separate files and all of these files are archived along with the HAR file. Defaults
to embed
, which stores content inline the HAR file as per HAR specification.
[JsonPropertyName("recordHarContent")]
public HarContentPolicy? RecordHarContent { get; set; }
Property Value
RecordHarMode
When set to minimal
, only record information necessary for routing from HAR.
This omits sizes, timing, page, cookies, security and other types of HAR information
that are not used when replaying from HAR. Defaults to full
.
[JsonPropertyName("recordHarMode")]
public HarMode? RecordHarMode { get; set; }
Property Value
RecordHarOmitContent
Optional setting to control whether to omit request content from the HAR. Defaults
to false
.
[JsonPropertyName("recordHarOmitContent")]
public bool? RecordHarOmitContent { get; set; }
Property Value
- bool?
RecordHarPath
Enables HAR recording for all pages into the specified HAR file on the filesystem. If not specified, the HAR is not recorded. Make sure to call CloseAsync(BrowserContextCloseOptions?) for the HAR to be saved.
[JsonPropertyName("recordHarPath")]
public string? RecordHarPath { get; set; }
Property Value
RecordHarUrlFilter
[JsonPropertyName("recordHarUrlFilter")]
public string? RecordHarUrlFilter { get; set; }
Property Value
RecordHarUrlFilterRegex
[JsonPropertyName("recordHarUrlFilterRegex")]
public Regex? RecordHarUrlFilterRegex { get; set; }
Property Value
RecordHarUrlFilterString
[JsonPropertyName("recordHarUrlFilterString")]
public string? RecordHarUrlFilterString { get; set; }
Property Value
RecordVideoDir
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure to call CloseAsync(BrowserContextCloseOptions?) for videos to be saved.
[JsonPropertyName("recordVideoDir")]
public string? RecordVideoDir { get; set; }
Property Value
RecordVideoSize
Dimensions of the recorded videos. If not specified the size will be equal to viewport
scaled down to fit into 800x800. If viewport
is not configured explicitly
the video size defaults to 800x450. Actual picture of each page will be scaled down
if necessary to fit the specified size.
[JsonPropertyName("recordVideoSize")]
public RecordVideoSize? RecordVideoSize { get; set; }
Property Value
ReducedMotion
Emulates 'prefers-reduced-motion'
media feature, supported values are 'reduce'
,
'no-preference'
. See EmulateMediaAsync(PageEmulateMediaOptions?) for more details.
Passing 'null'
resets emulation to system defaults. Defaults to 'no-preference'
.
[JsonPropertyName("reducedMotion")]
public ReducedMotion? ReducedMotion { get; set; }
Property Value
ScreenSize
Emulates consistent window screen size available inside web page via window.screen
.
Is only used when the viewport
is set.
[JsonPropertyName("screen")]
public ScreenSize? ScreenSize { get; set; }
Property Value
ServiceWorkers
Whether to allow sites to register Service workers. Defaults to 'allow'
.
-
'allow'
: Service Workers can be registered. 'block'
: Playwright will block all registration of Service Workers.
[JsonPropertyName("serviceWorkers")]
public ServiceWorkerPolicy? ServiceWorkers { get; set; }
Property Value
StorageState
Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via StorageStateAsync(BrowserContextStorageStateOptions?).
[JsonPropertyName("storageState")]
public string? StorageState { get; set; }
Property Value
StorageStatePath
Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via StorageStateAsync(BrowserContextStorageStateOptions?). Path to the file with saved storage state.
[JsonPropertyName("storageStatePath")]
public string? StorageStatePath { get; set; }
Property Value
StrictSelectors
If set to true, enables strict selectors mode for this context. In the strict selectors
mode all operations on selectors that imply single target DOM element will throw
when more than one element matches the selector. This option does not affect any
Locator APIs (Locators are always strict). Defaults to false
. See ILocator
to learn more about the strict mode.
[JsonPropertyName("strictSelectors")]
public bool? StrictSelectors { get; set; }
Property Value
- bool?
TimezoneId
Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs. Defaults to the system timezone.
[JsonPropertyName("timezoneId")]
public string? TimezoneId { get; set; }
Property Value
UserAgent
Specific user agent to use in this context.
[JsonPropertyName("userAgent")]
public string? UserAgent { get; set; }
Property Value
ViewportSize
Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use
ViewportSize.NoViewport
to disable the consistent viewport emulation. Learn
more about viewport
emulation.
[JsonPropertyName("viewport")]
public ViewportSize? ViewportSize { get; set; }
Property Value
Remarks
The ViewportSize.NoViewport
value opts out from the default presets, makes
viewport depend on the host window size defined by the operating system. It makes
the execution of the tests non-deterministic.