@crawlee/browser
Provides a simple framework for parallel crawling of web pages using headless browsers with Puppeteer and Playwright. The URLs to crawl are fed either from a static list of URLs or from a dynamic queue of URLs enabling recursive crawling of websites.
Since BrowserCrawler uses headless (or even headful) browsers to download web pages and extract data, it is useful for crawling of websites that require to execute JavaScript. If the target website doesn't need JavaScript, we should consider using the CheerioCrawler, which downloads the pages using raw HTTP requests and is about 10x faster.
The source URLs are represented by the Request objects that are fed from the RequestList or RequestQueue instances provided by the requestList or requestQueue constructor options, respectively. If neither requestList nor requestQueue options are provided, the crawler will open the default request queue either when the crawler.addRequests() function is called, or if requests parameter (representing the initial requests) of the crawler.run() function is provided.
If both requestList and requestQueue options are used, the instance first processes URLs from the RequestList and automatically enqueues all of them to the RequestQueue before it starts their processing. This ensures that a single URL is not crawled multiple times.
The crawler finishes when there are no more Request objects to crawl.
BrowserCrawler opens a new browser page (i.e. tab or window) for each Request object to crawl and then calls the function provided by user as the requestHandler option.
New pages are only opened when there is enough free CPU and memory available, as judged by the crawler's ConcurrencySystem.
Concurrency is tuned via the minConcurrency, maxConcurrency and maxRequestsPerMinute options of the BrowserCrawler constructor, or, for finer control, by injecting a pre-configured concurrencySystem.
NOTE: the pool of browser instances is internally managed by the BrowserPool class.
Index
Crawlers
Other
- AddRequestsBatchedOptions
- AddRequestsBatchedResult
- AfterCommitError
- ApifyLogAdapter
- ArgumentValidationError
- BaseCrawleeLogger
- BasicCrawler
- BasicCrawlerOptions
- BasicCrawlingContext
- BLOCKED_STATUS_CODES
- CalculatedStatistics
- CleanupRegistrar
- coerceBoolean
- coerceNumber
- ConcurrencyConsumer
- ConcurrencySystem
- ConcurrencySystemOptions
- ConfigField
- Configuration
- ConfigurationInput
- ConfigurationOptions
- ContextMiddleware
- ContextPipeline
- ContextPipelineCleanupError
- ContextPipelineInitializationError
- ContextPipelineInterruptedError
- CpuLoadSignal
- CpuLoadSignalOptions
- crawleeConfigFields
- CrawleeLogger
- CrawleeLoggerOptions
- CrawlerAddRequestsOptions
- CrawlerAddRequestsResult
- CrawlerRunOptions
- CrawlingContext
- CrawlingRequest
- createBasicRouter
- CreateSession
- createStorageTransaction
- CriticalError
- Dataset
- DatasetConsumer
- DatasetContent
- DatasetDataOptions
- DatasetExportOptions
- DatasetExportToOptions
- DatasetIteratorOptions
- DatasetMapper
- DatasetReducer
- DatasetStats
- defaultRoute
- DefaultRouteUserData
- DefaultStorageIdentifier
- EnqueueLinksOptions
- EnqueueStrategy
- EnqueueStrategyOption
- EnqueueUrlsOptions
- ErrnoException
- ErrorHandler
- ErrorTracker
- ErrorTrackerOptions
- EventLoopLoadSignal
- EventLoopLoadSignalOptions
- EventManager
- EventManagerOptions
- EventStatusMessageData
- EventType
- EventTypeName
- ExplicitStorageIdentifier
- ExtractLinksOptions
- field
- FieldsInput
- FieldsOutput
- FinalStatistics
- GetUserDataFromRequest
- GlobInput
- GlobObject
- IConcurrencySystem
- IProxyConfiguration
- IRequestLoader
- IRequestManager
- IStatistics
- IStorage
- KeyConsumer
- KeyValueStore
- KeyValueStoreIteratorOptions
- KeyValueStoreRawRecord
- KeyValueStoreStats
- LabeledSource
- LoadedRequest
- LoadSignal
- LoadSignalInfo
- LoadSignalsOptions
- LoadSignalStartContext
- LoadSnapshot
- LocalEventManager
- LocalEventManagerOptions
- log
- Log
- Logger
- LoggerJson
- LoggerOptions
- LoggerText
- LogLevel
- LogOptions
- MemoryLoadSignal
- MemoryLoadSignalOptions
- MemoryStorageBackend
- MemoryStorageOptions
- MissingSessionError
- NavigationSkippedError
- NonRetryableError
- PacingScope
- PacingSignal
- parseRetryAfterHeader
- parseValue
- PersistenceOptions
- PersistentRateLimitError
- ProxyConfiguration
- ProxyConfigurationFunction
- ProxyConfigurationOptions
- purgeDefaultStorages
- PushErrorMessageOptions
- RecordOptions
- RecoverableState
- RecoverableStateBaseOptions
- RecoverableStateOptions
- RecoverableStatePersistenceOptions
- RegExpInput
- RegExpObject
- Request
- RequestHandler
- RequestHandlerError
- RequestList
- RequestListOptions
- RequestListSource
- RequestListSourcesFunction
- RequestListState
- RequestLoaderStatus
- RequestManagerTandem
- RequestOptions
- RequestQueue
- RequestQueueOperationInfo
- RequestQueueOperationOptions
- RequestQueueStats
- RequestsLike
- RequestSourceStatus
- RequestState
- RequestThrottledError
- RequestTransform
- RequestValidationError
- RequireContextPipeline
- ResolvedConfigValues
- RestrictedCrawlingContext
- RetryRequestError
- RouteOptions
- Router
- RouterHandler
- RouterHandlerContext
- RouterLabel
- RouterRoutes
- RouteSchemas
- RoutesFromSchemas
- SchemaIssue
- serializeValue
- ServiceConflictError
- serviceLocator
- ServiceLocator
- Session
- SessionError
- SessionOptions
- SessionPool
- SessionPoolOptions
- SessionRetiredError
- SessionReuseStrategy
- SitemapRequestLoader
- SitemapRequestLoaderOptions
- SkippedRequestCallback
- SkippedRequestReason
- SnapshotStore
- Source
- StateConversion
- StateValidationError
- StatisticPersistedState
- Statistics
- StatisticsOptions
- StatisticState
- StatisticStateExtensionOptions
- StatusMessageCallback
- StatusMessageCallbackParams
- StorageBackend
- StorageBackendLoadSignal
- StorageBackendLoadSignalOptions
- StorageIdentifier
- StorageInstanceManager
- StorageOpenOptions
- StorageTransaction
- StorageTransactionOptions
- StorageTransactionState
- StorageTransactionView
- StorageWriteMode
- StorageWritePolicy
- SyncStateConversion
- SystemInfo
- TaskLoopOptions
- TaskLoopPredicates
- ThrottlingRequestManager
- ThrottlingRequestManagerOptions
- TypedContextAddRequests
- TypedContextEnqueueLinks
- TypedRequestsLike
- UrlPatternInput
- useState
- UseStateOptions
- withDirectStorageAccess
- withStorageTransaction
- BrowserCrawlerOptions
- BrowserCrawlingContext
- BrowserLaunchContext
- BrowserHook
- OwnedBrowserPool
Other
AddRequestsBatchedOptions
AddRequestsBatchedResult
AfterCommitError
ApifyLogAdapter
ArgumentValidationError
BaseCrawleeLogger
BasicCrawler
BasicCrawlerOptions
BasicCrawlingContext
BLOCKED_STATUS_CODES
CalculatedStatistics
CleanupRegistrar
coerceBoolean
coerceNumber
ConcurrencyConsumer
ConcurrencySystem
ConcurrencySystemOptions
ConfigField
Configuration
ConfigurationInput
ConfigurationOptions
ContextMiddleware
ContextPipeline
ContextPipelineCleanupError
ContextPipelineInitializationError
ContextPipelineInterruptedError
CpuLoadSignal
CpuLoadSignalOptions
crawleeConfigFields
CrawleeLogger
CrawleeLoggerOptions
CrawlerAddRequestsOptions
CrawlerAddRequestsResult
CrawlerRunOptions
CrawlingContext
CrawlingRequest
createBasicRouter
CreateSession
createStorageTransaction
CriticalError
Dataset
DatasetConsumer
DatasetContent
DatasetDataOptions
DatasetExportOptions
DatasetExportToOptions
DatasetIteratorOptions
DatasetMapper
DatasetReducer
DatasetStats
defaultRoute
DefaultRouteUserData
DefaultStorageIdentifier
EnqueueLinksOptions
EnqueueStrategy
EnqueueStrategyOption
EnqueueUrlsOptions
ErrnoException
ErrorHandler
ErrorTracker
ErrorTrackerOptions
EventLoopLoadSignal
EventLoopLoadSignalOptions
EventManager
EventManagerOptions
EventStatusMessageData
EventType
EventTypeName
ExplicitStorageIdentifier
ExtractLinksOptions
field
FieldsInput
FieldsOutput
FinalStatistics
GetUserDataFromRequest
GlobInput
GlobObject
IConcurrencySystem
IProxyConfiguration
IRequestLoader
IRequestManager
IStatistics
IStorage
KeyConsumer
KeyValueStore
KeyValueStoreIteratorOptions
KeyValueStoreRawRecord
KeyValueStoreStats
LabeledSource
LoadedRequest
LoadSignal
LoadSignalInfo
LoadSignalsOptions
LoadSignalStartContext
LoadSnapshot
LocalEventManager
LocalEventManagerOptions
log
Log
Logger
LoggerJson
LoggerOptions
LoggerText
LogLevel
LogOptions
MemoryLoadSignal
MemoryLoadSignalOptions
MemoryStorageBackend
MemoryStorageOptions
MissingSessionError
NavigationSkippedError
NonRetryableError
PacingScope
PacingSignal
parseRetryAfterHeader
parseValue
PersistenceOptions
PersistentRateLimitError
ProxyConfiguration
ProxyConfigurationFunction
ProxyConfigurationOptions
purgeDefaultStorages
PushErrorMessageOptions
RecordOptions
RecoverableState
RecoverableStateBaseOptions
RecoverableStateOptions
RecoverableStatePersistenceOptions
RegExpInput
RegExpObject
Request
RequestHandler
RequestHandlerError
RequestList
RequestListOptions
RequestListSource
RequestListSourcesFunction
RequestListState
RequestLoaderStatus
RequestManagerTandem
RequestOptions
RequestQueue
RequestQueueOperationInfo
RequestQueueOperationOptions
RequestQueueStats
RequestsLike
RequestSourceStatus
RequestState
RequestThrottledError
RequestTransform
RequestValidationError
RequireContextPipeline
ResolvedConfigValues
RestrictedCrawlingContext
RetryRequestError
RouteOptions
Router
RouterHandler
RouterHandlerContext
RouterLabel
RouterRoutes
RouteSchemas
RoutesFromSchemas
SchemaIssue
serializeValue
ServiceConflictError
serviceLocator
ServiceLocator
Session
SessionError
SessionOptions
SessionPool
SessionPoolOptions
SessionRetiredError
SessionReuseStrategy
SitemapRequestLoader
SitemapRequestLoaderOptions
SkippedRequestCallback
SkippedRequestReason
SnapshotStore
Source
StateConversion
StateValidationError
StatisticPersistedState
Statistics
StatisticsOptions
StatisticState
StatisticStateExtensionOptions
StatusMessageCallback
StatusMessageCallbackParams
StorageBackend
StorageBackendLoadSignal
StorageBackendLoadSignalOptions
StorageIdentifier
StorageInstanceManager
StorageOpenOptions
StorageTransaction
StorageTransactionOptions
StorageTransactionState
StorageTransactionView
StorageWriteMode
StorageWritePolicy
SyncStateConversion
SystemInfo
TaskLoopOptions
TaskLoopPredicates
ThrottlingRequestManager
ThrottlingRequestManagerOptions
TypedContextAddRequests
TypedContextEnqueueLinks
TypedRequestsLike
UrlPatternInput
useState
UseStateOptions
withDirectStorageAccess
withStorageTransaction
BrowserHook
Type parameters
- Context = BrowserCrawlingContext
- ContextExtension = {}
Type declaration
Parameters
crawlingContext: Context & ContextExtension
Returns Awaitable<void | Partial<Context>>
OwnedBrowserPool
Type parameters
- Page
The type of a browser pool the crawler builds (and therefore owns) for itself. It's an IBrowserPool that additionally exposes the lifecycle hooks a crawler only ever calls on a pool it created — which is why IBrowserPool itself intentionally omits them:
releaseAllBrowsers()at the end of every run, anddestroy()once the crawler itself is destroyed.