Class PlaywrightFetcherConfig

java.lang.Object
com.norconex.crawler.core.fetch.BaseFetcherConfig
com.norconex.crawler.web.fetch.impl.playwright.PlaywrightFetcherConfig

public class PlaywrightFetcherConfig extends BaseFetcherConfig

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:
  • Constructor Details

    • PlaywrightFetcherConfig

      public PlaywrightFetcherConfig()
  • Method Details

    • getHttpCredentials

      public Credentials getHttpCredentials()
      Gets the credentials for HTTP authentication challenges.
      Returns:
      credentials
    • setHttpCredentials

      public PlaywrightFetcherConfig setHttpCredentials(Credentials credentials)
      Sets the credentials for HTTP authentication challenges.
      Parameters:
      credentials - the credentials
      Returns:
      this config
    • getExtraHttpHeaders

      public Map<String,String> getExtraHttpHeaders()
      Returns an unmodifiable view of the extra HTTP headers.
      Returns:
      headers by name
    • setExtraHttpHeaders

      public PlaywrightFetcherConfig setExtraHttpHeaders(Map<String,String> headers)
      Sets the extra HTTP headers sent with every request.
      Parameters:
      headers - header names and values
      Returns:
      this config
    • getArgs

      public List<String> getArgs()
      Returns an unmodifiable view of the browser launch arguments. Use setArgs(List) to replace the list.
      Returns:
      unmodifiable list of launch arguments
    • setArgs

      public PlaywrightFetcherConfig setArgs(List<String> args)
      Sets the browser launch arguments.
      Parameters:
      args - launch arguments
      Returns:
      this config
    • getBrowser

      public PlaywrightBrowser getBrowser()
      The browser engine used for crawling. Default is PlaywrightBrowser.CHROMIUM.
    • isHeadless

      public boolean isHeadless()
      Whether to run the browser in headless mode. Default is true.
    • getChannel

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

      public Path getExecutablePath()
      Optional path to a custom browser executable. When null, Playwright uses the bundled browser binary it downloaded.
    • isIgnoreHttpsErrors

      public boolean isIgnoreHttpsErrors()
      When true, HTTPS certificate errors are ignored. Default is false.
    • getUserAgent

      public String 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 own navigator.userAgent carry it. Default is null (the browser's own).
    • getLocale

      public String getLocale()
      The locale the browser reports (e.g., fr-CA). It sets the Accept-Language header and the page's navigator.language. Default is null (the browser's own).
    • getTimezoneId

      public String getTimezoneId()
      The timezone the browser reports (an IANA name, e.g., America/Toronto). Default is null (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 is true.
    • isBypassCsp

      public boolean isBypassCsp()
      Whether to ignore the page's Content-Security-Policy, so scripts added by getEarlyPageScript() or getLatePageScript() are not blocked by it. Default is false.
    • 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 is false.
    • 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 is false.
    • getColorScheme

      public PlaywrightFetcherConfig.ColorScheme getColorScheme()
      The preferred color scheme. Default is null.
    • getStorageStatePath

      public Path getStorageStatePath()
      A file Playwright wrote of a signed-in session (cookies and local storage, as saved by context.storageState()). The browser starts with that session. Default is null.
    • getSlowMo

      public Duration getSlowMo()
      Optional slow-motion delay applied between Playwright operations. Useful for debugging. Default is null (no delay).
    • getPageLoadTimeout

      public Duration getPageLoadTimeout()
      Maximum time to wait for the page load event. When null, the Playwright default (30 s) applies.
    • getEarlyPageScript

      public String getEarlyPageScript()
      Optional JavaScript code executed immediately after page navigation, before any wait conditions are applied.
    • getLatePageScript

      public String getLatePageScript()
      Optional JavaScript code executed after all wait conditions have been satisfied.
    • getWaitForElementType

      public PlaywrightFetcherConfig.WaitElementType getWaitForElementType()
      The type of reference used when waiting for an element to appear. Used together with getWaitForElementSelector(). Default is PlaywrightFetcherConfig.WaitElementType.CSSSELECTOR.
    • getWaitForElementSelector

      public String getWaitForElementSelector()
      Selector expression used to wait for a specific element to appear in the page before returning. The kind of expression is defined by getWaitForElementType(). When null, no element wait is performed.
    • getWaitForElementTimeout

      public Duration getWaitForElementTimeout()
      Maximum time to wait for the element identified by getWaitForElementSelector() to appear. When null, the Playwright default timeout applies.
    • getWindowSize

      public Dimension getWindowSize()
      Optional browser viewport size. When null, the Playwright default viewport is used.
    • getProxySettings

      public ProxySettings getProxySettings()
      Proxy settings used when launching the browser. When not set (default), no proxy is configured.
    • getBrowserMaxNavigations

      public int getBrowserMaxNavigations()
      A maximum number of navigations after which each per-thread browser instance is restarted. Browsers can accumulate memory over time; restarting periodically can improve stability. Default is -1 (unlimited – no restart).
    • getBrowserMaxAge

      public Duration 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 is null (no age-based restart).
    • getCleanupInterval

      @NonNull public @NonNull Duration getCleanupInterval()
      Interval between checks for idle (unused) browser instances to close. Cannot be null. Defaults to 10 seconds.
    • getScreenshotHandler

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

      public PlaywrightFetcherConfig setBrowser(PlaywrightBrowser browser)
      The browser engine used for crawling. Default is PlaywrightBrowser.CHROMIUM.
      Returns:
      this.
    • setHeadless

      public PlaywrightFetcherConfig setHeadless(boolean headless)
      Whether to run the browser in headless mode. Default is true.
      Returns:
      this.
    • setChannel

      public PlaywrightFetcherConfig setChannel(String channel)
      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

      public PlaywrightFetcherConfig setExecutablePath(Path executablePath)
      Optional path to a custom browser executable. When null, Playwright uses the bundled browser binary it downloaded.
      Returns:
      this.
    • setIgnoreHttpsErrors

      public PlaywrightFetcherConfig setIgnoreHttpsErrors(boolean ignoreHttpsErrors)
      When true, HTTPS certificate errors are ignored. Default is false.
      Returns:
      this.
    • setUserAgent

      public PlaywrightFetcherConfig setUserAgent(String userAgent)
      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 own navigator.userAgent carry it. Default is null (the browser's own).
      Returns:
      this.
    • setLocale

      public PlaywrightFetcherConfig setLocale(String locale)
      The locale the browser reports (e.g., fr-CA). It sets the Accept-Language header and the page's navigator.language. Default is null (the browser's own).
      Returns:
      this.
    • setTimezoneId

      public PlaywrightFetcherConfig setTimezoneId(String timezoneId)
      The timezone the browser reports (an IANA name, e.g., America/Toronto). Default is null (the system's).
      Returns:
      this.
    • setJavaScriptEnabled

      public PlaywrightFetcherConfig setJavaScriptEnabled(boolean javaScriptEnabled)
      Whether the browser runs the page's JavaScript. Turn off to read pages as they are served, without any script changing them. Default is true.
      Returns:
      this.
    • setBypassCsp

      public PlaywrightFetcherConfig setBypassCsp(boolean bypassCsp)
      Whether to ignore the page's Content-Security-Policy, so scripts added by getEarlyPageScript() or getLatePageScript() are not blocked by it. Default is false.
      Returns:
      this.
    • setBlockServiceWorkers

      public PlaywrightFetcherConfig setBlockServiceWorkers(boolean blockServiceWorkers)
      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 is false.
      Returns:
      this.
    • setMobile

      public PlaywrightFetcherConfig setMobile(boolean mobile)
      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 is false.
      Returns:
      this.
    • setColorScheme

      public PlaywrightFetcherConfig setColorScheme(PlaywrightFetcherConfig.ColorScheme colorScheme)
      The preferred color scheme. Default is null.
      Returns:
      this.
    • setStorageStatePath

      public PlaywrightFetcherConfig setStorageStatePath(Path storageStatePath)
      A file Playwright wrote of a signed-in session (cookies and local storage, as saved by context.storageState()). The browser starts with that session. Default is null.
      Returns:
      this.
    • setSlowMo

      public PlaywrightFetcherConfig setSlowMo(Duration slowMo)
      Optional slow-motion delay applied between Playwright operations. Useful for debugging. Default is null (no delay).
      Returns:
      this.
    • setPageLoadTimeout

      public PlaywrightFetcherConfig setPageLoadTimeout(Duration pageLoadTimeout)
      Maximum time to wait for the page load event. When null, the Playwright default (30 s) applies.
      Returns:
      this.
    • setEarlyPageScript

      public PlaywrightFetcherConfig setEarlyPageScript(String earlyPageScript)
      Optional JavaScript code executed immediately after page navigation, before any wait conditions are applied.
      Returns:
      this.
    • setLatePageScript

      public PlaywrightFetcherConfig setLatePageScript(String latePageScript)
      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 with getWaitForElementSelector(). Default is PlaywrightFetcherConfig.WaitElementType.CSSSELECTOR.
      Returns:
      this.
    • setWaitForElementSelector

      public PlaywrightFetcherConfig setWaitForElementSelector(String waitForElementSelector)
      Selector expression used to wait for a specific element to appear in the page before returning. The kind of expression is defined by getWaitForElementType(). When null, no element wait is performed.
      Returns:
      this.
    • setWaitForElementTimeout

      public PlaywrightFetcherConfig setWaitForElementTimeout(Duration waitForElementTimeout)
      Maximum time to wait for the element identified by getWaitForElementSelector() to appear. When null, the Playwright default timeout applies.
      Returns:
      this.
    • setWindowSize

      public PlaywrightFetcherConfig setWindowSize(Dimension windowSize)
      Optional browser viewport size. When null, the Playwright default viewport is used.
      Returns:
      this.
    • setProxySettings

      public PlaywrightFetcherConfig setProxySettings(ProxySettings proxySettings)
      Proxy settings used when launching the browser. When not set (default), no proxy is configured.
      Returns:
      this.
    • setBrowserMaxNavigations

      public PlaywrightFetcherConfig setBrowserMaxNavigations(int browserMaxNavigations)
      A maximum number of navigations after which each per-thread browser instance is restarted. Browsers can accumulate memory over time; restarting periodically can improve stability. Default is -1 (unlimited – no restart).
      Returns:
      this.
    • setBrowserMaxAge

      public PlaywrightFetcherConfig setBrowserMaxAge(Duration browserMaxAge)
      Maximum age of a per-thread browser instance before it is restarted. Browsers can accumulate memory over time; restarting periodically can improve stability. Default is null (no age-based restart).
      Returns:
      this.
    • setCleanupInterval

      public PlaywrightFetcherConfig setCleanupInterval(@NonNull @NonNull Duration cleanupInterval)
      Interval between checks for idle (unused) browser instances to close. Cannot be null. Defaults to 10 seconds.
      Returns:
      this.
    • setScreenshotHandler

      public PlaywrightFetcherConfig 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).
      Returns:
      this.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class BaseFetcherConfig
    • canEqual

      protected boolean canEqual(Object other)
      Overrides:
      canEqual in class BaseFetcherConfig
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class BaseFetcherConfig
    • toString

      public String toString()
      Overrides:
      toString in class BaseFetcherConfig