Class Browser.NewPageOptions

  • Enclosing interface:
    Browser

    public static class Browser.NewPageOptions
    extends Object
    • Field Detail

      • acceptDownloads

        public Boolean acceptDownloads
        Whether to automatically download all the attachments. Defaults to true where all the downloads are accepted.
      • baseURL

        public String baseURL
        When using Page.navigate(), Page.route(), Page.waitForURL(), Page.waitForRequest(), or Page.waitForResponse() 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 in http://localhost:3000/bar.html
        • baseURL: http://localhost:3000/foo/ and navigating to ./bar.html results in http://localhost:3000/foo/bar.html
        • baseURL: http://localhost:3000/foo (without trailing slash) and navigating to ./bar.html results in http://localhost:3000/bar.html
      • bypassCSP

        public Boolean bypassCSP
        Toggles bypassing page's Content-Security-Policy. Defaults to false.
      • clientCertificates

        public List<ClientCertificate> clientCertificates
        TLS Client Authentication allows the server to request a client certificate and verify it.

        Details

        An array of client certificates to be used. Each certificate object must have either both certPath and keyPath, a single pfxPath, or their corresponding direct value equivalents (cert and key, or pfx). Optionally, passphrase property should be provided if the certificate is encrypted. The origin property should be provided with an exact match to the request origin that the certificate is valid for.

        NOTE: When using WebKit on macOS, accessing localhost will not pick up client certificates. You can make it work by replacing localhost with local.playwright.

      • contrast

        public Optional<Contrast> contrast
        Emulates "prefers-contrast" media feature, supported values are "no-preference", "more". See Page.emulateMedia() for more details. Passing null resets emulation to system defaults. Defaults to "no-preference".
      • extraHTTPHeaders

        public Map<String,​String> extraHTTPHeaders
        An object containing additional HTTP headers to be sent with every request. Defaults to none.
      • forcedColors

        public Optional<ForcedColors> forcedColors
        Emulates "forced-colors" media feature, supported values are "active", "none". See Page.emulateMedia() for more details. Passing null resets emulation to system defaults. Defaults to "none".
      • hasTouch

        public Boolean hasTouch
        Specifies if viewport supports touch events. Defaults to false. Learn more about mobile emulation.
      • httpCredentials

        public HttpCredentials httpCredentials
        Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.
      • ignoreHTTPSErrors

        public Boolean ignoreHTTPSErrors
        Whether to ignore HTTPS errors when sending network requests. Defaults to false.
      • isMobile

        public Boolean 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.
      • javaScriptEnabled

        public Boolean javaScriptEnabled
        Whether or not to enable JavaScript in the context. Defaults to true. Learn more about disabling JavaScript.
      • locale

        public String 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.
      • offline

        public Boolean offline
        Whether to emulate network being offline. Defaults to false. Learn more about network emulation.
      • proxy

        public Proxy proxy
        Network proxy settings to use with this context. Defaults to none.
      • recordHarContent

        public HarContentPolicy 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.
      • recordHarMode

        public HarMode 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.
      • recordHarOmitContent

        public Boolean recordHarOmitContent
        Optional setting to control whether to omit request content from the HAR. Defaults to false.
      • recordHarPath

        public Path 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 BrowserContext.close() for the HAR to be saved.
      • recordHarUrlFilter

        public Object recordHarUrlFilter
      • recordVideoDir

        public Path recordVideoDir
        Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure to call BrowserContext.close() for videos to be saved.
      • recordVideoSize

        public RecordVideoSize 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.
      • reducedMotion

        public Optional<ReducedMotion> reducedMotion
        Emulates "prefers-reduced-motion" media feature, supported values are "reduce", "no-preference". See Page.emulateMedia() for more details. Passing null resets emulation to system defaults. Defaults to "no-preference".
      • screenSize

        public ScreenSize screenSize
        Emulates consistent window screen size available inside web page via window.screen. Is only used when the viewport is set.
      • serviceWorkers

        public ServiceWorkerPolicy 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

        public String storageState
        Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via BrowserContext.storageState().
      • storageStatePath

        public Path storageStatePath
        Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via BrowserContext.storageState(). Path to the file with saved storage state.
      • strictSelectors

        public Boolean 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 Locator to learn more about the strict mode.
      • timezoneId

        public String 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

        public String userAgent
        Specific user agent to use in this context.
      • viewportSize

        public Optional<ViewportSize> viewportSize
        Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use null to disable the consistent viewport emulation. Learn more about viewport emulation.

        NOTE: The null 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.

    • Constructor Detail

      • NewPageOptions

        public NewPageOptions()
    • Method Detail

      • setAcceptDownloads

        public Browser.NewPageOptions setAcceptDownloads​(boolean acceptDownloads)
        Whether to automatically download all the attachments. Defaults to true where all the downloads are accepted.
      • setBaseURL

        public Browser.NewPageOptions setBaseURL​(String baseURL)
        When using Page.navigate(), Page.route(), Page.waitForURL(), Page.waitForRequest(), or Page.waitForResponse() 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 in http://localhost:3000/bar.html
        • baseURL: http://localhost:3000/foo/ and navigating to ./bar.html results in http://localhost:3000/foo/bar.html
        • baseURL: http://localhost:3000/foo (without trailing slash) and navigating to ./bar.html results in http://localhost:3000/bar.html
      • setBypassCSP

        public Browser.NewPageOptions setBypassCSP​(boolean bypassCSP)
        Toggles bypassing page's Content-Security-Policy. Defaults to false.
      • setClientCertificates

        public Browser.NewPageOptions setClientCertificates​(List<ClientCertificate> clientCertificates)
        TLS Client Authentication allows the server to request a client certificate and verify it.

        Details

        An array of client certificates to be used. Each certificate object must have either both certPath and keyPath, a single pfxPath, or their corresponding direct value equivalents (cert and key, or pfx). Optionally, passphrase property should be provided if the certificate is encrypted. The origin property should be provided with an exact match to the request origin that the certificate is valid for.

        NOTE: When using WebKit on macOS, accessing localhost will not pick up client certificates. You can make it work by replacing localhost with local.playwright.

      • setContrast

        public Browser.NewPageOptions setContrast​(Contrast contrast)
        Emulates "prefers-contrast" media feature, supported values are "no-preference", "more". See Page.emulateMedia() for more details. Passing null resets emulation to system defaults. Defaults to "no-preference".
      • setExtraHTTPHeaders

        public Browser.NewPageOptions setExtraHTTPHeaders​(Map<String,​String> extraHTTPHeaders)
        An object containing additional HTTP headers to be sent with every request. Defaults to none.
      • setForcedColors

        public Browser.NewPageOptions setForcedColors​(ForcedColors forcedColors)
        Emulates "forced-colors" media feature, supported values are "active", "none". See Page.emulateMedia() for more details. Passing null resets emulation to system defaults. Defaults to "none".
      • setIgnoreHTTPSErrors

        public Browser.NewPageOptions setIgnoreHTTPSErrors​(boolean ignoreHTTPSErrors)
        Whether to ignore HTTPS errors when sending network requests. Defaults to false.
      • setIsMobile

        public Browser.NewPageOptions setIsMobile​(boolean 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.
      • setJavaScriptEnabled

        public Browser.NewPageOptions setJavaScriptEnabled​(boolean javaScriptEnabled)
        Whether or not to enable JavaScript in the context. Defaults to true. Learn more about disabling JavaScript.
      • setLocale

        public Browser.NewPageOptions setLocale​(String 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.
      • setProxy

        public Browser.NewPageOptions setProxy​(Proxy proxy)
        Network proxy settings to use with this context. Defaults to none.
      • setRecordHarContent

        public Browser.NewPageOptions setRecordHarContent​(HarContentPolicy 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.
      • setRecordHarMode

        public Browser.NewPageOptions setRecordHarMode​(HarMode 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.
      • setRecordHarOmitContent

        public Browser.NewPageOptions setRecordHarOmitContent​(boolean recordHarOmitContent)
        Optional setting to control whether to omit request content from the HAR. Defaults to false.
      • setRecordHarPath

        public Browser.NewPageOptions setRecordHarPath​(Path 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 BrowserContext.close() for the HAR to be saved.
      • setRecordVideoDir

        public Browser.NewPageOptions setRecordVideoDir​(Path recordVideoDir)
        Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure to call BrowserContext.close() for videos to be saved.
      • setRecordVideoSize

        public Browser.NewPageOptions setRecordVideoSize​(int width,
                                                         int height)
        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.
      • setRecordVideoSize

        public Browser.NewPageOptions setRecordVideoSize​(RecordVideoSize 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.
      • setReducedMotion

        public Browser.NewPageOptions setReducedMotion​(ReducedMotion reducedMotion)
        Emulates "prefers-reduced-motion" media feature, supported values are "reduce", "no-preference". See Page.emulateMedia() for more details. Passing null resets emulation to system defaults. Defaults to "no-preference".
      • setScreenSize

        public Browser.NewPageOptions setScreenSize​(int width,
                                                    int height)
        Emulates consistent window screen size available inside web page via window.screen. Is only used when the viewport is set.
      • setScreenSize

        public Browser.NewPageOptions setScreenSize​(ScreenSize screenSize)
        Emulates consistent window screen size available inside web page via window.screen. Is only used when the viewport is set.
      • setServiceWorkers

        public Browser.NewPageOptions setServiceWorkers​(ServiceWorkerPolicy 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.
      • setStorageStatePath

        public Browser.NewPageOptions setStorageStatePath​(Path storageStatePath)
        Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via BrowserContext.storageState(). Path to the file with saved storage state.
      • setStrictSelectors

        public Browser.NewPageOptions setStrictSelectors​(boolean 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 Locator to learn more about the strict mode.
      • setViewportSize

        public Browser.NewPageOptions setViewportSize​(int width,
                                                      int height)
        Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use null to disable the consistent viewport emulation. Learn more about viewport emulation.

        NOTE: The null 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.

      • setViewportSize

        public Browser.NewPageOptions setViewportSize​(ViewportSize viewportSize)
        Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use null to disable the consistent viewport emulation. Learn more about viewport emulation.

        NOTE: The null 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.