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
- YAML
- JSON
- XML
class: PlaywrightFetcher
browser: CHROMIUM
headless: true
waitForElementType: CSSSELECTOR
waitForElementSelector: "#main-content"
waitForElementTimeout: PT10S
referenceFilters:
- class: GenericReferenceFilter
valueMatcher:
method: REGEX
pattern: ".*dynamic.*"
{
"class": "PlaywrightFetcher",
"browser": "CHROMIUM",
"headless": true,
"waitForElementType": "CSSSELECTOR",
"waitForElementSelector": "#main-content",
"waitForElementTimeout": "PT10S",
"referenceFilters": [
{
"class": "GenericReferenceFilter",
"valueMatcher": {
"method": "REGEX",
"pattern": ".*dynamic.*"
}
}
]
}
<class>PlaywrightFetcher</class>
<browser>CHROMIUM</browser>
<headless>true</headless>
<waitForElementType>CSSSELECTOR</waitForElementType>
<waitForElementSelector>#main-content</waitForElementSelector>
<waitForElementTimeout>PT10S</waitForElementTimeout>
<referenceFilters>
<referenceFilter>
<class>GenericReferenceFilter</class>
<valueMatcher>
<method>REGEX</method>
<pattern>.*dynamic.*</pattern>
</valueMatcher>
</referenceFilter>
</referenceFilters>
Reading a site as a mobile visitor, in French
- YAML
- JSON
- XML
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
{
"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
}
<class>PlaywrightFetcher</class>
<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)</userAgent>
<mobile>true</mobile>
<windowSize>390x844</windowSize>
<locale>fr-CA</locale>
<timezoneId>America/Toronto</timezoneId>
<blockServiceWorkers>true</blockServiceWorkers>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
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
{
"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"
}
<playwrightFetcher>
<class>PlaywrightFetcher</class>
<args>
<arg>string</arg>
</args>
<blockServiceWorkers>false</blockServiceWorkers>
<browser>CHROMIUM</browser>
<browserMaxAge>0</browserMaxAge>
<browserMaxNavigations>0</browserMaxNavigations>
<bypassCsp>false</bypassCsp>
<channel>string</channel>
<cleanupInterval>0</cleanupInterval>
<colorScheme>LIGHT</colorScheme>
<earlyPageScript>string</earlyPageScript>
<executablePath>string</executablePath>
<extraHttpHeaders/>
<headless>false</headless>
<httpCredentials>
<password>string</password>
<passwordKey>
<size>0</size>
<source>KEY</source>
<value>string</value>
</passwordKey>
<username>string</username>
</httpCredentials>
<ignoreHttpsErrors>false</ignoreHttpsErrors>
<javaScriptEnabled>false</javaScriptEnabled>
<latePageScript>string</latePageScript>
<locale>string</locale>
<mobile>false</mobile>
<pageLoadTimeout>0</pageLoadTimeout>
<proxySettings>
<credentials>
<password>string</password>
<passwordKey/>
<username>string</username>
</credentials>
<host>
<name>string</name>
<port>0</port>
</host>
<realm>string</realm>
<scheme>string</scheme>
</proxySettings>
<referenceFilters>
<referenceFilter/>
</referenceFilters>
<screenshotHandler>
<configuration>
<cssSelector>string</cssSelector>
<imageFormat>string</imageFormat>
<targetDir>string</targetDir>
<targetDirField>string</targetDirField>
<targetDirStructure>URL2PATH</targetDirStructure>
<targetMetaField>string</targetMetaField>
<targets>
<target/>
</targets>
</configuration>
</screenshotHandler>
<slowMo>0</slowMo>
<storageStatePath>string</storageStatePath>
<timezoneId>string</timezoneId>
<userAgent>string</userAgent>
<waitForElementSelector>string</waitForElementSelector>
<waitForElementTimeout>0</waitForElementTimeout>
<waitForElementType>TAGNAME</waitForElementType>
<windowSize>string</windowSize>
</playwrightFetcher>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
args | string[] | No | - |
blockServiceWorkers | boolean | No | false |
browser | enum | No | CHROMIUM |
browserMaxAge | integer | No | - |
browserMaxNavigations | integer | No | -1 |
bypassCsp | boolean | No | false |
channel | string | No | - |
cleanupInterval | integer | No | 10000 |
colorScheme | enum | No | - |
earlyPageScript | string | No | - |
executablePath | string | No | - |
extraHttpHeaders | Record<string, string> | No | - |
headless | boolean | No | true |
httpCredentials | Credentials | No | Credentials |
ignoreHttpsErrors | boolean | No | false |
javaScriptEnabled | boolean | No | true |
latePageScript | string | No | - |
locale | string | No | - |
mobile | boolean | No | false |
pageLoadTimeout | integer | No | - |
proxySettings | ProxySettings | No | - |
referenceFilters | ReferenceFilter[] | No | - |
screenshotHandler | PlaywrightScreenshotHandler | No | - |
slowMo | integer | No | - |
storageStatePath | string | No | - |
timezoneId | string | No | - |
userAgent | string | No | - |
waitForElementSelector | string | No | - |
waitForElementTimeout | integer | No | - |
waitForElementType | enum | No | CSSSELECTOR |
windowSize | string | No | - |
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
CHROMIUMFIREFOXWEBKIT
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
LIGHTDARKNO_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
TAGNAMECLASSNAMECSSSELECTORIDLINKTEXTNAMEPARTIALLINKTEXTXPATH
windowSize
Optional browser viewport size. When not set, the Playwright default viewport is used.