Class Browser.NewPageOptions
- Enclosing interface:
Browser
-
Field Summary
FieldsModifier and TypeFieldDescriptionWhether to automatically download all the attachments.When usingPage.navigate(),Page.route(),Page.waitForURL(),Page.waitForRequest(), orPage.waitForResponse()it takes the base URL in consideration by using theURL()constructor for building the corresponding URL.Toggles bypassing page's Content-Security-Policy.Emulates"prefers-colors-scheme"media feature, supported values are"light","dark","no-preference".Specify device scale factor (can be thought of as dpr).An object containing additional HTTP headers to be sent with every request.Emulates"forced-colors"media feature, supported values are"active","none".Specifies if viewport supports touch events.Credentials for HTTP authentication.Whether to ignore HTTPS errors when sending network requests.Whether themeta viewporttag is taken into account and touch events are enabled.Whether or not to enable JavaScript in the context.Specify user locale, for exampleen-GB,de-DE, etc.Whether to emulate network being offline.A list of permissions to grant to all pages in this context.Network proxy settings to use with this context.Optional setting to control resource content management.When set tominimal, only record information necessary for routing from HAR.Optional setting to control whether to omit request content from the HAR.Enables HAR recording for all pages into the specified HAR file on the filesystem.Enables video recording for all pages into the specified directory.Dimensions of the recorded videos.Emulates"prefers-reduced-motion"media feature, supported values are"reduce","no-preference".Emulates consistent window screen size available inside web page viawindow.screen.Whether to allow sites to register Service workers.Populates context with given storage state.Populates context with given storage state.If set to true, enables strict selectors mode for this context.Changes the timezone of the context.Specific user agent to use in this context.Emulates consistent viewport for each page. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionsetAcceptDownloads(boolean acceptDownloads) Whether to automatically download all the attachments.setBaseURL(String baseURL) When usingPage.navigate(),Page.route(),Page.waitForURL(),Page.waitForRequest(), orPage.waitForResponse()it takes the base URL in consideration by using theURL()constructor for building the corresponding URL.setBypassCSP(boolean bypassCSP) Toggles bypassing page's Content-Security-Policy.setColorScheme(ColorScheme colorScheme) Emulates"prefers-colors-scheme"media feature, supported values are"light","dark","no-preference".setDeviceScaleFactor(double deviceScaleFactor) Specify device scale factor (can be thought of as dpr).setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) An object containing additional HTTP headers to be sent with every request.setForcedColors(ForcedColors forcedColors) Emulates"forced-colors"media feature, supported values are"active","none".setGeolocation(double latitude, double longitude) setGeolocation(Geolocation geolocation) setHasTouch(boolean hasTouch) Specifies if viewport supports touch events.setHttpCredentials(HttpCredentials httpCredentials) Credentials for HTTP authentication.setHttpCredentials(String username, String password) Credentials for HTTP authentication.setIgnoreHTTPSErrors(boolean ignoreHTTPSErrors) Whether to ignore HTTPS errors when sending network requests.setIsMobile(boolean isMobile) Whether themeta viewporttag is taken into account and touch events are enabled.setJavaScriptEnabled(boolean javaScriptEnabled) Whether or not to enable JavaScript in the context.Specify user locale, for exampleen-GB,de-DE, etc.setOffline(boolean offline) Whether to emulate network being offline.setPermissions(List<String> permissions) A list of permissions to grant to all pages in this context.Network proxy settings to use with this context.Network proxy settings to use with this context.setRecordHarContent(HarContentPolicy recordHarContent) Optional setting to control resource content management.setRecordHarMode(HarMode recordHarMode) When set tominimal, only record information necessary for routing from HAR.setRecordHarOmitContent(boolean recordHarOmitContent) Optional setting to control whether to omit request content from the HAR.setRecordHarPath(Path recordHarPath) Enables HAR recording for all pages into the specified HAR file on the filesystem.setRecordHarUrlFilter(String recordHarUrlFilter) setRecordHarUrlFilter(Pattern recordHarUrlFilter) setRecordVideoDir(Path recordVideoDir) Enables video recording for all pages into the specified directory.setRecordVideoSize(int width, int height) Dimensions of the recorded videos.setRecordVideoSize(RecordVideoSize recordVideoSize) Dimensions of the recorded videos.setReducedMotion(ReducedMotion reducedMotion) Emulates"prefers-reduced-motion"media feature, supported values are"reduce","no-preference".setScreenSize(int width, int height) Emulates consistent window screen size available inside web page viawindow.screen.setScreenSize(ScreenSize screenSize) Emulates consistent window screen size available inside web page viawindow.screen.setServiceWorkers(ServiceWorkerPolicy serviceWorkers) Whether to allow sites to register Service workers.setStorageState(String storageState) Populates context with given storage state.setStorageStatePath(Path storageStatePath) Populates context with given storage state.setStrictSelectors(boolean strictSelectors) If set to true, enables strict selectors mode for this context.setTimezoneId(String timezoneId) Changes the timezone of the context.setUserAgent(String userAgent) Specific user agent to use in this context.setViewportSize(int width, int height) Emulates consistent viewport for each page.setViewportSize(ViewportSize viewportSize) Emulates consistent viewport for each page.
-
Field Details
-
acceptDownloads
Whether to automatically download all the attachments. Defaults totruewhere all the downloads are accepted. -
baseURL
When usingPage.navigate(),Page.route(),Page.waitForURL(),Page.waitForRequest(), orPage.waitForResponse()it takes the base URL in consideration by using theURL()constructor for building the corresponding URL. Unset by default. Examples:- baseURL:
http://localhost:3000and navigating to/bar.htmlresults inhttp://localhost:3000/bar.html - baseURL:
http://localhost:3000/foo/and navigating to./bar.htmlresults inhttp://localhost:3000/foo/bar.html - baseURL:
http://localhost:3000/foo(without trailing slash) and navigating to./bar.htmlresults inhttp://localhost:3000/bar.html
- baseURL:
-
bypassCSP
Toggles bypassing page's Content-Security-Policy. Defaults tofalse. -
colorScheme
Emulates"prefers-colors-scheme"media feature, supported values are"light","dark","no-preference". SeePage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to"light". -
deviceScaleFactor
Specify device scale factor (can be thought of as dpr). Defaults to1. Learn more about emulating devices with device scale factor. -
extraHTTPHeaders
An object containing additional HTTP headers to be sent with every request. Defaults to none. -
forcedColors
Emulates"forced-colors"media feature, supported values are"active","none". SeePage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to"none". -
geolocation
-
hasTouch
Specifies if viewport supports touch events. Defaults to false. Learn more about mobile emulation. -
httpCredentials
Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses. -
ignoreHTTPSErrors
Whether to ignore HTTPS errors when sending network requests. Defaults tofalse. -
isMobile
Whether themeta viewporttag 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 tofalseand is not supported in Firefox. Learn more about mobile emulation. -
javaScriptEnabled
Whether or not to enable JavaScript in the context. Defaults totrue. Learn more about disabling JavaScript. -
locale
Specify user locale, for exampleen-GB,de-DE, etc. Locale will affectnavigator.languagevalue,Accept-Languagerequest header value as well as number and date formatting rules. Defaults to the system default locale. Learn more about emulation in our emulation guide. -
offline
Whether to emulate network being offline. Defaults tofalse. Learn more about network emulation. -
permissions
A list of permissions to grant to all pages in this context. SeeBrowserContext.grantPermissions()for more details. Defaults to none. -
proxy
Network proxy settings to use with this context. Defaults to none.NOTE: 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. Ifomitis specified, content is not persisted. Ifattachis specified, resources are persisted as separate files and all of these files are archived along with the HAR file. Defaults toembed, which stores content inline the HAR file as per HAR specification. -
recordHarMode
When set tominimal, 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 tofull. -
recordHarOmitContent
Optional setting to control whether to omit request content from the HAR. Defaults tofalse. -
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 callBrowserContext.close()for the HAR to be saved. -
recordHarUrlFilter
-
recordVideoDir
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure to callBrowserContext.close()for videos to be saved. -
recordVideoSize
Dimensions of the recorded videos. If not specified the size will be equal toviewportscaled down to fit into 800x800. Ifviewportis 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. -
reducedMotion
Emulates"prefers-reduced-motion"media feature, supported values are"reduce","no-preference". SeePage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to"no-preference". -
screenSize
Emulates consistent window screen size available inside web page viawindow.screen. Is only used when theviewportis set. -
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.
-
-
storageState
Populates context with given storage state. This option can be used to initialize context with logged-in information obtained viaBrowserContext.storageState(). -
storageStatePath
Populates context with given storage state. This option can be used to initialize context with logged-in information obtained viaBrowserContext.storageState(). Path to the file with saved storage state. -
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 tofalse. SeeLocatorto learn more about the strict mode. -
timezoneId
Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs. Defaults to the system timezone. -
userAgent
Specific user agent to use in this context. -
viewportSize
Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Usenullto disable the consistent viewport emulation. Learn more about viewport emulation.NOTE: The
nullvalue 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.
-
-
Constructor Details
-
NewPageOptions
public NewPageOptions()
-
-
Method Details
-
setAcceptDownloads
Whether to automatically download all the attachments. Defaults totruewhere all the downloads are accepted. -
setBaseURL
When usingPage.navigate(),Page.route(),Page.waitForURL(),Page.waitForRequest(), orPage.waitForResponse()it takes the base URL in consideration by using theURL()constructor for building the corresponding URL. Unset by default. Examples:- baseURL:
http://localhost:3000and navigating to/bar.htmlresults inhttp://localhost:3000/bar.html - baseURL:
http://localhost:3000/foo/and navigating to./bar.htmlresults inhttp://localhost:3000/foo/bar.html - baseURL:
http://localhost:3000/foo(without trailing slash) and navigating to./bar.htmlresults inhttp://localhost:3000/bar.html
- baseURL:
-
setBypassCSP
Toggles bypassing page's Content-Security-Policy. Defaults tofalse. -
setColorScheme
Emulates"prefers-colors-scheme"media feature, supported values are"light","dark","no-preference". SeePage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to"light". -
setDeviceScaleFactor
Specify device scale factor (can be thought of as dpr). Defaults to1. Learn more about emulating devices with device scale factor. -
setExtraHTTPHeaders
An object containing additional HTTP headers to be sent with every request. Defaults to none. -
setForcedColors
Emulates"forced-colors"media feature, supported values are"active","none". SeePage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to"none". -
setGeolocation
-
setGeolocation
-
setHasTouch
Specifies if viewport supports touch events. Defaults to false. Learn more about mobile emulation. -
setHttpCredentials
Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses. -
setHttpCredentials
Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses. -
setIgnoreHTTPSErrors
Whether to ignore HTTPS errors when sending network requests. Defaults tofalse. -
setIsMobile
Whether themeta viewporttag 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 tofalseand is not supported in Firefox. Learn more about mobile emulation. -
setJavaScriptEnabled
Whether or not to enable JavaScript in the context. Defaults totrue. Learn more about disabling JavaScript. -
setLocale
Specify user locale, for exampleen-GB,de-DE, etc. Locale will affectnavigator.languagevalue,Accept-Languagerequest header value as well as number and date formatting rules. Defaults to the system default locale. Learn more about emulation in our emulation guide. -
setOffline
Whether to emulate network being offline. Defaults tofalse. Learn more about network emulation. -
setPermissions
A list of permissions to grant to all pages in this context. SeeBrowserContext.grantPermissions()for more details. Defaults to none. -
setProxy
Network proxy settings to use with this context. Defaults to none.NOTE: 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' } }). -
setProxy
Network proxy settings to use with this context. Defaults to none.NOTE: 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' } }). -
setRecordHarContent
Optional setting to control resource content management. Ifomitis specified, content is not persisted. Ifattachis specified, resources are persisted as separate files and all of these files are archived along with the HAR file. Defaults toembed, which stores content inline the HAR file as per HAR specification. -
setRecordHarMode
When set tominimal, 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 tofull. -
setRecordHarOmitContent
Optional setting to control whether to omit request content from the HAR. Defaults tofalse. -
setRecordHarPath
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 callBrowserContext.close()for the HAR to be saved. -
setRecordHarUrlFilter
-
setRecordHarUrlFilter
-
setRecordVideoDir
Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure to callBrowserContext.close()for videos to be saved. -
setRecordVideoSize
Dimensions of the recorded videos. If not specified the size will be equal toviewportscaled down to fit into 800x800. Ifviewportis 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. -
setRecordVideoSize
Dimensions of the recorded videos. If not specified the size will be equal toviewportscaled down to fit into 800x800. Ifviewportis 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. -
setReducedMotion
Emulates"prefers-reduced-motion"media feature, supported values are"reduce","no-preference". SeePage.emulateMedia()for more details. Passingnullresets emulation to system defaults. Defaults to"no-preference". -
setScreenSize
Emulates consistent window screen size available inside web page viawindow.screen. Is only used when theviewportis set. -
setScreenSize
Emulates consistent window screen size available inside web page viawindow.screen. Is only used when theviewportis set. -
setServiceWorkers
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.
-
-
setStorageState
Populates context with given storage state. This option can be used to initialize context with logged-in information obtained viaBrowserContext.storageState(). -
setStorageStatePath
Populates context with given storage state. This option can be used to initialize context with logged-in information obtained viaBrowserContext.storageState(). Path to the file with saved storage state. -
setStrictSelectors
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 tofalse. SeeLocatorto learn more about the strict mode. -
setTimezoneId
Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs. Defaults to the system timezone. -
setUserAgent
Specific user agent to use in this context. -
setViewportSize
Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Usenullto disable the consistent viewport emulation. Learn more about viewport emulation.NOTE: The
nullvalue 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. -
setViewportSize
Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Usenullto disable the consistent viewport emulation. Learn more about viewport emulation.NOTE: The
nullvalue 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.
-