Class PlaywrightFetcherConfig
java.lang.Object
com.norconex.crawler.core.fetch.BaseFetcherConfig
com.norconex.crawler.web.fetch.impl.playwright.PlaywrightFetcherConfig
Configuration for PlaywrightFetcher.
By default Playwright uses its own downloaded browser binaries
(~/.cache/ms-playwright). To use a system-installed browser instead
(e.g., Chrome, Edge, Firefox already present on the machine or CI runner),
set the channel field (e.g., "chrome",
"msedge", "firefox") — no download is then required.
No external WebDriver binary is ever needed.
- Since:
- 4.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe preferred color scheme pages are told about (theprefers-color-schememedia query).static enumElement locator strategy forgetWaitForElementSelector(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleangetArgs()Returns an unmodifiable view of the browser launch arguments.The browser engine used for crawling.Maximum age of a per-thread browser instance before it is restarted.intA maximum number of navigations after which each per-thread browser instance is restarted.Optional browser channel that instructs Playwright to use a system-installed browser instead of its own downloaded binaries.@NonNull DurationInterval between checks for idle (unused) browser instances to close.The preferred color scheme.Optional JavaScript code executed immediately after page navigation, before any wait conditions are applied.Optional path to a custom browser executable.Returns an unmodifiable view of the extra HTTP headers.Gets the credentials for HTTP authentication challenges.Optional JavaScript code executed after all wait conditions have been satisfied.The locale the browser reports (e.g.,fr-CA).Maximum time to wait for the page load event.Proxy settings used when launching the browser.When configured, takes a screenshot of each fetched page and stores it according to the handler's configuration (document metadata field or local directory).Optional slow-motion delay applied between Playwright operations.A file Playwright wrote of a signed-in session (cookies and local storage, as saved bycontext.storageState()).The timezone the browser reports (an IANA name, e.g.,America/Toronto).The user agent the browser sends, in place of its own.Selector expression used to wait for a specific element to appear in the page before returning.Maximum time to wait for the element identified bygetWaitForElementSelector()to appear.The type of reference used when waiting for an element to appear.Optional browser viewport size.inthashCode()booleanWhether to keep service workers from registering.booleanWhether to ignore the page's Content-Security-Policy, so scripts added bygetEarlyPageScript()orgetLatePageScript()are not blocked by it.booleanWhether to run the browser in headless mode.booleanWhentrue, HTTPS certificate errors are ignored.booleanWhether the browser runs the page's JavaScript.booleanisMobile()Whether to behave as a mobile device: the page is told it is mobile and the screen is touch-enabled.Sets the browser launch arguments.setBlockServiceWorkers(boolean blockServiceWorkers) Whether to keep service workers from registering.setBrowser(PlaywrightBrowser browser) The browser engine used for crawling.setBrowserMaxAge(Duration browserMaxAge) Maximum age of a per-thread browser instance before it is restarted.setBrowserMaxNavigations(int browserMaxNavigations) A maximum number of navigations after which each per-thread browser instance is restarted.setBypassCsp(boolean bypassCsp) Whether to ignore the page's Content-Security-Policy, so scripts added bygetEarlyPageScript()orgetLatePageScript()are not blocked by it.setChannel(String channel) Optional browser channel that instructs Playwright to use a system-installed browser instead of its own downloaded binaries.setCleanupInterval(@NonNull Duration cleanupInterval) Interval between checks for idle (unused) browser instances to close.setColorScheme(PlaywrightFetcherConfig.ColorScheme colorScheme) The preferred color scheme.setEarlyPageScript(String earlyPageScript) Optional JavaScript code executed immediately after page navigation, before any wait conditions are applied.setExecutablePath(Path executablePath) Optional path to a custom browser executable.setExtraHttpHeaders(Map<String, String> headers) Sets the extra HTTP headers sent with every request.setHeadless(boolean headless) Whether to run the browser in headless mode.setHttpCredentials(Credentials credentials) Sets the credentials for HTTP authentication challenges.setIgnoreHttpsErrors(boolean ignoreHttpsErrors) Whentrue, HTTPS certificate errors are ignored.setJavaScriptEnabled(boolean javaScriptEnabled) Whether the browser runs the page's JavaScript.setLatePageScript(String latePageScript) Optional JavaScript code executed after all wait conditions have been satisfied.The locale the browser reports (e.g.,fr-CA).setMobile(boolean mobile) Whether to behave as a mobile device: the page is told it is mobile and the screen is touch-enabled.setPageLoadTimeout(Duration pageLoadTimeout) Maximum time to wait for the page load event.setProxySettings(ProxySettings proxySettings) Proxy settings used when launching the browser.setScreenshotHandler(PlaywrightScreenshotHandler screenshotHandler) When configured, takes a screenshot of each fetched page and stores it according to the handler's configuration (document metadata field or local directory).Optional slow-motion delay applied between Playwright operations.setStorageStatePath(Path storageStatePath) A file Playwright wrote of a signed-in session (cookies and local storage, as saved bycontext.storageState()).setTimezoneId(String timezoneId) The timezone the browser reports (an IANA name, e.g.,America/Toronto).setUserAgent(String userAgent) The user agent the browser sends, in place of its own.setWaitForElementSelector(String waitForElementSelector) Selector expression used to wait for a specific element to appear in the page before returning.setWaitForElementTimeout(Duration waitForElementTimeout) Maximum time to wait for the element identified bygetWaitForElementSelector()to appear.setWaitForElementType(PlaywrightFetcherConfig.WaitElementType waitForElementType) The type of reference used when waiting for an element to appear.setWindowSize(Dimension windowSize) Optional browser viewport size.toString()Methods inherited from class com.norconex.crawler.core.fetch.BaseFetcherConfig
getReferenceFilters, setReferenceFilters
-
Constructor Details
-
PlaywrightFetcherConfig
public PlaywrightFetcherConfig()
-
-
Method Details
-
getHttpCredentials
Gets the credentials for HTTP authentication challenges.- Returns:
- credentials
-
setHttpCredentials
Sets the credentials for HTTP authentication challenges.- Parameters:
credentials- the credentials- Returns:
- this config
-
getExtraHttpHeaders
Returns an unmodifiable view of the extra HTTP headers.- Returns:
- headers by name
-
setExtraHttpHeaders
Sets the extra HTTP headers sent with every request.- Parameters:
headers- header names and values- Returns:
- this config
-
getArgs
Returns an unmodifiable view of the browser launch arguments. UsesetArgs(List)to replace the list.- Returns:
- unmodifiable list of launch arguments
-
setArgs
Sets the browser launch arguments.- Parameters:
args- launch arguments- Returns:
- this config
-
getBrowser
The browser engine used for crawling. Default isPlaywrightBrowser.CHROMIUM. -
isHeadless
public boolean isHeadless()Whether to run the browser in headless mode. Default istrue. -
getChannel
Optional browser channel that instructs Playwright to use a system-installed browser instead of its own downloaded binaries. Supported values:"chrome","msedge","firefox". Leave blank (the default) to use Playwright's bundled browser binaries. -
getExecutablePath
Optional path to a custom browser executable. Whennull, Playwright uses the bundled browser binary it downloaded. -
isIgnoreHttpsErrors
public boolean isIgnoreHttpsErrors()Whentrue, HTTPS certificate errors are ignored. Default isfalse. -
getUserAgent
The user agent the browser sends, in place of its own. It is set on the browser context, so both the requests and the page's ownnavigator.userAgentcarry it. Default isnull(the browser's own). -
getLocale
The locale the browser reports (e.g.,fr-CA). It sets theAccept-Languageheader and the page'snavigator.language. Default isnull(the browser's own). -
getTimezoneId
The timezone the browser reports (an IANA name, e.g.,America/Toronto). Default isnull(the system's). -
isJavaScriptEnabled
public boolean isJavaScriptEnabled()Whether the browser runs the page's JavaScript. Turn off to read pages as they are served, without any script changing them. Default istrue. -
isBypassCsp
public boolean isBypassCsp()Whether to ignore the page's Content-Security-Policy, so scripts added bygetEarlyPageScript()orgetLatePageScript()are not blocked by it. Default isfalse. -
isBlockServiceWorkers
public boolean isBlockServiceWorkers()Whether to keep service workers from registering. A service worker can answer requests itself, so what is read may not be what the site serves. Default isfalse. -
isMobile
public boolean isMobile()Whether to behave as a mobile device: the page is told it is mobile and the screen is touch-enabled. Combine with a mobile user agent and a small window size. Default isfalse. -
getColorScheme
The preferred color scheme. Default isnull. -
getStorageStatePath
A file Playwright wrote of a signed-in session (cookies and local storage, as saved bycontext.storageState()). The browser starts with that session. Default isnull. -
getSlowMo
Optional slow-motion delay applied between Playwright operations. Useful for debugging. Default isnull(no delay). -
getPageLoadTimeout
Maximum time to wait for the page load event. Whennull, the Playwright default (30 s) applies. -
getEarlyPageScript
Optional JavaScript code executed immediately after page navigation, before any wait conditions are applied. -
getLatePageScript
Optional JavaScript code executed after all wait conditions have been satisfied. -
getWaitForElementType
The type of reference used when waiting for an element to appear. Used together withgetWaitForElementSelector(). Default isPlaywrightFetcherConfig.WaitElementType.CSSSELECTOR. -
getWaitForElementSelector
Selector expression used to wait for a specific element to appear in the page before returning. The kind of expression is defined bygetWaitForElementType(). Whennull, no element wait is performed. -
getWaitForElementTimeout
Maximum time to wait for the element identified bygetWaitForElementSelector()to appear. Whennull, the Playwright default timeout applies. -
getWindowSize
Optional browser viewport size. Whennull, the Playwright default viewport is used. -
getProxySettings
Proxy settings used when launching the browser. When not set (default), no proxy is configured. -
getBrowserMaxAge
Maximum age of a per-thread browser instance before it is restarted. Browsers can accumulate memory over time; restarting periodically can improve stability. Default isnull(no age-based restart). -
getCleanupInterval
Interval between checks for idle (unused) browser instances to close. Cannot benull. Defaults to 10 seconds. -
getScreenshotHandler
When configured, takes a screenshot of each fetched page and stores it according to the handler's configuration (document metadata field or local directory). -
setBrowser
The browser engine used for crawling. Default isPlaywrightBrowser.CHROMIUM.- Returns:
this.
-
setHeadless
Whether to run the browser in headless mode. Default istrue.- Returns:
this.
-
setChannel
Optional browser channel that instructs Playwright to use a system-installed browser instead of its own downloaded binaries. Supported values:"chrome","msedge","firefox". Leave blank (the default) to use Playwright's bundled browser binaries.- Returns:
this.
-
setExecutablePath
Optional path to a custom browser executable. Whennull, Playwright uses the bundled browser binary it downloaded.- Returns:
this.
-
setIgnoreHttpsErrors
Whentrue, HTTPS certificate errors are ignored. Default isfalse.- Returns:
this.
-
setUserAgent
The user agent the browser sends, in place of its own. It is set on the browser context, so both the requests and the page's ownnavigator.userAgentcarry it. Default isnull(the browser's own).- Returns:
this.
-
setLocale
The locale the browser reports (e.g.,fr-CA). It sets theAccept-Languageheader and the page'snavigator.language. Default isnull(the browser's own).- Returns:
this.
-
setTimezoneId
The timezone the browser reports (an IANA name, e.g.,America/Toronto). Default isnull(the system's).- Returns:
this.
-
setJavaScriptEnabled
Whether the browser runs the page's JavaScript. Turn off to read pages as they are served, without any script changing them. Default istrue.- Returns:
this.
-
setBypassCsp
Whether to ignore the page's Content-Security-Policy, so scripts added bygetEarlyPageScript()orgetLatePageScript()are not blocked by it. Default isfalse.- Returns:
this.
-
setBlockServiceWorkers
Whether to keep service workers from registering. A service worker can answer requests itself, so what is read may not be what the site serves. Default isfalse.- Returns:
this.
-
setMobile
Whether to behave as a mobile device: the page is told it is mobile and the screen is touch-enabled. Combine with a mobile user agent and a small window size. Default isfalse.- Returns:
this.
-
setColorScheme
The preferred color scheme. Default isnull.- Returns:
this.
-
setStorageStatePath
A file Playwright wrote of a signed-in session (cookies and local storage, as saved bycontext.storageState()). The browser starts with that session. Default isnull.- Returns:
this.
-
setSlowMo
Optional slow-motion delay applied between Playwright operations. Useful for debugging. Default isnull(no delay).- Returns:
this.
-
setPageLoadTimeout
Maximum time to wait for the page load event. Whennull, the Playwright default (30 s) applies.- Returns:
this.
-
setEarlyPageScript
Optional JavaScript code executed immediately after page navigation, before any wait conditions are applied.- Returns:
this.
-
setLatePageScript
Optional JavaScript code executed after all wait conditions have been satisfied.- Returns:
this.
-
setWaitForElementType
public PlaywrightFetcherConfig setWaitForElementType(PlaywrightFetcherConfig.WaitElementType waitForElementType) The type of reference used when waiting for an element to appear. Used together withgetWaitForElementSelector(). Default isPlaywrightFetcherConfig.WaitElementType.CSSSELECTOR.- Returns:
this.
-
setWaitForElementSelector
Selector expression used to wait for a specific element to appear in the page before returning. The kind of expression is defined bygetWaitForElementType(). Whennull, no element wait is performed.- Returns:
this.
-
setWaitForElementTimeout
Maximum time to wait for the element identified bygetWaitForElementSelector()to appear. Whennull, the Playwright default timeout applies.- Returns:
this.
-
setWindowSize
Optional browser viewport size. Whennull, the Playwright default viewport is used.- Returns:
this.
-
setProxySettings
Proxy settings used when launching the browser. When not set (default), no proxy is configured.- Returns:
this.
-
setBrowserMaxAge
Maximum age of a per-thread browser instance before it is restarted. Browsers can accumulate memory over time; restarting periodically can improve stability. Default isnull(no age-based restart).- Returns:
this.
-
setCleanupInterval
Interval between checks for idle (unused) browser instances to close. Cannot benull. Defaults to 10 seconds.- Returns:
this.
-
setScreenshotHandler
When configured, takes a screenshot of each fetched page and stores it according to the handler's configuration (document metadata field or local directory).- Returns:
this.
-
equals
- Overrides:
equalsin classBaseFetcherConfig
-
canEqual
- Overrides:
canEqualin classBaseFetcherConfig
-
hashCode
public int hashCode()- Overrides:
hashCodein classBaseFetcherConfig
-
toString
- Overrides:
toStringin classBaseFetcherConfig
-