Skip to main content
Version: 3.4

BrowserCrawlerOptions <Context, InternalBrowserPoolOptions, __BrowserPlugins, __BrowserControllerReturn, __LaunchContextReturn>

Hierarchy

  • Omit<BasicCrawlerOptions, requestHandler | handleRequestFunction | failedRequestHandler | handleFailedRequestFunction | errorHandler>
    • BrowserCrawlerOptions
      • PuppeteerCrawlerOptions
      • PlaywrightCrawlerOptions

Index

Properties

optionalautoscaledPoolOptions

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.

optionalbrowserPoolOptions

browserPoolOptions?: Partial<BrowserPoolOptions<BrowserPlugin<CommonLibrary, undefined | Dictionary, CommonBrowser, unknown, CommonPage>>> & Partial<BrowserPoolHooks<__BrowserControllerReturn, __LaunchContextReturn, UnwrapPromise<ReturnType<__BrowserControllerReturn[newPage]>>>>

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

optionalerrorHandler

errorHandler?: BrowserErrorHandler<Context>

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.

optionalfailedRequestHandler

failedRequestHandler?: BrowserErrorHandler<Context>

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.

optionalheadless

headless?: boolean

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

optionalkeepAlive

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.

optionallaunchContext

launchContext?: BrowserLaunchContext<any, any>

optionalmaxConcurrency

maxConcurrency?: number

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

optionalmaxRequestRetries

maxRequestRetries?: number = 3

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

optionalmaxRequestsPerCrawl

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.

optionalmaxRequestsPerMinute

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.

optionalminConcurrency

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.

optionalnavigationTimeoutSecs

navigationTimeoutSecs?: number

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

optionalpersistCookiesPerSession

persistCookiesPerSession?: boolean

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

optionalpostNavigationHooks

postNavigationHooks?: BrowserHook<Context, Dictionary>[]

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);
}
},
]

optionalpreNavigationHooks

preNavigationHooks?: BrowserHook<Context, Dictionary>[]

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');
gotoOptions.timeout = 60_000;
gotoOptions.waitUntil = 'domcontentloaded';
},
]

Modyfing pageOptions is supported only in Playwright incognito. See PrePageCreateHook

optionalproxyConfiguration

proxyConfiguration?: ProxyConfiguration

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

optionalrequestHandler

requestHandler?: BrowserRequestHandler<Context>

Function that is called to process each request.

The function receives the BrowserCrawlingContext (actual context will be enhanced with the crawler specific properties) as an argument, where:

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 the maxRequestRetries times. If all the retries fail, the crawler calls the function provided to the failedRequestHandler parameter. To make this work, we should always let our function throw exceptions rather than catch them. The exceptions are logged to the request using the Request.pushErrorMessage() function.

optionalrequestHandlerTimeoutSecs

requestHandlerTimeoutSecs?: number = 60

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

optionalrequestList

requestList?: RequestList

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().

optionalrequestQueue

requestQueue?: RequestQueue

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().

optionalsessionPoolOptions

sessionPoolOptions?: SessionPoolOptions

The configuration options for SessionPool to use.

optionalstatusMessageLoggingInterval

statusMessageLoggingInterval?: number

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

optionaluseSessionPool

useSessionPool?: boolean

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