Skip to main content
Version: Next

AdaptivePlaywrightCrawlerOptions

Hierarchy

Index

Properties

optionalinheritedautoscaledPoolOptions

autoscaledPoolOptions?: AutoscaledPoolOptions

Custom options passed to the underlying AutoscaledPool constructor.

NOTE: The runTaskFunction and isTaskReadyFunction options are provided by the crawler and cannot be overridden. However, we can provide a custom implementation of isFinishedFunction.

optionalinheritedbrowserPoolOptions

browserPoolOptions?: Partial<BrowserPoolOptions<BrowserPlugin<CommonLibrary, undefined | Dictionary, CommonBrowser, unknown, CommonPage>>> & Partial<BrowserPoolHooks<BrowserController<BrowserType<{}>, undefined | LaunchOptions, Browser, undefined | { acceptDownloads?: boolean; baseURL?: string; bypassCSP?: boolean; clientCertificates?: { cert?: ... | ...; certPath?: ... | ...; key?: ... | ...; keyPath?: ... | ...; origin: string; passphrase?: ... | ...; pfx?: ... | ...; pfxPath?: ... | ... }[]; colorScheme?: null | light | dark | no-preference; deviceScaleFactor?: number; extraHTTPHeaders?: {}; forcedColors?: null | active | none; geolocation?: { accuracy?: number; latitude: number; longitude: number }; hasTouch?: boolean; httpCredentials?: { origin?: string; password: string; send?: unauthorized | always; username: string }; ignoreHTTPSErrors?: boolean; isMobile?: boolean; javaScriptEnabled?: boolean; locale?: string; logger?: Logger; offline?: boolean; permissions?: string[]; proxy?: { bypass?: string; password?: string; server: string; username?: string }; recordHar?: { content?: omit | embed | attach; mode?: full | minimal; omitContent?: boolean; path: string; urlFilter?: string | RegExp }; recordVideo?: { dir: string; size?: { height: ...; width: ... } }; reducedMotion?: null | reduce | no-preference; screen?: { height: number; width: number }; serviceWorkers?: allow | block; storageState?: string | { cookies: { domain: ...; expires: ...; httpOnly: ...; name: ...; path: ...; sameSite: ...; secure: ...; value: ... }[]; origins: { localStorage: ...; origin: ... }[] }; strictSelectors?: boolean; timezoneId?: string; userAgent?: string; videoSize?: { height: number; width: number }; videosPath?: string; viewport?: null | { height: number; width: number } }, Page>, LaunchContext<BrowserType<{}>, undefined | LaunchOptions, Browser, undefined | { acceptDownloads?: boolean; baseURL?: string; bypassCSP?: boolean; clientCertificates?: { cert?: ... | ...; certPath?: ... | ...; key?: ... | ...; keyPath?: ... | ...; origin: string; passphrase?: ... | ...; pfx?: ... | ...; pfxPath?: ... | ... }[]; colorScheme?: null | light | dark | no-preference; deviceScaleFactor?: number; extraHTTPHeaders?: {}; forcedColors?: null | active | none; geolocation?: { accuracy?: number; latitude: number; longitude: number }; hasTouch?: boolean; httpCredentials?: { origin?: string; password: string; send?: unauthorized | always; username: string }; ignoreHTTPSErrors?: boolean; isMobile?: boolean; javaScriptEnabled?: boolean; locale?: string; logger?: Logger; offline?: boolean; permissions?: string[]; proxy?: { bypass?: string; password?: string; server: string; username?: string }; recordHar?: { content?: omit | embed | attach; mode?: full | minimal; omitContent?: boolean; path: string; urlFilter?: string | RegExp }; recordVideo?: { dir: string; size?: { height: ...; width: ... } }; reducedMotion?: null | reduce | no-preference; screen?: { height: number; width: number }; serviceWorkers?: allow | block; storageState?: string | { cookies: { domain: ...; expires: ...; httpOnly: ...; name: ...; path: ...; sameSite: ...; secure: ...; value: ... }[]; origins: { localStorage: ...; origin: ... }[] }; strictSelectors?: boolean; timezoneId?: string; userAgent?: string; videoSize?: { height: number; width: number }; videosPath?: string; viewport?: null | { height: number; width: number } }, Page>, Page>>

Custom options passed to the underlying BrowserPool constructor. We can tweak those to fine-tune browser management.

optionalinheritederrorHandler

User-provided function that allows modifying the request object before it gets retried by the crawler. It's executed before each retry for the requests that failed less than maxRequestRetries times.

The function receives the BrowserCrawlingContext (actual context will be enhanced with the crawler specific properties) as the first argument, where the request corresponds to the request to be retried. Second argument is the Error instance that represents the last error thrown during processing of the request.

optionalinheritedexperiments

experiments?: CrawlerExperiments

Enables experimental features of Crawlee, which can alter the behavior of the crawler. WARNING: these options are not guaranteed to be stable and may change or be removed at any time.

optionalinheritedfailedRequestHandler

failedRequestHandler?: BrowserErrorHandler<PlaywrightCrawlingContext<Dictionary>>

A function to handle requests that failed more than option.maxRequestRetries times.

The function receives the BrowserCrawlingContext (actual context will be enhanced with the crawler specific properties) as the first argument, where the request corresponds to the failed request. Second argument is the Error instance that represents the last error thrown during processing of the request.

optionalinheritedheadless

headless?: boolean | new | old

Whether to run browser in headless mode. Defaults to true. Can be also set via Configuration.

optionalinheritedhttpClient

httpClient?: BaseHttpClient

HTTP client implementation for the sendRequest context helper and for plain HTTP crawling. Defaults to a new instance of GotScrapingHttpClient

optionalinheritedignoreIframes

ignoreIframes?: boolean

Whether to ignore iframes when processing the page content via parseWithCheerio helper. By default, iframes are expanded automatically. Use this option to disable this behavior.

optionalinheritedignoreShadowRoots

ignoreShadowRoots?: boolean

Whether to ignore custom elements (and their #shadow-roots) when processing the page content via parseWithCheerio helper. By default, they are expanded automatically. Use this option to disable this behavior.

optionalinheritedkeepAlive

keepAlive?: boolean

Allows to keep the crawler alive even if the RequestQueue gets empty. By default, the crawler.run() will resolve once the queue is empty. With keepAlive: true it will keep running, waiting for more requests to come. Use crawler.teardown() to exit the crawler.

optionalinheritedlaunchContext

launchContext?: PlaywrightLaunchContext

The same options as used by launchPlaywright.

optionalinheritedmaxConcurrency

maxConcurrency?: number

Sets the maximum concurrency (parallelism) for the crawl. Shortcut for the AutoscaledPool maxConcurrency option.

optionalinheritedmaxRequestRetries

maxRequestRetries?: number = 3

Indicates how many times the request is retried if requestHandler fails.

optionalinheritedmaxRequestsPerCrawl

maxRequestsPerCrawl?: number

Maximum number of pages that the crawler will open. The crawl will stop when this limit is reached. This value should always be set in order to prevent infinite loops in misconfigured crawlers.

NOTE: In cases of parallel crawling, the actual number of pages visited might be slightly higher than this value.

optionalinheritedmaxRequestsPerMinute

maxRequestsPerMinute?: number

The maximum number of requests per minute the crawler should run. By default, this is set to Infinity, but we can pass any positive, non-zero integer. Shortcut for the AutoscaledPool maxTasksPerMinute option.

optionalinheritedmaxSessionRotations

maxSessionRotations?: number = 10

Maximum number of session rotations per request. The crawler will automatically rotate the session in case of a proxy error or if it gets blocked by the website.

The session rotations are not counted towards the maxRequestRetries limit.

optionalinheritedminConcurrency

minConcurrency?: number

Sets the minimum concurrency (parallelism) for the crawl. Shortcut for the AutoscaledPool minConcurrency option.

WARNING: If we set this value too high with respect to the available system memory and CPU, our crawler will run extremely slow or crash. If not sure, it's better to keep the default value and the concurrency will scale up automatically.

optionalinheritednavigationTimeoutSecs

navigationTimeoutSecs?: number

Timeout in which page navigation needs to finish, in seconds.

optionalinheritedpersistCookiesPerSession

persistCookiesPerSession?: boolean

Defines whether the cookies should be persisted for sessions. This can only be used when useSessionPool is set to true.

optionalinheritedpostNavigationHooks

postNavigationHooks?: PlaywrightHook[]

Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful. The function accepts crawlingContext as the only parameter. Example:

postNavigationHooks: [
async (crawlingContext) => {
const { page } = crawlingContext;
if (hasCaptcha(page)) {
await solveCaptcha (page);
}
},
]

optionalinheritedpreNavigationHooks

preNavigationHooks?: PlaywrightHook[]

Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies or browser properties before navigation. The function accepts two parameters, crawlingContext and gotoOptions, which are passed to the page.goto() function the crawler calls to navigate. Example:

preNavigationHooks: [
async (crawlingContext, gotoOptions) => {
const { page } = crawlingContext;
await page.evaluate((attr) => { window.foo = attr; }, 'bar');
},
]

Modyfing pageOptions is supported only in Playwright incognito. See PrePageCreateHook

optionalinheritedproxyConfiguration

proxyConfiguration?: ProxyConfiguration

If set, the crawler will be configured for all connections to use the Proxy URLs provided and rotated according to the configuration.

optionalrenderingTypeDetectionRatio

renderingTypeDetectionRatio?: number

Specifies the frequency of rendering type detection checks - 0.1 means roughly 10% of requests. Defaults to 0.1 (so 10%).

optionalrenderingTypePredictor

renderingTypePredictor?: Pick<RenderingTypePredictor, predict | storeResult>

A custom rendering type predictor

optionalrequestHandler

requestHandler?: (crawlingContext: { request: LoadedRequest<Request<Dictionary>> } & Omit<AdaptivePlaywrightCrawlerContext, request>) => Awaitable<void>

Function that is called to process each request.

The function receives the AdaptivePlaywrightCrawlingContext as an argument, and it must refrain from calling code with side effects, other than the methods of the crawling context. Any other side effects may be invoked repeatedly by the crawler, which can lead to inconsistent results.

The function must return a promise, which is then awaited by the crawler.

If the function throws an exception, the crawler will try to re-crawl the request later, up to option.maxRequestRetries times.


Type declaration

optionalinheritedrequestHandlerTimeoutSecs

requestHandlerTimeoutSecs?: number = 60

Timeout in which the function passed as requestHandler needs to finish, in seconds.

optionalinheritedrequestList

requestList?: IRequestList

Static list of URLs to be processed. If not provided, the crawler will open the default request queue when the crawler.addRequests() function is called.

Alternatively, requests parameter of crawler.run() could be used to enqueue the initial requests - it is a shortcut for running crawler.addRequests() before the crawler.run().

optionalinheritedrequestQueue

requestQueue?: RequestProvider

Dynamic queue of URLs to be processed. This is useful for recursive crawling of websites. If not provided, the crawler will open the default request queue when the crawler.addRequests() function is called.

Alternatively, requests parameter of crawler.run() could be used to enqueue the initial requests - it is a shortcut for running crawler.addRequests() before the crawler.run().

optionalresultChecker

resultChecker?: (result: RequestHandlerResult) => boolean

An optional callback that is called on dataset items found by the request handler in plain HTTP mode. If it returns false, the request is retried in a browser. If no callback is specified, every dataset item is considered valid.


Type declaration

optionalresultComparator

resultComparator?: (resultA: RequestHandlerResult, resultB: RequestHandlerResult) => boolean

An optional callback used in rendering type detection. On each detection, the result of the plain HTTP run is compared to that of the browser one. If the callback returns true, the results are considered equal and the target site is considered static. If no result comparator is specified, but there is a resultChecker, any site where the resultChecker returns true is considered static. If neither resultComparator nor resultChecker are specified, a deep comparison of returned dataset items is used as a default.


Type declaration

optionalinheritedretryOnBlocked

retryOnBlocked?: boolean

If set to true, the crawler will automatically try to bypass any detected bot protection.

Currently supports:

optionalinheritedsameDomainDelaySecs

sameDomainDelaySecs?: number = 0

Indicates how much time (in seconds) to wait before crawling another same domain request.

optionalinheritedsessionPoolOptions

sessionPoolOptions?: SessionPoolOptions

The configuration options for SessionPool to use.

optionalinheritedstatisticsOptions

statisticsOptions?: StatisticsOptions

Customize the way statistics collecting works, such as logging interval or whether to output them to the Key-Value store.

optionalinheritedstatusMessageCallback

statusMessageCallback?: StatusMessageCallback<BasicCrawlingContext<Dictionary>, BasicCrawler<BasicCrawlingContext<Dictionary>>>

Allows overriding the default status message. The callback needs to call crawler.setStatusMessage() explicitly. The default status message is provided in the parameters.

const crawler = new CheerioCrawler({
statusMessageCallback: async (ctx) => {
return ctx.crawler.setStatusMessage(`this is status message from ${new Date().toISOString()}`, { level: 'INFO' }); // log level defaults to 'DEBUG'
},
statusMessageLoggingInterval: 1, // defaults to 10s
async requestHandler({ $, enqueueLinks, request, log }) {
// ...
},
});

optionalinheritedstatusMessageLoggingInterval

statusMessageLoggingInterval?: number

Defines the length of the interval for calling the setStatusMessage in seconds.

optionalinheriteduseSessionPool

useSessionPool?: boolean

Basic crawler will initialize the SessionPool with the corresponding sessionPoolOptions. The session instance will be than available in the requestHandler.