@crawlee/core
Core set of classes required for Crawlee.
The crawlee package consists of several smaller packages, released separately under @crawlee namespace:
@crawlee/core: the base for all the crawler implementations, also contains things likeRequest,RequestQueue,RequestListorDatasetclasses@crawlee/cheerio: exportsCheerioCrawler@crawlee/playwright: exportsPlaywrightCrawler@crawlee/puppeteer: exportsPuppeteerCrawler@crawlee/linkedom: exportsLinkeDOMCrawler@crawlee/jsdom: exportsJSDOMCrawler@crawlee/basic: exportsBasicCrawler@crawlee/http: exportsHttpCrawler(which is used for creating@crawlee/jsdomand@crawlee/cheerio)@crawlee/browser: exportsBrowserCrawler(which is used for creating@crawlee/playwrightand@crawlee/puppeteer)@crawlee/memory-storage:@apify/storage-localalternative@crawlee/browser-pool: previouslybrowser-poolpackage@crawlee/utils: utility methods@crawlee/types: holds TS interfaces mainly about theStorageBackend
Installing Crawlee
Most of the Crawlee packages are extending and reexporting each other, so it's enough to install just the one you plan on using, e.g. @crawlee/playwright if you plan on using playwright - it already contains everything from the @crawlee/browser package, which includes everything from @crawlee/basic, which includes everything from @crawlee/core.
If we don't care much about additional code being pulled in, we can just use the crawlee meta-package, which contains (re-exports) most of the @crawlee/* packages, and therefore contains all the crawler classes.
npm install crawlee
Or if all we need is cheerio support, we can install only @crawlee/cheerio.
npm install @crawlee/cheerio
When using playwright or puppeteer, we still need to install those dependencies explicitly - this allows the users to be in control of which version will be used.
npm install crawlee playwright
# or npm install @crawlee/playwright playwright
Alternatively we can also use the crawlee meta-package which contains (re-exports) most of the @crawlee/* packages, and therefore contains all the crawler classes.
Sometimes you might want to use some utility methods from
@crawlee/utils, so you might want to install that as well. This package contains some utilities that were previously available underApify.utils. Browser related utilities can be also found in the crawler packages (e.g.@crawlee/playwright).
Index
Crawlers
Result Stores
Scaling
Sources
Other
- EnqueueStrategy
- EventType
- LogLevel
- RequestState
- ApifyLogAdapter
- ArgumentValidationError
- BaseCrawleeLogger
- Configuration
- ContextPipeline
- ContextPipelineCleanupError
- ContextPipelineInitializationError
- ContextPipelineInterruptedError
- CriticalError
- ErrorSnapshotter
- ErrorTracker
- EventManager
- LocalEventManager
- Log
- Logger
- LoggerJson
- LoggerText
- MemoryStorageBackend
- MissingSessionError
- NavigationSkippedError
- NonRetryableError
- PersistentRateLimitError
- RecoverableState
- RequestHandlerError
- RequestManagerTandem
- RequestThrottledError
- RequestValidationError
- RetryRequestError
- Router
- ServiceConflictError
- ServiceLocator
- SessionError
- SitemapRequestLoader
- SnapshotStore
- StateValidationError
- StorageInstanceManager
- StorageStatsTracker
- StorageTransaction
- AddRequestsBatchedOptions
- AddRequestsBatchedResult
- CalculatedStatistics
- ConcurrencySystemOptions
- ConfigField
- ContextMiddleware
- CpuLoadSignalOptions
- CrawleeLogger
- CrawleeLoggerOptions
- CrawlingContext
- CreateSession
- DatasetConsumer
- DatasetContent
- DatasetDataOptions
- DatasetExportOptions
- DatasetExportToOptions
- DatasetIteratorOptions
- DatasetJournalEntry
- DatasetMapper
- DatasetOptions
- DatasetReducer
- DatasetStats
- DefaultStorageIdentifier
- EnqueueUrlsOptions
- ErrnoException
- ErrorTrackerOptions
- EventLoopLoadSignalOptions
- EventManagerOptions
- EventStatusMessageData
- ExtractLinksOptions
- FinalStatistics
- GlobObject
- IRequestLoader
- IRequestManager
- IStorage
- JournaledRequest
- KeyConsumer
- KeyValueStoreIteratorOptions
- KeyValueStoreJournalEntry
- KeyValueStoreOptions
- KeyValueStoreRawRecord
- KeyValueStoreStats
- LoadSignal
- LoadSignalInfo
- LoadSignalsOptions
- LoadSignalStartContext
- LoadSnapshot
- LocalEventManagerOptions
- LoggerOptions
- MemoryLoadSignalOptions
- MemoryStorageOptions
- PersistenceOptions
- ProxyConfigurationFunction
- ProxyConfigurationOptions
- PushErrorMessageOptions
- RecordOptions
- RecoverableStateOptions
- RecoverableStatePersistenceOptions
- RegExpObject
- RequestListOptions
- RequestListState
- RequestOptions
- RequestQueueJournalEntry
- RequestQueueOperationInfo
- RequestQueueOperationOptions
- RequestQueueOptions
- RequestQueueStats
- RequestTransform
- ResponseLike
- RestrictedCrawlingContext
- RouteOptions
- RouterHandler
- SchemaIssue
- SessionOptions
- SessionPoolOptions
- SitemapRequestLoaderOptions
- SnapshotResult
- StatisticPersistedState
- StatisticsOptions
- StatisticState
- StatisticStateExtensionOptions
- StorageBackend
- StorageBackendLoadSignalOptions
- StorageOpenOptions
- StorageTransactionOptions
- StorageTransactionView
- StorageWritePolicy
- SystemInfo
- TaskLoopOptions
- TaskLoopPredicates
- ThrottlingRequestManagerOptions
- UrlPatternObject
- UseStateOptions
- ConfigurationInput
- ConfigurationOptions
- DefaultRouteUserData
- EnqueueLinksOptions
- EnqueueStrategyOption
- EventTypeName
- ExplicitStorageIdentifier
- FieldsInput
- FieldsOutput
- GetUserDataFromRequest
- GlobInput
- JournalEntry
- LabeledSource
- LoadedRequest
- PacingScope
- PacingSignal
- RegExpInput
- RequestListSourcesFunction
- RequestLoaderStatus
- RequestManagerOpener
- RequestsLike
- RequestSourceStatus
- ResolvedConfigValues
- RouterHandlerContext
- RouterLabel
- RouterRoutes
- RouteSchemas
- RoutesFromSchemas
- SessionReuseStrategy
- SkippedRequestCallback
- SkippedRequestReason
- Source
- StateConversion
- StorageIdentifier
- StorageTransactionState
- StorageWriteMode
- SyncStateConversion
- TypedContextAddRequests
- TypedContextEnqueueLinks
- UrlPatternInput
- WithRequired
- BLOCKED_STATUS_CODES
- coerceBoolean
- coerceNumber
- crawleeConfigFields
- defaultRoute
- log
- MAX_POOL_SIZE
- PERSIST_STATE_KEY
- serviceLocator
- createStorageTransaction
- field
- parseRetryAfterHeader
- parseValue
- purgeDefaultStorages
- resolveStorageIdentifier
- serializeValue
- useState
- withDirectStorageAccess
- withStorageTransaction
Other
ConfigurationInput
ConfigurationOptions
Deprecated - Use ConfigurationInput instead.
DefaultRouteUserData
The userData type of the default route: inferred from the defaultRoute schema when the route map
carries one, otherwise the provided Fallback.
Type parameters
- Routes
- Fallback: Dictionary
EnqueueLinksOptions
The combined options accepted by a crawler context's enqueueLinks() helper: extractLinks() + enqueueUrls().
EnqueueStrategyOption
The strategy option accepted by ExtractLinksOptions and EnqueueUrlsOptions.
EventTypeName
ExplicitStorageIdentifier
A storage identifier where exactly one of id, name, or alias is specified.
Produced by resolveStorageIdentifier from ambiguous user input.
FieldsInput
Type parameters
- F: Record<string, ConfigField>
FieldsOutput
Type parameters
- F: Record<string, ConfigField>
GetUserDataFromRequest
Type parameters
- T
GlobInput
JournalEntry
LabeledSource
A request input (URL string, request-options object, or Request) whose userData is typed
according to its label, based on a router's route map.
When the route map is open (the default Record<string, ...>), this is just the regular loose
Source input. When the map declares concrete labels, providing a label requires the matching
userData shape and rejects labels not present in the map; unlabeled requests keep loose userData.
Type parameters
- Routes: Record<keyof Routes, Dictionary>
LoadedRequest
Type parameters
- R: Request
PacingScope
How much of the URL space a PacingSignal covers.
Open on purpose: 'hostname' and 'registrableDomain' are what Crawlee's own reporters send and what
ThrottlingRequestManager understands, but any string is accepted, so a pacer keyed on something
else can be reported to in its own vocabulary.
PacingSignal
Something said about the pace requests should go out at, reported to a request manager through IRequestManager.recordPacingSignal.
One shape rather than a method per channel: a pacing manager switches on reason, a wrapping one forwards the
value without knowing what is in it, and a new kind of signal costs the interface nothing. The url travels
inside the value because the crawl-wide variant has none. Nothing here names the mechanism a signal came
from - status codes, headers and robots.txt are the crawler's business - and every delay is in milliseconds.
Scope
A manager may apply a signal to a wider scope than it was given - a floor that holds for one host still holds when a whole site is paced by it - but never to a narrower one, which would leave some of the URLs the signal covers running unpaced. A manager that can only do the latter, or that does not recognise the scope at all, MUST throw rather than quietly under-apply it.
RegExpInput
RequestListSourcesFunction
Type declaration
Returns Promise<RequestListSource[]>
RequestLoaderStatus
Loaders never stall — only a manager that paces its own dispatch can.
RequestManagerOpener
Opens a request manager, matching the shape of storage open methods such as
RequestQueue.open.
ThrottlingRequestManager calls this once per configured domain, so every per-domain queue shares the concrete type and storage backend of the manager being wrapped.
Type parameters
Type declaration
Parameters
optionalidentifier: string | StorageIdentifier | null
optionaloptions: StorageOpenOptions
Returns Promise<T>
RequestsLike
RequestSourceStatus
A request source's own availability, in a single answer.
ready— the next IRequestLoader.fetchNextRequest is expected to hand something over.waiting— nothing to fetch right now, but the source is not done: requests are in progress, are being added in the background, or are held back untilreadyAt.stalled— the source holds requests it cannot make progress on. Only a manager that paces its own dispatch can reach this; see ThrottlingRequestManager.finished— everything has been handled.
ResolvedConfigValues
RouterHandlerContext
The crawling context received by a route handler, with request.userData narrowed to UserData, and
addRequests/enqueueLinks typed according to the router's route map (Routes) so that enqueuing a
request under a declared label requires the matching userData shape.
Type parameters
- Context
- UserData: Dictionary
- Routes: Record<keyof Routes, Dictionary>
RouterLabel
The set of labels accepted by Router.addHandler. When the router declares a concrete
route map (e.g. { PRODUCT: ...; CATEGORY: ... }), only those labels (plus symbols) are
allowed — unknown labels become a compile-time error. When the map is left open (the default
Record<string, ...>), any string or symbol label is accepted, preserving the original behaviour.
Type parameters
- Routes: Record<keyof Routes, Dictionary>
RouterRoutes
Type parameters
- Context
- Routes: Record<keyof Routes, Dictionary>
RouteSchemas
A map of request labels to a Standard Schema (Zod, Valibot, ArkType, …)
validating that label's request.userData. Pass it to Router.create or a createXRouter
factory to derive the per-label request.userData types and validate them at runtime. The optional
defaultRoute key registers a schema for requests handled by the default route.
RoutesFromSchemas
Derives a route map (label → userData type) from a RouteSchemas map by inferring each schema's
output type. Outputs that are not object-shaped fall back to a plain Dictionary. The
defaultRoute schema is kept under its symbol key so Router.addDefaultHandler can pick it
up; string labels (the ones Router.addHandler and the crawler-level typing accept) ignore it.
Type parameters
- Schemas: RouteSchemas
SessionReuseStrategy
SkippedRequestCallback
Type declaration
Parameters
args: { reason: SkippedRequestReason; request: Request }
reason: SkippedRequestReason
request: Request
Returns Awaitable<void>
SkippedRequestReason
Source
StateConversion
One direction of the conversion between the state model and its persisted form - either a plain function, or a Standard Schema whose validated output is the result.
A schema that fails to validate makes RecoverableState throw a StateValidationError. Zod
codecs work directly, as their validation is the decode direction; use (state) => codec.encode(state) for the
other one.
Type parameters
- TFrom
- TTo
StorageIdentifier
Identifies a storage by its ID, name, or alias. At most one may be provided.
{ id }— open a pre-existing storage by its unique ID.{ name }— open or create a globally named storage (persists across runs). The namedefaultis reserved: it resolves to the default storage, and is emptied on start along with it.{ alias }— open or create a run-scoped unnamed storage identified by this alias. The alias is used locally (e.g. as a directory name or cache key) but the storage itself has no persistent name. Use this for non-default unnamed storages. Like the default storage, an aliased one is emptied on start unlesspurgeOnStartis disabled.{}/ omitted — open the default storage.
StorageTransactionState
StorageWriteMode
Governs whether writes of a given storage type performed inside a StorageTransaction are
applied immediately (writeThrough) or recorded and replayed on commit (deferred).
SyncStateConversion
A StateConversion for a caller that cannot await one - Statistics, whose toJSON() is
synchronous, being the reason this exists.
Only the function arm can be narrowed here: a Standard Schema is free to validate asynchronously, so a schema that does is rejected when it runs rather than when it is passed.
Type parameters
- TFrom
- TTo
TypedContextAddRequests
The label-aware addRequests method signature exposed on a request handler's context when the crawler is
bound to a typed router. Mirrors RestrictedCrawlingContext.addRequests with typed sources.
Type parameters
- Routes: Record<keyof Routes, Dictionary>
Type declaration
Parameters
requestsLike: ReadonlyDeep<LabeledSource<Routes>[]>
optionaloptions: ReadonlyDeep<EnqueueUrlsOptions>
Returns Promise<AddRequestsBatchedResult>
TypedContextEnqueueLinks
Transforms a context's existing enqueueLinks method so that the label/userData in its options follow
the router's route map, while preserving everything else about the signature (argument optionality and
return type, which differ between crawler types).
Type parameters
- EnqueueLinks
- Routes: Record<keyof Routes, Dictionary>
UrlPatternInput
Unified URL pattern input — accepts glob strings, glob objects, RegExp instances, or regexp objects.
WithRequired
Type parameters
- T
- K: keyof T
constBLOCKED_STATUS_CODES
constcoerceBoolean
Zod preprocessor treating '0' and 'false' as falsy.
constcoerceNumber
constcrawleeConfigFields
Type declaration
availableMemoryRatio: ConfigField<ZodDefault<ZodPreprocess<ZodNumber>>>
chromeExecutablePath: ConfigField<ZodOptional<ZodString>>
containerized: ConfigField<ZodOptional<ZodPreprocess<ZodBoolean>>>
defaultBrowserPath: ConfigField<ZodOptional<ZodString>>
defaultDatasetId: ConfigField<ZodDefault<ZodString>>
defaultKeyValueStoreId: ConfigField<ZodDefault<ZodString>>
defaultRequestQueueId: ConfigField<ZodDefault<ZodString>>
disableBrowserSandbox: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean>>>
headless: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean>>>
inputKey: ConfigField<ZodDefault<ZodString>>
internalTimeoutMillis: ConfigField<ZodOptional<ZodPreprocess<ZodNumber>>>
Internal safety-net timeout for a single request, in milliseconds. When unset the crawler derives it from the request handler timeout (twice it, and never below 5 minutes).
logLevel: ConfigField<ZodOptional<ZodPreprocess<ZodEnum<typeof LogLevel>>>>
maxUsedCpuRatio: ConfigField<ZodDefault<ZodPreprocess<ZodNumber>>>
memoryMbytes: ConfigField<ZodOptional<ZodPreprocess<ZodNumber>>>
persistStateIntervalMillis: ConfigField<ZodDefault<ZodPreprocess<ZodNumber>>>
persistStorage: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean>>>
purgeOnStart: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean>>>
storageDir: ConfigField<ZodDefault<ZodString>>
systemInfoIntervalMillis: ConfigField<ZodDefault<ZodPreprocess<ZodNumber>>>
xvfb: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean>>>
constdefaultRoute
The key of the default route — the fallback handler registered via Router.addDefaultHandler.
Use it in a RouteSchemas map to register a schema that validates the userData of every request
that falls through to the default handler (i.e. whose label has no route of its own).