Skip to main content

PlaywrightFetcher

Uses Microsoft Playwright for browser-based crawling, driving real browser engines (Chromium, Firefox, WebKit) across Windows, macOS, and Linux. Unlike WebDriverFetcher, no exte...

Notes​

By default, Playwright downloads and uses its own browser binaries stored under ~/.cache/ms-playwright. To use a system-installed browser instead (e.g., Chrome, Edge, or Firefox already present on the machine or CI runner), set the channel property (e.g., chrome, msedge, firefox).

Because Playwright manages one browser instance per thread, it is safe to use with multi-threaded crawling. Browsers are automatically restarted after browserMaxNavigations navigations or after they exceed browserMaxAge, whichever comes first.

Examples​

Chromium with element wait​

class: PlaywrightFetcher
browser: CHROMIUM
headless: true
waitForElementType: CSSSELECTOR
waitForElementSelector: "#main-content"
waitForElementTimeout: PT10S
referenceFilters:
- class: GenericReferenceFilter
valueMatcher:
method: REGEX
pattern: ".*dynamic.*"

Reading a site as a mobile visitor, in French​

class: PlaywrightFetcher
userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1 (operator: Acme Corp; +https://acme.example/bot)"
mobile: true
windowSize: 390x844
locale: fr-CA
timezoneId: America/Toronto
blockServiceWorkers: true

Usage​

Full configuration skeleton, with every option and its default
class: PlaywrightFetcher
args:
- string
blockServiceWorkers: false
browser: CHROMIUM
browserMaxAge: 0
browserMaxNavigations: 0
bypassCsp: false
channel: string
cleanupInterval: 0
colorScheme: LIGHT
earlyPageScript: string
executablePath: string
extraHttpHeaders: {}
headless: false
httpCredentials:
password: string
passwordKey:
size: 0
source: KEY
value: string
username: string
ignoreHttpsErrors: false
javaScriptEnabled: false
latePageScript: string
locale: string
mobile: false
pageLoadTimeout: 0
proxySettings:
credentials:
password: string
passwordKey: {}
username: string
host:
name: string
port: 0
realm: string
scheme: string
referenceFilters: []
screenshotHandler:
configuration:
cssSelector: string
imageFormat: string
targetDir: string
targetDirField: string
targetDirStructure: URL2PATH
targetMetaField: string
targets: []
slowMo: 0
storageStatePath: string
timezoneId: string
userAgent: string
waitForElementSelector: string
waitForElementTimeout: 0
waitForElementType: TAGNAME
windowSize: string

Properties​

PropertyTypeRequiredDefault
argsstring[]No-
blockServiceWorkersbooleanNofalse
browserenumNoCHROMIUM
browserMaxAgeintegerNo-
browserMaxNavigationsintegerNo-1
bypassCspbooleanNofalse
channelstringNo-
cleanupIntervalintegerNo10000
colorSchemeenumNo-
earlyPageScriptstringNo-
executablePathstringNo-
extraHttpHeadersRecord<string, string>No-
headlessbooleanNotrue
httpCredentialsCredentialsNoCredentials
ignoreHttpsErrorsbooleanNofalse
javaScriptEnabledbooleanNotrue
latePageScriptstringNo-
localestringNo-
mobilebooleanNofalse
pageLoadTimeoutintegerNo-
proxySettingsProxySettingsNo-
referenceFiltersReferenceFilter[]No-
screenshotHandlerPlaywrightScreenshotHandlerNo-
slowMointegerNo-
storageStatePathstringNo-
timezoneIdstringNo-
userAgentstringNo-
waitForElementSelectorstringNo-
waitForElementTimeoutintegerNo-
waitForElementTypeenumNoCSSSELECTOR
windowSizestringNo-

Property Details​

args​

Optional command-line arguments passed to the browser at launch (e.g., --disable-extensions).

blockServiceWorkers​

When true, service workers are kept from registering. A service worker can answer requests itself, so what is read may not be what the site serves. Default is false.

browser​

The browser engine to use for crawling. Supported values are CHROMIUM (default), FIREFOX, and WEBKIT. Ignored when channel is set.

Allowed Values​

  • CHROMIUM
  • FIREFOX
  • WEBKIT

browserMaxAge​

Maximum age of a per-thread browser instance before it is automatically restarted. Helps prevent memory accumulation over long crawls. Default is no age-based restart.

browserMaxNavigations​

Maximum number of page navigations per thread browser instance before it is automatically restarted. Helps prevent memory accumulation. Default is -1 (unlimited).

bypassCsp​

When true, the page's Content-Security-Policy is ignored, so scripts added by earlyPageScript or latePageScript are not blocked by it. Default is false.

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.

cleanupInterval​

How often idle (unused) per-thread browser instances are checked and closed. Defaults to 10 seconds.

colorScheme​

The preferred color scheme pages are told about (the prefers-color-scheme media query). Supported values: LIGHT, DARK, NO_PREFERENCE. When not set, the browser's own is used.

Allowed Values​

  • LIGHT
  • DARK
  • NO_PREFERENCE

earlyPageScript​

Optional JavaScript snippet executed immediately after page navigation, before any wait conditions (such as waitForElementSelector) are applied. Useful for dismissing popups or injecting page-level state.

executablePath​

Optional path to a custom browser executable. When not set, Playwright uses the bundled browser binary it downloaded.

extraHttpHeaders​

Extra HTTP headers sent with every request, as header names and values.

headless​

Whether to run the browser in headless (no visible window) mode. Default is true.

httpCredentials​

The username and password the browser answers HTTP Basic or Digest authentication challenges with. They are sent only if the site asks.

ignoreHttpsErrors​

When true, HTTPS certificate errors (e.g., self-signed or expired certificates) are ignored. Default is false.

javaScriptEnabled​

Whether the browser runs the page's JavaScript. Turn it off to read pages as they are served, without any script changing them. Default is true.

latePageScript​

Optional JavaScript snippet executed after all wait conditions have been satisfied. Useful for final page manipulation before the content is captured.

locale​

The locale the browser reports (for example fr-CA). It sets the Accept-Language header and the page's navigator.language. When not set, the browser's own is used.

mobile​

When true, the browser behaves as a mobile device: the page is told it is mobile and the screen is touch-enabled. Combine it with a mobile userAgent and a small windowSize. Default is false.

pageLoadTimeout​

Maximum time to wait for the page load event to fire. When not set, the Playwright default (30 seconds) applies.

proxySettings​

Proxy settings used when launching the browser. When not configured, no proxy is applied.

referenceFilters​

One or more reference filters that restrict which URLs this fetcher will handle. When multiple fetchers are configured, each document URL is offered to fetchers in order; the first fetcher whose filters accept the URL handles the request.

screenshotHandler​

When configured, captures a screenshot of each fetched page and stores it according to the handler's settings (document metadata field or local directory).

slowMo​

Optional slow-motion delay applied between Playwright operations. Useful for debugging or visually tracing a crawl. Default is no delay.

storageStatePath​

Path to a file Playwright wrote of a signed-in session (cookies and local storage, as saved by context.storageState()). The browser starts with that session. When not set, it starts with none.

timezoneId​

The timezone the browser reports, as an IANA name (for example America/Toronto). When not set, the system's is used.

userAgent​

The user agent the browser sends, in place of its own. It applies both to the requests and to the page's own navigator.userAgent, so the two agree. When not set, the browser's own is used.

waitForElementSelector​

Selector expression used to wait for a specific element to appear in the page before the content is captured. The type of expression is controlled by waitForElementType. When not set, no element wait is performed.

waitForElementTimeout​

Maximum time to wait for the element identified by waitForElementSelector to appear. When not set, the Playwright default timeout applies.

waitForElementType​

The locator strategy used by waitForElementSelector. Supported values: TAGNAME, CLASSNAME, CSSSELECTOR (default), ID, LINKTEXT, NAME, PARTIALLINKTEXT, XPATH.

Allowed Values​

  • TAGNAME
  • CLASSNAME
  • CSSSELECTOR
  • ID
  • LINKTEXT
  • NAME
  • PARTIALLINKTEXT
  • XPATH

windowSize​

Optional browser viewport size. When not set, the Playwright default viewport is used.