Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
refactor!: Improve statistics-related naming (#4109)
Jan Bucharc49371170f7a
diff --git a/docs/public-api/crawlee-core.api.md b/docs/public-api/crawlee-core.api.mdindex 881659a1e..44449fc40 100644--- a/docs/public-api/crawlee-core.api.md+++ b/docs/public-api/crawlee-core.api.md@@ -143,9 +143,9 @@ interface BrowserPage {export interface CalculatedStatistics {crawlerRuntimeMillis: number;requestAvgFailedDurationMillis: number;- requestAvgFinishedDurationMillis: number;+ requestAvgSucceededDurationMillis: number;requestsFailedPerMinute: number;- requestsFinishedPerMinute: number;+ requestsSucceededPerMinute: number;requestsTotal: number;requestTotalDurationMillis: number;}@@ -687,15 +687,15 @@ export interface FinalStatistics {// (undocumented)requestAvgFailedDurationMillis: number;// (undocumented)- requestAvgFinishedDurationMillis: number;+ requestAvgSucceededDurationMillis: number;// (undocumented)requestsFailed: number;// (undocumented)requestsFailedPerMinute: number;// (undocumented)- requestsFinished: number;+ requestsSucceeded: number;// (undocumented)- requestsFinishedPerMinute: number;+ requestsSucceededPerMinute: number;// (undocumented)requestsTotal: number;// (undocumented)@@ -772,16 +772,16 @@ export interface IRequestManager extends IRequestLoader {// @publicexport interface IStatistics<StateExtension extends object = {}> {calculate(): CalculatedStatistics;- discardJob(id: number | string): void;+ discardRequestRecord(id: number | string): void;readonly errorTracker: ErrorTracker;readonly errorTrackerRetry: ErrorTracker;- failJob(id: number | string, retryCount: number): void;- finishJob(id: number | string, retryCount: number): void;persistState?(): Promise<void>;+ recordRequestFailure(id: number | string, retryCount: number): void;+ recordRequestStart(id: number | string): void;+ recordRequestSuccess(id: number | string, retryCount: number): void;registerStatusCode(code: number): void;readonly requestRetryHistogram: number[];startCapturing(): Promise<void>;- startJob(id: number | string): void;readonly state: StatisticState & StateExtension;stopCapturing(): Promise<void>;}@@ -1851,7 +1851,7 @@ export class StateValidationError extends Error {}// @public-export interface StatisticPersistedState extends Omit<StatisticState, 'statsPersistedAt' | 'crawlerStartedAt' | 'crawlerFinishedAt' | 'requestMinDurationMillis' | 'requestsFailedPerMinute' | 'requestsFinishedPerMinute' | 'requestRetryHistogram' | 'instanceStart'> {+export interface StatisticPersistedState extends Omit<StatisticState, 'statsPersistedAt' | 'crawlerStartedAt' | 'crawlerFinishedAt' | 'requestMinDurationMillis' | 'requestsFailedPerMinute' | 'requestsSucceededPerMinute' | 'requestRetryHistogram' | 'instanceStart'> {// (undocumented)crawlerFinishedAt: string | null;crawlerLastStartTimestamp: number;@@ -1859,14 +1859,14 @@ export interface StatisticPersistedState extends Omit<StatisticState, 'statsPers// (undocumented)requestAvgFailedDurationMillis: number | null;// (undocumented)- requestAvgFinishedDurationMillis: number | null;+ requestAvgSucceededDurationMillis: number | null;// (undocumented)requestMinDurationMillis: number | null;requestRetryHistogram: (number | null)[];// (undocumented)requestsFailedPerMinute: number | null;// (undocumented)- requestsFinishedPerMinute: number | null;+ requestsSucceededPerMinute: number | null;// (undocumented)requestsTotal: number;// (undocumented)@@ -1928,17 +1928,17 @@ export interface StatisticState {// (undocumented)requestsFailedPerMinute: number;// (undocumented)- requestsFinished: number;+ requestsRetries: number;// (undocumented)- requestsFinishedPerMinute: number;+ requestsSucceeded: number;// (undocumented)- requestsRetries: number;+ requestsSucceededPerMinute: number;// (undocumented)requestsWithStatusCode: Record<string, number>;// (undocumented)requestTotalFailedDurationMillis: number;// (undocumented)- requestTotalFinishedDurationMillis: number;+ requestTotalSucceededDurationMillis: number;// (undocumented)retryErrors: Record<string, unknown>;// (undocumented)diff --git a/docs/upgrading/upgrading_v4.md b/docs/upgrading/upgrading_v4.mdindex 46bcd09ab..c2c760cc4 100644--- a/docs/upgrading/upgrading_v4.md+++ b/docs/upgrading/upgrading_v4.md@@ -55,6 +55,8 @@ The purely mechanical renames, collected in one place. Where a row links to a se| `(await enqueueLinks()).processedRequests` | `(await enqueueLinks()).addedRequests` ([details](#enqueuelinks-return-value-reshaped-addrequestsbatchedresult-instead-of-batchaddrequestsresult)) || `autoscaledPoolOptions` | `taskLoopOptions` ([narrowed](#autoscaledpooloptions-is-now-taskloopoptions-and-no-longer-carries-concurrency-config)) || `crawler.stats` | `crawler.statistics` ([retyped](#statisticsoptions-is-replaced-by-a-statistics-instance)) |+| `statistics.state.requestsFinished` (and the other `*Finished*` counters) | `requestsSucceeded` ([details](#finished-request-counters-are-renamed-to-succeeded)) |+| `statistics.startJob()` / `finishJob()` / `failJob()` / `discardJob()` | `recordRequestStart()` / `recordRequestSuccess()` / `recordRequestFailure()` / `discardRequestRecord()` ([details](#the-request-recording-methods-are-renamed)) || `browserPoolOptions` | `browserPool` + a `*BrowserPool()` factory ([details](#browserpooloptions-is-removed)) || `gotScraping` (from `@crawlee/utils`) | `GotScrapingHttpClient` (`@crawlee/got-scraping-client`) || `SDK_`-prefixed internal KVS keys | `CRAWLEE_`-prefixed ([details](#internal-kvs-keys-renamed)) |@@ -148,6 +150,17 @@ The crawler following options are removed:- `handleRequestTimeoutSecs` -> `requestHandlerTimeoutSecs`- `handleFailedRequestFunction` -> `failedRequestHandler`+### `*Finished*` request counters are renamed to `*Succeeded*`++A failed request is also finished, so counters that only ever counted the successful ones were misleading. The rename covers `StatisticState` (`crawler.statistics.state`), the `CalculatedStatistics` returned by `crawler.statistics.calculate()` - which is also what the periodic statistics log line reports - the `FinalStatistics` returned by `crawler.run()`, and the record persisted under `CRAWLEE_CRAWLER_STATISTICS_*`:++- `requestsFinished` -> `requestsSucceeded`+- `requestsFinishedPerMinute` -> `requestsSucceededPerMinute`+- `requestTotalFinishedDurationMillis` -> `requestTotalSucceededDurationMillis`+- `requestAvgFinishedDurationMillis` -> `requestAvgSucceededDurationMillis`++Tooling that reads the persisted record needs the same rename applied. `crawlerFinishedAt` is unchanged - the crawler really does finish.+### Crawler constructors no longer take a `Configuration` argumentThe crawler classes dropped the optional second `config?: Configuration` constructor parameter: `PlaywrightCrawler`, `PuppeteerCrawler`, and `AdaptivePlaywrightCrawler` (the same applies to the other crawlers, which never advertised it publicly). `AdaptivePlaywrightCrawler` additionally now extends `BasicCrawler` rather than `PlaywrightCrawler`. Pass a `Configuration` via the `configuration` option instead (see [Using per-crawler services](#using-per-crawler-services-recommended)).@@ -942,7 +955,7 @@ The change spans, among others:- **`RequestList`** — all `_`-prefixed helpers (`addFetchedRequests`, `addPersistedRequests`, `addRequest`, `addRequestsFromSources`, `ensureInProgress`, `ensureIsInitialized`, `ensureUniqueKeyValid`, `fetchRequestsFromUrl`, `getPersistedState`, `loadStateAndPersistedRequests`, `persistRequests`, `restoreState`)- **`RequestQueue`** — `proxyConfiguration`, `requestCache`, `requestSeenCache`, `queuePausedForMigration`, `inProgressRequestBatchCount`, `expectedRequestProcessingSecs`, `httpClient`, `events`, and the helpers `cacheRequest`, `fetchRequestsFromUrl`, `addFetchedRequests` (`id`, `name`, `backend`, `log` are now `readonly`)- **`ProxyConfiguration`** — `nextCustomUrlIndex`, `proxyUrls`, `newUrlFunction`, and the helpers `handleProxyUrlsList`, `callNewUrlFunction`, `throwCannotCombineCustomMethods`, `throwNoOptionsProvided` (the internal `log` field and `usedProxyUrls` map are removed; `isManInTheMiddle` is now `readonly`)-- **`Statistics`** — `saveRetryCountForJob`, `teardown`, `keyValueStore` (`errorTracker`, `errorTrackerRetry` are now `readonly`, and `state` / `requestRetryHistogram` are getters)+- **`Statistics`** — `saveRetryCountForRequest` (was `saveRetryCountForJob`), `teardown`, `keyValueStore` (`errorTracker`, `errorTrackerRetry` are now `readonly`, and `state` / `requestRetryHistogram` are getters)- **`SystemStatus`** — `isSystemIdle`- **`Router`** — the constructor is now `private`; use the static `Router.create()` factory- **`BaseHttpClient`** — `log` (subclasses receive it via the constructor `logger` option instead of reading `this.log`)@@ -1334,6 +1347,15 @@ Omit the option and the crawler builds its own default, exactly as before. A supThe option accepts the built-in `Statistics` or any object implementing the new `IStatistics` interface, so a fully custom statistics backend can be plugged in without subclassing. The crawler exposes it as `crawler.statistics` (renamed from `crawler.stats`) typed as `IStatistics`.+### The request-recording methods are renamed++A crawler processes requests, not jobs, so the four methods `IStatistics` exposes for recording them dropped the borrowed vocabulary. Signatures are unchanged, so a custom implementation only needs renaming:++- `startJob()` -> `recordRequestStart()`+- `finishJob()` -> `recordRequestSuccess()`+- `failJob()` -> `recordRequestFailure()`+- `discardJob()` -> `discardRequestRecord()`+### The `Statistics` persistence lifecycle is stricter`persistState()` and `resetStore()` no longer take `PersistenceOptions` — persistence is enabled or disabled once, in the constructor. `resetStore()` throws while the instance is capturing, where the next `PERSIST_STATE` event would write the record straight back; call it before `startCapturing()` or after `stopCapturing()`. And `reset()` only resets the counters — it no longer stops an ongoing capture, which `stopCapturing()` does.diff --git a/packages/basic-crawler/src/internals/basic-crawler.ts b/packages/basic-crawler/src/internals/basic-crawler.tsindex f0e729e30..b982c0d3a 100644--- a/packages/basic-crawler/src/internals/basic-crawler.ts+++ b/packages/basic-crawler/src/internals/basic-crawler.ts@@ -867,7 +867,7 @@ export class BasicCrawler<readonly #maxRequestsPerCrawl?: number;private get handledRequestsCount(): number {- return this.statistics.state.requestsFinished + this.statistics.state.requestsFailed;+ return this.statistics.state.requestsSucceeded + this.statistics.state.requestsFailed;}#statusMessageLoggingInterval: number;@@ -1239,8 +1239,9 @@ export class BasicCrawler<// Started here, rather than in `handleRequest`, so that a failure during context pipeline// initialization (e.g. a browser page timing out before the request handler ever runs) is- // still accounted for by `failJob` below - which is a no-op without a matching `startJob`.- this.statistics.startJob(request.id || request.uniqueKey);+ // still accounted for by `recordRequestFailure` below - which is a no-op without a+ // matching `recordRequestStart`.+ this.statistics.recordRequestStart(request.id || request.uniqueKey);const crawlingContext = { request } as { request: Request } & Partial<CrawlingContext>;try {@@ -1262,7 +1263,7 @@ export class BasicCrawler<// ContextPipelineInterruptedError means the request was intentionally skipped// (e.g., doesn't match enqueue strategy after redirect). Just return gracefully.if (error instanceof ContextPipelineInterruptedError) {- this.statistics.discardJob(request.id || request.uniqueKey);+ this.statistics.discardRequestRecord(request.id || request.uniqueKey);await this.timeoutAndRetry(async () => this.requestManager?.markRequestAsHandled(request),this.internalTimeoutMillis,@@ -1663,7 +1664,7 @@ export class BasicCrawler<message = `Experiencing problems, ${failedDelta} failed requests in the past ${this.#statusMessageLoggingInterval} seconds.`;} else {const total = await this.requestManager?.getTotalCount();- message = `Crawled ${this.statistics.state.requestsFinished}${total ? `/${total}` : ''} pages, ${+ message = `Crawled ${this.statistics.state.requestsSucceeded}${total ? `/${total}` : ''} pages, ${this.statistics.state.requestsFailed} failed requests, desired concurrency ${this.concurrencySystem?.desiredConcurrency ?? 0}.`;}@@ -1799,7 +1800,7 @@ export class BasicCrawler<const finalStats = this.statistics.calculate();stats = {- requestsFinished: this.statistics.state.requestsFinished,+ requestsSucceeded: this.statistics.state.requestsSucceeded,requestsFailed: this.statistics.state.requestsFailed,retryHistogram: this.statistics.requestRetryHistogram,...finalStats,@@ -1809,7 +1810,7 @@ export class BasicCrawler<// A crawl that did nothing while the manager holds only handled requests is a mistake whoever// handled them - this run, another crawler on the same queue, or a previous process. Starting// against handled requests is not: that is what resuming a crawl looks like.- if (stats.requestsFinished + stats.requestsFailed === 0) {+ if (stats.requestsSucceeded + stats.requestsFailed === 0) {// Never let the diagnostic itself break the run.const alreadyHandled = (await this.requestManager?.getHandledCount().catch(() => 0)) ?? 0;@@ -1852,8 +1853,8 @@ export class BasicCrawler<periodicLogger.stop();this.setStatusMessage(- `Finished! Total ${this.statistics.state.requestsFinished + this.statistics.state.requestsFailed} requests: ${- this.statistics.state.requestsFinished+ `Finished! Total ${this.statistics.state.requestsSucceeded + this.statistics.state.requestsFailed} requests: ${+ this.statistics.state.requestsSucceeded} succeeded, ${this.statistics.state.requestsFailed} failed.`,{ isStatusMessageTerminal: true, level: 'INFO' },);@@ -2680,7 +2681,7 @@ export class BasicCrawler<);isRequestLocked = false; // markRequestAsHandled succeeded and unlocked the request- this.statistics.finishJob(statisticsId, request.retryCount);+ this.statistics.recordRequestSuccess(statisticsId, request.retryCount);// reclaim session if request finishes successfullyrequest.state = RequestState.DONE;@@ -2897,7 +2898,7 @@ export class BasicCrawler<// or failed more than retryCount times and will not be retried anymore.// Mark the request as failed and do not retry.await source.markRequestAsHandled(request);- this.statistics.failJob(request.id || request.uniqueKey, request.retryCount);+ this.statistics.recordRequestFailure(request.id || request.uniqueKey, request.retryCount);await this.handleFailedRequestHandler(crawlingContext, error); // This function prints an error message.}diff --git a/packages/core/src/autoscaling/system_status.ts b/packages/core/src/autoscaling/system_status.tsindex 899326d6a..06173a6a7 100644--- a/packages/core/src/autoscaling/system_status.ts+++ b/packages/core/src/autoscaling/system_status.ts@@ -91,12 +91,12 @@ export interface LoadSignalInfo {}export interface FinalStatistics {- requestsFinished: number;+ requestsSucceeded: number;requestsFailed: number;retryHistogram: number[];requestAvgFailedDurationMillis: number;- requestAvgFinishedDurationMillis: number;- requestsFinishedPerMinute: number;+ requestAvgSucceededDurationMillis: number;+ requestsSucceededPerMinute: number;requestsFailedPerMinute: number;requestTotalDurationMillis: number;requestsTotal: number;diff --git a/packages/core/src/crawlers/statistics.ts b/packages/core/src/crawlers/statistics.tsindex f44d9e147..f620f7553 100644--- a/packages/core/src/crawlers/statistics.ts+++ b/packages/core/src/crawlers/statistics.ts@@ -11,17 +11,15 @@ import { ErrorTracker } from './error_tracker.js';/*** @ignore*/-class Job {+class RequestProcessingRecord {#lastRunAt: number | null = null;- #durationMillis?: number;run() {this.#lastRunAt = Date.now();}finish() {- this.#durationMillis = Date.now() - this.#lastRunAt!;- return this.#durationMillis;+ return Date.now() - this.#lastRunAt!;}}@@ -62,15 +60,15 @@ const errorTrackerConfig = {* validated by their own conversion on the way back, so the keys it does not know about are simply dropped here.*/const persistedStatisticState = z.object({- requestsFinished: z.number(),+ requestsSucceeded: z.number(),requestsFailed: z.number(),requestsRetries: z.number(),requestsFailedPerMinute: z.number().nullable(),- requestsFinishedPerMinute: z.number().nullable(),+ requestsSucceededPerMinute: z.number().nullable(),requestMinDurationMillis: z.number().nullable(),requestMaxDurationMillis: z.number(),requestTotalFailedDurationMillis: z.number(),- requestTotalFinishedDurationMillis: z.number(),+ requestTotalSucceededDurationMillis: z.number(),crawlerStartedAt: z.string().nullable(),crawlerFinishedAt: z.string().nullable(),statsPersistedAt: z.string(),@@ -81,7 +79,7 @@ const persistedStatisticState = z.object({requestRetryHistogram: z.array(z.number().nullable()),statsId: z.string(),requestAvgFailedDurationMillis: z.number().nullable(),- requestAvgFinishedDurationMillis: z.number().nullable(),+ requestAvgSucceededDurationMillis: z.number().nullable(),requestTotalDurationMillis: z.number(),requestsTotal: z.number(),requestsWithStatusCode: z.record(z.string(), z.number()),@@ -112,11 +110,11 @@ function buildStatisticStateCodec(statistics: {return z.codec(persistedStatisticState, z.custom<StatisticState>(), {decode: (record) => ({...statistics.defaultState(),- requestsFinished: record.requestsFinished,+ requestsSucceeded: record.requestsSucceeded,requestsFailed: record.requestsFailed,requestsRetries: record.requestsRetries,requestTotalFailedDurationMillis: record.requestTotalFailedDurationMillis,- requestTotalFinishedDurationMillis: record.requestTotalFinishedDurationMillis,+ requestTotalSucceededDurationMillis: record.requestTotalSucceededDurationMillis,// Restoring the `null` as-is would make every later `duration < min` comparison fail, leaving the// minimum `null` for the rest of the run.requestMinDurationMillis: record.requestMinDurationMillis ?? Infinity,@@ -133,15 +131,17 @@ function buildStatisticStateCodec(statistics: {Date.now() - (new Date(record.statsPersistedAt).getTime() - record.crawlerLastStartTimestamp),}),encode: (state) => {+ // The per-minute rates fall through into `counters` and are overwritten below by `calculate()`'s,+ // which are the ones the record carries.const { requestsWithStatusCode, errors, retryErrors, requestRetryHistogram, instanceStart, ...counters } =state;// Every rate and average `calculate()` derives is `Infinity` until the run is long enough, or until- // something has finished or failed, to divide by.+ // something has succeeded or failed, to divide by.const {requestAvgFailedDurationMillis,- requestAvgFinishedDurationMillis,+ requestAvgSucceededDurationMillis,requestsFailedPerMinute,- requestsFinishedPerMinute,+ requestsSucceededPerMinute,...aggregates} = statistics.calculate();@@ -158,9 +158,9 @@ function buildStatisticStateCodec(statistics: {statsId: statistics.statsId,...aggregates,requestAvgFailedDurationMillis: finiteOrNull(requestAvgFailedDurationMillis),- requestAvgFinishedDurationMillis: finiteOrNull(requestAvgFinishedDurationMillis),+ requestAvgSucceededDurationMillis: finiteOrNull(requestAvgSucceededDurationMillis),requestsFailedPerMinute: finiteOrNull(requestsFailedPerMinute),- requestsFinishedPerMinute: finiteOrNull(requestsFinishedPerMinute),+ requestsSucceededPerMinute: finiteOrNull(requestsSucceededPerMinute),requestsWithStatusCode,errors,retryErrors,@@ -204,20 +204,20 @@ export interface IStatistics<StateExtension extends object = {}> {/** The live statistics state the crawler reads for status messages and the final summary. */readonly state: StatisticState & StateExtension;- /** Retries histogram - index `i` holds the number of requests that finished after `i` retries. */+ /** Retries histogram - index `i` holds the number of requests that settled after `i` retries. */readonly requestRetryHistogram: number[];- /** Marks a request as started, so its duration can be measured on finish/fail. */- startJob(id: number | string): void;+ /** Marks a request as started, so its duration can be measured on success/failure. */+ recordRequestStart(id: number | string): void;- /** Marks a started request as finished, updating the finished counters and durations. */- finishJob(id: number | string, retryCount: number): void;+ /** Marks a started request as succeeded, updating the succeeded counters and durations. */+ recordRequestSuccess(id: number | string, retryCount: number): void;/** Marks a started request as failed, updating the failed counters and durations. */- failJob(id: number | string, retryCount: number): void;+ recordRequestFailure(id: number | string, retryCount: number): void;- /** Drops a started request without counting it as finished or failed (e.g. skipped by robots.txt). */- discardJob(id: number | string): void;+ /** Drops a started request without counting it as succeeded or failed (e.g. skipped by robots.txt). */+ discardRequestRecord(id: number | string): void;/** Increments the counter for the given HTTP status code. */registerStatusCode(code: number): void;@@ -243,19 +243,19 @@ export interface CalculatedStatistics {/** Mean duration of a failed request, in milliseconds; `Infinity` when nothing has failed. */requestAvgFailedDurationMillis: number;- /** Mean duration of a finished request, in milliseconds; `Infinity` when nothing has finished. */- requestAvgFinishedDurationMillis: number;+ /** Mean duration of a succeeded request, in milliseconds; `Infinity` when nothing has succeeded. */+ requestAvgSucceededDurationMillis: number;- /** Requests finished per minute over the run so far. */- requestsFinishedPerMinute: number;+ /** Requests succeeded per minute over the run so far. */+ requestsSucceededPerMinute: number;/** Requests failed per minute over the run so far. */requestsFailedPerMinute: number;- /** Combined duration of all finished and failed requests, in milliseconds. */+ /** Combined duration of all succeeded and failed requests, in milliseconds. */requestTotalDurationMillis: number;- /** Total number of settled requests (finished plus failed). */+ /** Total number of settled requests (succeeded plus failed). */requestsTotal: number;/** Wall-clock runtime since capturing started, in milliseconds. */@@ -307,7 +307,7 @@ export class Statistics<readonly #stateExtensionKeys: readonly (keyof StateExtension)[];#logIntervalMillis: number;#logMessage: string;- #requestsInProgress = new Map<number | string, Job>();+ #requestsInProgress = new Map<number | string, RequestProcessingRecord>();private readonly log: CrawleeLogger;#logInterval: unknown;@@ -447,15 +447,15 @@ export class Statistics</** The built-in half of {@apilink Statistics.defaultState}, before any custom fields are merged over it. */#builtInDefaultState(): StatisticState {return {- requestsFinished: 0,+ requestsSucceeded: 0,requestsFailed: 0,requestsRetries: 0,requestsFailedPerMinute: 0,- requestsFinishedPerMinute: 0,+ requestsSucceededPerMinute: 0,requestMinDurationMillis: Infinity,requestMaxDurationMillis: 0,requestTotalFailedDurationMillis: 0,- requestTotalFinishedDurationMillis: 0,+ requestTotalSucceededDurationMillis: 0,crawlerStartedAt: null,crawlerFinishedAt: null,statsPersistedAt: null,@@ -491,54 +491,44 @@ export class Statistics<this.state.requestsWithStatusCode[s]++;}- /**- * Starts a job- * @ignore- */- startJob(id: number | string) {- let job = this.#requestsInProgress.get(id);- if (!job) job = new Job();- job.run();- this.#requestsInProgress.set(id, job);+ /** @ignore */+ recordRequestStart(id: number | string) {+ let record = this.#requestsInProgress.get(id);+ if (!record) record = new RequestProcessingRecord();+ record.run();+ this.#requestsInProgress.set(id, record);}- /**- * Mark job as finished and sets the state- * @ignore- */- finishJob(id: number | string, retryCount: number) {- const job = this.#requestsInProgress.get(id);- if (!job) return;- const jobDurationMillis = job.finish();- this.state.requestsFinished++;- this.state.requestTotalFinishedDurationMillis += jobDurationMillis;- this.saveRetryCountForJob(retryCount);- if (jobDurationMillis < this.state.requestMinDurationMillis)- this.state.requestMinDurationMillis = jobDurationMillis;- if (jobDurationMillis > this.state.requestMaxDurationMillis)- this.state.requestMaxDurationMillis = jobDurationMillis;+ /** @ignore */+ recordRequestSuccess(id: number | string, retryCount: number) {+ const record = this.#requestsInProgress.get(id);+ if (!record) return;+ const durationMillis = record.finish();+ this.state.requestsSucceeded++;+ this.state.requestTotalSucceededDurationMillis += durationMillis;+ this.saveRetryCountForRequest(retryCount);+ if (durationMillis < this.state.requestMinDurationMillis) this.state.requestMinDurationMillis = durationMillis;+ if (durationMillis > this.state.requestMaxDurationMillis) this.state.requestMaxDurationMillis = durationMillis;this.#requestsInProgress.delete(id);}- /**- * Mark job as failed and sets the state- * @ignore- */- failJob(id: number | string, retryCount: number) {- const job = this.#requestsInProgress.get(id);- if (!job) return;- this.state.requestTotalFailedDurationMillis += job.finish();+ /** @ignore */+ recordRequestFailure(id: number | string, retryCount: number) {+ const record = this.#requestsInProgress.get(id);+ if (!record) return;+ this.state.requestTotalFailedDurationMillis += record.finish();this.state.requestsFailed++;- this.saveRetryCountForJob(retryCount);+ this.saveRetryCountForRequest(retryCount);this.#requestsInProgress.delete(id);}/**- * Discards a started job without affecting the finished/failed counters, e.g. when a request- * turns out to be skipped (robots.txt, enqueue strategy) after `startJob` was already called for it.+ * Discards a started request without affecting the succeeded/failed counters, e.g. when a request+ * turns out to be skipped (robots.txt, enqueue strategy) after `recordRequestStart` was already+ * called for it.* @ignore*/- discardJob(id: number | string) {+ discardRequestRecord(id: number | string) {this.#requestsInProgress.delete(id);}@@ -548,21 +538,21 @@ export class Statistics<calculate(): CalculatedStatistics {const {requestsFailed,- requestsFinished,+ requestsSucceeded,requestTotalFailedDurationMillis,- requestTotalFinishedDurationMillis,+ requestTotalSucceededDurationMillis,} = this.state;const totalMillis = Date.now() - this.state.instanceStart;const totalMinutes = totalMillis / 1000 / 60;return {requestAvgFailedDurationMillis: Math.round(requestTotalFailedDurationMillis / requestsFailed) || Infinity,- requestAvgFinishedDurationMillis:- Math.round(requestTotalFinishedDurationMillis / requestsFinished) || Infinity,- requestsFinishedPerMinute: Math.round(requestsFinished / totalMinutes) || 0,+ requestAvgSucceededDurationMillis:+ Math.round(requestTotalSucceededDurationMillis / requestsSucceeded) || Infinity,+ requestsSucceededPerMinute: Math.round(requestsSucceeded / totalMinutes) || 0,requestsFailedPerMinute: Math.floor(requestsFailed / totalMinutes) || 0,- requestTotalDurationMillis: requestTotalFinishedDurationMillis + requestTotalFailedDurationMillis,- requestsTotal: requestsFailed + requestsFinished,+ requestTotalDurationMillis: requestTotalSucceededDurationMillis + requestTotalFailedDurationMillis,+ requestsTotal: requestsFailed + requestsSucceeded,crawlerRuntimeMillis: totalMillis,};}@@ -604,7 +594,7 @@ export class Statistics<await this.#recoverableState.teardown();}- private saveRetryCountForJob(retryCount: number) {+ private saveRetryCountForRequest(retryCount: number) {if (retryCount > 0) this.state.requestsRetries++;this.requestRetryHistogram[retryCount] ??= 0;this.requestRetryHistogram[retryCount]++;@@ -864,7 +854,7 @@ export interface StatisticStateExtensionOptions<* Format of the persisted stats.** The `null`s are `Infinity` on the way out - JSON has no infinity, so a record written before anything- * finished or failed carries a `null` in its place.+ * succeeded or failed carries a `null` in its place.*/export interface StatisticPersistedState extends Omit<StatisticState,@@ -873,13 +863,13 @@ export interface StatisticPersistedState extends Omit<| 'crawlerFinishedAt'| 'requestMinDurationMillis'| 'requestsFailedPerMinute'- | 'requestsFinishedPerMinute'+ | 'requestsSucceededPerMinute'| 'requestRetryHistogram'| 'instanceStart'> {statsId: string;requestsFailedPerMinute: number | null;- requestsFinishedPerMinute: number | null;+ requestsSucceededPerMinute: number | null;/** ISO strings - the live state keeps these as `Date`s. */crawlerStartedAt: string | null;crawlerFinishedAt: string | null;@@ -888,7 +878,7 @@ export interface StatisticPersistedState extends Omit</** A retry count that no request ever reached leaves a `null` here. */requestRetryHistogram: (number | null)[];requestAvgFailedDurationMillis: number | null;- requestAvgFinishedDurationMillis: number | null;+ requestAvgSucceededDurationMillis: number | null;requestTotalDurationMillis: number;requestsTotal: number;/** {@apilink StatisticState.instanceStart} of the run that wrote the record. */@@ -899,15 +889,15 @@ export interface StatisticPersistedState extends Omit<* Contains the statistics state*/export interface StatisticState {- requestsFinished: number;+ requestsSucceeded: number;requestsFailed: number;requestsRetries: number;requestsFailedPerMinute: number;- requestsFinishedPerMinute: number;+ requestsSucceededPerMinute: number;requestMinDurationMillis: number;requestMaxDurationMillis: number;requestTotalFailedDurationMillis: number;- requestTotalFinishedDurationMillis: number;+ requestTotalSucceededDurationMillis: number;crawlerStartedAt: Date | string | null;crawlerFinishedAt: Date | string | null;crawlerRuntimeMillis: number;@@ -916,7 +906,7 @@ export interface StatisticState {retryErrors: Record<string, unknown>;requestsWithStatusCode: Record<string, number>;- /** Retries histogram - index `i` holds the number of requests that finished after `i` retries. */+ /** Retries histogram - index `i` holds the number of requests that settled after `i` retries. */requestRetryHistogram: number[];/**diff --git a/test/core/crawlers/basic_crawler.test.ts b/test/core/crawlers/basic_crawler.test.tsindex 6e4cca7c9..851c385b8 100644--- a/test/core/crawlers/basic_crawler.test.ts+++ b/test/core/crawlers/basic_crawler.test.ts@@ -2422,7 +2422,7 @@ describe('BasicCrawler', () => {await crawler.run();- expect(stats.state.requestsFinished).toBe(1);+ expect(stats.state.requestsSucceeded).toBe(1);});it('drives a foreign IStatistics implementation through the interface alone', async () => {@@ -2431,15 +2431,15 @@ describe('BasicCrawler', () => {const customStats: IStatistics = {errorTracker: new ErrorTracker(),errorTrackerRetry: new ErrorTracker(),- state: { requestsFinished: 0 } as IStatistics['state'],+ state: { requestsSucceeded: 0 } as IStatistics['state'],requestRetryHistogram: [],- startJob: () => calls.push('startJob'),- finishJob: () => {- customStats.state.requestsFinished += 1;- calls.push('finishJob');+ recordRequestStart: () => calls.push('recordRequestStart'),+ recordRequestSuccess: () => {+ customStats.state.requestsSucceeded += 1;+ calls.push('recordRequestSuccess');},- failJob: () => {},- discardJob: () => {},+ recordRequestFailure: () => {},+ discardRequestRecord: () => {},registerStatusCode: () => {},calculate: () => ({}) as CalculatedStatistics,startCapturing: async () => void calls.push('startCapturing'),@@ -2452,8 +2452,8 @@ describe('BasicCrawler', () => {await crawler.run([{ url: 'https://example.com' }]);- expect(calls).toEqual(['startCapturing', 'startJob', 'finishJob', 'stopCapturing']);- expect(customStats.state.requestsFinished).toBe(1);+ expect(calls).toEqual(['startCapturing', 'recordRequestStart', 'recordRequestSuccess', 'stopCapturing']);+ expect(customStats.state.requestsSucceeded).toBe(1);});it('exposes the custom state fields of a supplied instance on crawler.statistics', async () => {@@ -2490,7 +2490,7 @@ describe('BasicCrawler', () => {// Two runs, one request each - the injected instance keeps accumulating instead of being wiped.expect(resetSpy).not.toHaveBeenCalled();- expect(stats.state.requestsFinished).toBe(2);+ expect(stats.state.requestsSucceeded).toBe(2);const owningCrawler = new BasicCrawler({requestHandler: async () => {},@@ -2504,7 +2504,7 @@ describe('BasicCrawler', () => {// A crawler-owned default is wiped at the start of each run.expect(ownedResetSpy).toHaveBeenCalled();- expect(owningCrawler.statistics.state.requestsFinished).toBe(1);+ expect(owningCrawler.statistics.state.requestsSucceeded).toBe(1);});});@@ -2682,7 +2682,7 @@ describe('BasicCrawler', () => {requestHandler: async () => {},});- crawler.statistics.state.requestsFinished = 2;+ crawler.statistics.state.requestsSucceeded = 2;// Try to add 6 requests - should only add 3 due to limitconst requestsToAdd = [@@ -2715,7 +2715,7 @@ describe('BasicCrawler', () => {requestHandler: async () => {},});- crawler.statistics.state.requestsFinished = 1;+ crawler.statistics.state.requestsSucceeded = 1;// First call - should add 2 requests (2 more slots to go)await crawler.addRequests(['http://example.com/1', 'http://example.com/2']);@@ -2764,7 +2764,7 @@ describe('BasicCrawler', () => {requestHandler: async () => {},});- crawler.statistics.state.requestsFinished = 0;+ crawler.statistics.state.requestsSucceeded = 0;// Mock robots.txt checking to disallow some URLsvitest.spyOn(crawler as any, 'isAllowedBasedOnRobotsTxtFile').mockImplementation(async (url) => {@@ -3193,7 +3193,7 @@ describe('BasicCrawler', () => {return;}- crawler.statistics.state.requestsFinished = 2;+ crawler.statistics.state.requestsSucceeded = 2;await context.addRequests(requestsToAdd, { label: 'not-undefined' });},@@ -3447,7 +3447,7 @@ describe('BasicCrawler', () => {return;}- crawler.statistics.state.requestsFinished = 2;+ crawler.statistics.state.requestsSucceeded = 2;// e.g. `enqueueLinks({ urls, limit: config.limit })` where `config.limit` is not setawait context.addRequests(requestsToAdd, { limit: undefined, label: 'child' });@@ -3486,7 +3486,7 @@ describe('BasicCrawler', () => {return;}- crawler.statistics.state.requestsFinished = 2;+ crawler.statistics.state.requestsSucceeded = 2;await context.addRequests(requestsToAdd, { limit: 4, label: 'child' });},@@ -4035,8 +4035,8 @@ describe('BasicCrawler', () => {await crawlerA.run([{ url: `http://${HOSTNAME}:${port}` }]);await crawlerB.run([{ url: `http://${HOSTNAME}:${port}` }]);- expect(crawlerA.statistics.state.requestsFinished).toBe(1);- expect(crawlerB.statistics.state.requestsFinished).toBe(1);+ expect(crawlerA.statistics.state.requestsSucceeded).toBe(1);+ expect(crawlerB.statistics.state.requestsSucceeded).toBe(1);});});diff --git a/test/core/crawlers/playwright_crawler.test.ts b/test/core/crawlers/playwright_crawler.test.tsindex d22d02cf1..26938f83f 100644--- a/test/core/crawlers/playwright_crawler.test.ts+++ b/test/core/crawlers/playwright_crawler.test.ts@@ -163,7 +163,7 @@ describe('PlaywrightCrawler', () => {// Every request must be accounted for by either requestHandler or failedRequestHandler.expect(success.length + failure.length).toBe(urls.length);// With operationTimeoutSecs=0.001, no request can actually succeed, so every one must fail.- expect(stats.requestsFinished).toBe(0);+ expect(stats.requestsSucceeded).toBe(0);expect(stats.requestsFailed).toBe(urls.length);});diff --git a/test/core/crawlers/statistics.test.ts b/test/core/crawlers/statistics.test.tsindex b328b9623..cd90678ce 100644--- a/test/core/crawlers/statistics.test.ts+++ b/test/core/crawlers/statistics.test.ts@@ -5,8 +5,8 @@ import type { Dictionary } from '@crawlee/types';import { z } from 'zod';describe('Statistics', () => {- const getPerMinute = (jobCount: number, totalTickMillis: number) => {- return Math.round(jobCount / (totalTickMillis / 1000 / 60));+ const getPerMinute = (requestCount: number, totalTickMillis: number) => {+ return Math.round(requestCount / (totalTickMillis / 1000 / 60));};const persistStateKey = (statistics: Statistics) => `CRAWLEE_CRAWLER_STATISTICS_${statistics.id}`;@@ -48,9 +48,9 @@ describe('Statistics', () => {test('should persist the state to KV and load again', async () => {vitest.advanceTimersByTime(1000);- stats.startJob(0);+ stats.recordRequestStart(0);vitest.advanceTimersByTime(100);- stats.finishJob(0, 1);+ stats.recordRequestSuccess(0, 1);stats.registerStatusCode(200);await stats.startCapturing();@@ -61,9 +61,9 @@ describe('Statistics', () => {await restored.startCapturing();expect(restored.state).toMatchObject({- requestsFinished: 1,+ requestsSucceeded: 1,requestsRetries: 1,- requestTotalFinishedDurationMillis: 100,+ requestTotalSucceededDurationMillis: 100,requestMinDurationMillis: 100,requestMaxDurationMillis: 100,crawlerStartedAt: stats.state.crawlerStartedAt,@@ -90,9 +90,9 @@ describe('Statistics', () => {expect(restored.state.requestMinDurationMillis).toEqual(Infinity);// The whole point of the minimum - a `duration < null` comparison would never win.- restored.startJob(0);+ restored.recordRequestStart(0);vitest.advanceTimersByTime(100);- restored.finishJob(0, 0);+ restored.recordRequestSuccess(0, 0);expect(restored.state.requestMinDurationMillis).toEqual(100);await restored.stopCapturing();@@ -100,13 +100,13 @@ describe('Statistics', () => {test('should start from scratch on a record it cannot make sense of', async () => {await stats.startCapturing();- stats.startJob(0);+ stats.recordRequestStart(0);vitest.advanceTimersByTime(100);- stats.finishJob(0, 0);+ stats.recordRequestSuccess(0, 0);await stats.stopCapturing();const record = (await store.getValue<StatisticPersistedState>(persistStateKey(stats)))!;- await store.setValue(persistStateKey(stats), { ...record, requestsFinished: 'plenty' });+ await store.setValue(persistStateKey(stats), { ...record, requestsSucceeded: 'plenty' });const restored = new Statistics({ id: stats.id });// @ts-expect-error Accessing private prop@@ -120,8 +120,8 @@ describe('Statistics', () => {expect.stringContaining('starting the statistics from scratch'),expect.objectContaining({ persistStateKey: persistStateKey(stats) }),);- expect(restored.state.requestsFinished).toEqual(0);- expect(restored.state.requestTotalFinishedDurationMillis).toEqual(0);+ expect(restored.state.requestsSucceeded).toEqual(0);+ expect(restored.state.requestTotalSucceededDurationMillis).toEqual(0);await restored.stopCapturing();});@@ -129,18 +129,18 @@ describe('Statistics', () => {test('should write the record when the run is too short to have a rate', async () => {// Everything inside one millisecond: `calculate()` divides by a zero-length run and reports the// per-minute rates as `Infinity`, which the record can only carry as `null`.- stats.startJob(0);- stats.finishJob(0, 0);- stats.startJob(1);- stats.failJob(1, 0);+ stats.recordRequestStart(0);+ stats.recordRequestSuccess(0, 0);+ stats.recordRequestStart(1);+ stats.recordRequestFailure(1, 0);await stats.startCapturing();await stats.persistState();expect(await store.getValue<StatisticPersistedState>(persistStateKey(stats))).toMatchObject({- requestsFinished: 1,+ requestsSucceeded: 1,requestsFailed: 1,- requestsFinishedPerMinute: null,+ requestsSucceededPerMinute: null,requestsFailedPerMinute: null,});@@ -148,9 +148,9 @@ describe('Statistics', () => {});test('should keep the shape of the persisted record', async () => {- stats.startJob(0);+ stats.recordRequestStart(0);vitest.advanceTimersByTime(100);- stats.finishJob(0, 0);+ stats.recordRequestSuccess(0, 0);stats.registerStatusCode(200);await stats.startCapturing();@@ -159,15 +159,15 @@ describe('Statistics', () => {const record = (await store.getValue<StatisticPersistedState>(persistStateKey(stats)))!;expect(record).toEqual({- requestsFinished: 1,+ requestsSucceeded: 1,requestsFailed: 0,requestsRetries: 0,requestsFailedPerMinute: 0,- requestsFinishedPerMinute: 600,+ requestsSucceededPerMinute: 600,requestMinDurationMillis: 100,requestMaxDurationMillis: 100,requestTotalFailedDurationMillis: 0,- requestTotalFinishedDurationMillis: 100,+ requestTotalSucceededDurationMillis: 100,crawlerStartedAt: '1970-01-01T00:00:00.100Z',crawlerFinishedAt: null,statsPersistedAt: '1970-01-01T00:00:00.100Z',@@ -176,7 +176,7 @@ describe('Statistics', () => {requestRetryHistogram: [1],statsId: stats.id,requestAvgFailedDurationMillis: null,- requestAvgFinishedDurationMillis: 100,+ requestAvgSucceededDurationMillis: 100,requestTotalDurationMillis: 100,requestsTotal: 1,requestsWithStatusCode: { 200: 1 },@@ -186,15 +186,15 @@ describe('Statistics', () => {// The record is read by tooling outside Crawlee - the key order is part of its shape.expect(Object.keys(record)).toEqual([- 'requestsFinished',+ 'requestsSucceeded','requestsFailed','requestsRetries','requestsFailedPerMinute',- 'requestsFinishedPerMinute',+ 'requestsSucceededPerMinute','requestMinDurationMillis','requestMaxDurationMillis','requestTotalFailedDurationMillis',- 'requestTotalFinishedDurationMillis',+ 'requestTotalSucceededDurationMillis','crawlerStartedAt','crawlerFinishedAt','statsPersistedAt',@@ -203,7 +203,7 @@ describe('Statistics', () => {'requestRetryHistogram','statsId','requestAvgFailedDurationMillis',- 'requestAvgFinishedDurationMillis',+ 'requestAvgSucceededDurationMillis','requestTotalDurationMillis','requestsTotal','requestsWithStatusCode',@@ -229,9 +229,9 @@ describe('Statistics', () => {});test('on persistState event', async () => {- stats.startJob(0);+ stats.recordRequestStart(0);vitest.advanceTimersByTime(100);- stats.finishJob(0, 0);+ stats.recordRequestSuccess(0, 0);await stats.startCapturing();@@ -248,9 +248,9 @@ describe('Statistics', () => {test('an explicit id restores state across instances under a stable key', async () => {const stats1 = new Statistics({ id: 'shared-stats' });- stats1.startJob(0);+ stats1.recordRequestStart(0);vitest.advanceTimersByTime(100);- stats1.finishJob(0, 0);+ stats1.recordRequestSuccess(0, 0);await stats1.startCapturing();await stats1.persistState();@@ -259,94 +259,94 @@ describe('Statistics', () => {const stats2 = new Statistics({ id: 'shared-stats' });await stats2.startCapturing();- expect(stats2.state.requestsFinished).toEqual(1);+ expect(stats2.state.requestsSucceeded).toEqual(1);await stats2.stopCapturing();});});- test('should finish a job', () => {- stats.startJob(0);+ test('should record a successful request', () => {+ stats.recordRequestStart(0);vitest.advanceTimersByTime(1);- stats.finishJob(0, 0);+ stats.recordRequestSuccess(0, 0);vitest.advanceTimersByTime(1);const current = stats.calculate();expect(current).toEqual({crawlerRuntimeMillis: 2,requestAvgFailedDurationMillis: Infinity,- requestAvgFinishedDurationMillis: 1,+ requestAvgSucceededDurationMillis: 1,requestTotalDurationMillis: 1,requestsFailedPerMinute: 0,- requestsFinishedPerMinute: getPerMinute(1, 2),+ requestsSucceededPerMinute: getPerMinute(1, 2),requestsTotal: 1,});});- test('should fail a job', () => {- stats.startJob(0);+ test('should record a failed request', () => {+ stats.recordRequestStart(0);vitest.advanceTimersByTime(0);- stats.failJob(0, 0);+ stats.recordRequestFailure(0, 0);vitest.advanceTimersByTime(1);const current = stats.calculate();expect(current).toEqual({crawlerRuntimeMillis: 1,requestAvgFailedDurationMillis: Infinity,- requestAvgFinishedDurationMillis: Infinity,+ requestAvgSucceededDurationMillis: Infinity,requestTotalDurationMillis: 0,requestsFailedPerMinute: 60000,- requestsFinishedPerMinute: 0,+ requestsSucceededPerMinute: 0,requestsTotal: 1,});expect(stats.requestRetryHistogram).toEqual([1]);});test('should collect retries', () => {- stats.startJob(0);- stats.startJob(1);- stats.startJob(2);- stats.finishJob(0, 0);- stats.finishJob(1, 1);- stats.finishJob(2, 2);+ stats.recordRequestStart(0);+ stats.recordRequestStart(1);+ stats.recordRequestStart(2);+ stats.recordRequestSuccess(0, 0);+ stats.recordRequestSuccess(1, 1);+ stats.recordRequestSuccess(2, 2);const current = stats.calculate();expect(current).toEqual({crawlerRuntimeMillis: 0,requestAvgFailedDurationMillis: Infinity,- requestAvgFinishedDurationMillis: Infinity,+ requestAvgSucceededDurationMillis: Infinity,requestTotalDurationMillis: 0,requestsFailedPerMinute: 0,- requestsFinishedPerMinute: Infinity,+ requestsSucceededPerMinute: Infinity,requestsTotal: 3,});expect(stats.requestRetryHistogram).toEqual([1, 1, 1]);});- test('should return correct stats for multiple parallel jobs', () => {- stats.startJob(0);+ test('should return correct stats for multiple parallel requests', () => {+ stats.recordRequestStart(0);vitest.advanceTimersByTime(1);- stats.startJob(1);+ stats.recordRequestStart(1);vitest.advanceTimersByTime(1);- stats.startJob(2);+ stats.recordRequestStart(2);vitest.advanceTimersByTime(2);- stats.finishJob(1, 0); // runtime: 3ms+ stats.recordRequestSuccess(1, 0); // runtime: 3msvitest.advanceTimersByTime(1); // since startedAt: 5ms- stats.failJob(0, 0); // runtime: irrelevant+ stats.recordRequestFailure(0, 0); // runtime: irrelevantvitest.advanceTimersByTime(10);- stats.finishJob(2, 0); // runtime: 13ms+ stats.recordRequestSuccess(2, 0); // runtime: 13msvitest.advanceTimersByTime(10); // since startedAt: 25msconst current = stats.calculate();expect(current).toEqual({crawlerRuntimeMillis: 25,requestAvgFailedDurationMillis: 5,- requestAvgFinishedDurationMillis: (13 + 3) / 2,+ requestAvgSucceededDurationMillis: (13 + 3) / 2,requestTotalDurationMillis: 21,requestsFailedPerMinute: 2400,- requestsFinishedPerMinute: getPerMinute(2, 25),+ requestsSucceededPerMinute: getPerMinute(2, 25),requestsTotal: 3,});expect(stats.state).toMatchObject({requestsFailed: 1,- requestsFinished: 2,+ requestsSucceeded: 2,});expect(stats.requestRetryHistogram).toEqual([3]);});@@ -359,9 +359,9 @@ describe('Statistics', () => {logged.push([message, data]);});- stats.startJob(0);+ stats.recordRequestStart(0);vitest.advanceTimersByTime(1);- stats.finishJob(0, 0);+ stats.recordRequestSuccess(0, 0);await stats.startCapturing();vitest.advanceTimersByTime(50000);expect(logged).toHaveLength(0);@@ -371,10 +371,10 @@ describe('Statistics', () => {expect(logged[0][1]).toEqual({crawlerRuntimeMillis: 60001,requestAvgFailedDurationMillis: Infinity,- requestAvgFinishedDurationMillis: 1,+ requestAvgSucceededDurationMillis: 1,requestTotalDurationMillis: 1,requestsFailedPerMinute: 0,- requestsFinishedPerMinute: 1,+ requestsSucceededPerMinute: 1,requestsTotal: 1,retryHistogram: [1],});@@ -385,10 +385,10 @@ describe('Statistics', () => {expect(logged[0][1]).toEqual({crawlerRuntimeMillis: 60001,requestAvgFailedDurationMillis: Infinity,- requestAvgFinishedDurationMillis: 1,+ requestAvgSucceededDurationMillis: 1,requestTotalDurationMillis: 1,requestsFailedPerMinute: 0,- requestsFinishedPerMinute: 1,+ requestsSucceededPerMinute: 1,requestsTotal: 1,retryHistogram: [1],});@@ -396,13 +396,13 @@ describe('Statistics', () => {test('should reset stats', async () => {await stats.startCapturing();- stats.startJob(1);+ stats.recordRequestStart(1);vitest.advanceTimersByTime(3);- stats.finishJob(1, 0);- expect(stats.state.requestsFinished).toEqual(1);+ stats.recordRequestSuccess(1, 0);+ expect(stats.state.requestsSucceeded).toEqual(1);expect(stats.requestRetryHistogram).toEqual([1]);stats.reset();- expect(stats.state.requestsFinished).toEqual(0);+ expect(stats.state.requestsSucceeded).toEqual(0);expect(stats.requestRetryHistogram).toEqual([]);// Resetting the counters does not end the capture - stopCapturing() is what does.@@ -427,8 +427,8 @@ describe('Statistics', () => {const stats = new Statistics({ id, stateExtension: { defaultState: { productsFound: 0 } } });await stats.startCapturing();- stats.startJob(0);- stats.finishJob(0, 0);+ stats.recordRequestStart(0);+ stats.recordRequestSuccess(0, 0);stats.state.productsFound = 7;await stats.stopCapturing();};@@ -474,8 +474,8 @@ describe('Statistics', () => {});test('should reject a custom field that collides with a built-in one', () => {- expect(() => new Statistics({ stateExtension: { defaultState: { requestsFinished: 999 } } })).toThrow(- /`requestsFinished` collides with a built-in one/,+ expect(() => new Statistics({ stateExtension: { defaultState: { requestsSucceeded: 999 } } })).toThrow(+ /`requestsSucceeded` collides with a built-in one/,);});@@ -544,7 +544,7 @@ describe('Statistics', () => {);// the custom field lost its value, the crawler's own counters did notexpect(stats.state.productsFound).toEqual(0);- expect(stats.state.requestsFinished).toEqual(1);+ expect(stats.state.requestsSucceeded).toEqual(1);await stats.stopCapturing();});@@ -592,9 +592,9 @@ describe('Statistics', () => {describe('explicit id option', () => {test('statistics with same explicit id should share persisted state', async () => {const stats1 = new Statistics({ id: 'shared-stats' });- stats1.startJob(0);+ stats1.recordRequestStart(0);vitest.advanceTimersByTime(100);- stats1.finishJob(0, 0);+ stats1.recordRequestSuccess(0, 0);await stats1.startCapturing();await stats1.persistState();@@ -603,16 +603,16 @@ describe('Statistics', () => {const stats2 = new Statistics({ id: 'shared-stats' });await stats2.startCapturing();- expect(stats2.state.requestsFinished).toEqual(1);+ expect(stats2.state.requestsSucceeded).toEqual(1);await stats2.stopCapturing();});test('statistics with different explicit ids should have isolated state', async () => {const statsA = new Statistics({ id: 'stats-a' });- statsA.startJob(0);+ statsA.recordRequestStart(0);vitest.advanceTimersByTime(100);- statsA.finishJob(0, 0);+ statsA.recordRequestSuccess(0, 0);await statsA.startCapturing();await statsA.persistState();@@ -621,7 +621,7 @@ describe('Statistics', () => {const statsB = new Statistics({ id: 'stats-b' });await statsB.startCapturing();- expect(statsB.state.requestsFinished).toEqual(0);+ expect(statsB.state.requestsSucceeded).toEqual(0);await statsB.stopCapturing();});diff --git a/test/e2e/adaptive-playwright-robots-file/test.mjs b/test/e2e/adaptive-playwright-robots-file/test.mjsindex 5e7a2c4df..ae181f39d 100644--- a/test/e2e/adaptive-playwright-robots-file/test.mjs+++ b/test/e2e/adaptive-playwright-robots-file/test.mjs@@ -6,7 +6,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);// Without this the two assertions below hold vacuously when the crawl never starts.-await expect(stats.requestsFinished >= 1, 'All requests finished');+await expect(stats.requestsSucceeded >= 1, 'All requests finished');const paths = datasetItems.map((item) => new URL(item.url).pathname);diff --git a/test/e2e/autoscaling-max-tasks-per-minute/test.mjs b/test/e2e/autoscaling-max-tasks-per-minute/test.mjsindex 1b1182c0c..7831fb294 100644--- a/test/e2e/autoscaling-max-tasks-per-minute/test.mjs+++ b/test/e2e/autoscaling-max-tasks-per-minute/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats } = await runActor(testActorDirname);-await expect(stats.requestsFinished === 2, 'All requests finished');+await expect(stats.requestsSucceeded === 2, 'All requests finished');await expect(stats.crawlerRuntimeMillis > 60_000 && stats.crawlerRuntimeMillis < 70_000,`Ran one task per minute, took ~1 minute to complete, but no more than that (${stats.crawlerRuntimeMillis}ms)`,diff --git a/test/e2e/cheerio-curl-impersonate-ts/test.mjs b/test/e2e/cheerio-curl-impersonate-ts/test.mjsindex ecc0b9d90..c5bbb9a80 100644--- a/test/e2e/cheerio-curl-impersonate-ts/test.mjs+++ b/test/e2e/cheerio-curl-impersonate-ts/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 0, 'All requests finished');+await expect(stats.requestsSucceeded > 0, 'All requests finished');await expect(datasetItems.length === 1, 'A dataset item was pushed');const result = datasetItems[0];diff --git a/test/e2e/cheerio-default-ts/test.mjs b/test/e2e/cheerio-default-ts/test.mjsindex b843e87e9..7de081929 100644--- a/test/e2e/cheerio-default-ts/test.mjs+++ b/test/e2e/cheerio-default-ts/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 40, 'All requests finished');+await expect(stats.requestsSucceeded > 40, 'All requests finished');await expect(datasetItems.length > 40, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');diff --git a/test/e2e/cheerio-default/test.mjs b/test/e2e/cheerio-default/test.mjsindex b843e87e9..7de081929 100644--- a/test/e2e/cheerio-default/test.mjs+++ b/test/e2e/cheerio-default/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 40, 'All requests finished');+await expect(stats.requestsSucceeded > 40, 'All requests finished');await expect(datasetItems.length > 40, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');diff --git a/test/e2e/cheerio-ignore-ssl-errors/test.mjs b/test/e2e/cheerio-ignore-ssl-errors/test.mjsindex 2325ccba2..9a5a176ef 100644--- a/test/e2e/cheerio-ignore-ssl-errors/test.mjs+++ b/test/e2e/cheerio-ignore-ssl-errors/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 20, 'All requests finished');+await expect(stats.requestsSucceeded > 20, 'All requests finished');await expect(datasetItems.length > 20, 'Minimum number of dataset items');await expect(validateDataset(datasetItems, ['url', 'title']), 'Dataset items validation');diff --git a/test/e2e/cheerio-impit-ts/test.mjs b/test/e2e/cheerio-impit-ts/test.mjsindex 218055485..af9af30c1 100644--- a/test/e2e/cheerio-impit-ts/test.mjs+++ b/test/e2e/cheerio-impit-ts/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 0, 'All requests finished');+await expect(stats.requestsSucceeded > 0, 'All requests finished');await expect(datasetItems.length === 1, 'A dataset item was pushed');const result = datasetItems[0];diff --git a/test/e2e/cheerio-initial-cookies/test.mjs b/test/e2e/cheerio-initial-cookies/test.mjsindex 760a89858..845553bbf 100644--- a/test/e2e/cheerio-initial-cookies/test.mjs+++ b/test/e2e/cheerio-initial-cookies/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished === 1, 'All requests finished');+await expect(stats.requestsSucceeded === 1, 'All requests finished');await expect(datasetItems[0].numberOfMatchingCookies === 3, 'Number of page cookies');await expect(datasetItems[0].numberOfMatchingCookies === datasetItems[0].initialCookiesLength,diff --git a/test/e2e/cheerio-max-requests/test.mjs b/test/e2e/cheerio-max-requests/test.mjsindex f3b80998f..a185e243b 100644--- a/test/e2e/cheerio-max-requests/test.mjs+++ b/test/e2e/cheerio-max-requests/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished >= 10, 'All requests finished');+await expect(stats.requestsSucceeded >= 10, 'All requests finished');await expect(datasetItems.length > 5 && datasetItems.length < 15, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'title', 'uniqueIdentifier', 'firstParagraph', 'modifiedDate']),diff --git a/test/e2e/cheerio-page-info/test.mjs b/test/e2e/cheerio-page-info/test.mjsindex db70e11af..cdc55dc97 100644--- a/test/e2e/cheerio-page-info/test.mjs+++ b/test/e2e/cheerio-page-info/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished === 2, 'All requests finished');+await expect(stats.requestsSucceeded === 2, 'All requests finished');await expect(datasetItems.length === 1, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'title', 'uniqueIdentifier', 'firstParagraph', 'modifiedDate']),diff --git a/test/e2e/cheerio-request-queue-v2/test.mjs b/test/e2e/cheerio-request-queue-v2/test.mjsindex b843e87e9..7de081929 100644--- a/test/e2e/cheerio-request-queue-v2/test.mjs+++ b/test/e2e/cheerio-request-queue-v2/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 40, 'All requests finished');+await expect(stats.requestsSucceeded > 40, 'All requests finished');await expect(datasetItems.length > 40, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');diff --git a/test/e2e/cheerio-robots-file/test.mjs b/test/e2e/cheerio-robots-file/test.mjsindex df7072351..cdf29f787 100644--- a/test/e2e/cheerio-robots-file/test.mjs+++ b/test/e2e/cheerio-robots-file/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished >= 1, 'All requests finished');+await expect(stats.requestsSucceeded >= 1, 'All requests finished');const paths = datasetItems.map((item) => new URL(item.url).pathname);diff --git a/test/e2e/cheerio-stop-resume-ts/test.mjs b/test/e2e/cheerio-stop-resume-ts/test.mjsindex 6611a0a47..b9f43221d 100644--- a/test/e2e/cheerio-stop-resume-ts/test.mjs+++ b/test/e2e/cheerio-stop-resume-ts/test.mjs@@ -6,7 +6,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);/// Some extra requests are expected (at most 10 extra for each run).-await expect(stats.requestsFinished < 40, 'crawler.stop() works');+await expect(stats.requestsSucceeded < 40, 'crawler.stop() works');const visitedUrls = new Set(datasetItems.map((x) => x.url));await expect(visitedUrls.size === datasetItems.length, 'a second crawler.run() resumes the same queue');diff --git a/test/e2e/cheerio-throw-on-ssl-errors/test.mjs b/test/e2e/cheerio-throw-on-ssl-errors/test.mjsindex dcb3d14d9..32f2312f8 100644--- a/test/e2e/cheerio-throw-on-ssl-errors/test.mjs+++ b/test/e2e/cheerio-throw-on-ssl-errors/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 5 && stats.requestsFinished < 10, 'All requests finished');+await expect(stats.requestsSucceeded > 5 && stats.requestsSucceeded < 10, 'All requests finished');await expect(stats.requestsFailed > 20 && stats.requestsFailed < 30, 'Number of failed requests');await expect(datasetItems.length >= 5 && datasetItems.length < 10, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'title']), 'Dataset items validation');diff --git a/test/e2e/jsdom-default-ts/test.mjs b/test/e2e/jsdom-default-ts/test.mjsindex b843e87e9..7de081929 100644--- a/test/e2e/jsdom-default-ts/test.mjs+++ b/test/e2e/jsdom-default-ts/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 40, 'All requests finished');+await expect(stats.requestsSucceeded > 40, 'All requests finished');await expect(datasetItems.length > 40, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');diff --git a/test/e2e/jsdom-react-ts/test.mjs b/test/e2e/jsdom-react-ts/test.mjsindex 69c265224..3917fa1bb 100644--- a/test/e2e/jsdom-react-ts/test.mjs+++ b/test/e2e/jsdom-react-ts/test.mjs@@ -7,7 +7,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished === 1, 'All requests finished');+await expect(stats.requestsSucceeded === 1, 'All requests finished');await expect(datasetItems.length === 1, 'Number of dataset items');await expect(validateDataset(datasetItems, ['result']), 'Dataset items validation');await expect(datasetItems[0].result, 'Dataset items');diff --git a/test/e2e/linkedom-default-ts/test.mjs b/test/e2e/linkedom-default-ts/test.mjsindex b843e87e9..7de081929 100644--- a/test/e2e/linkedom-default-ts/test.mjs+++ b/test/e2e/linkedom-default-ts/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname);-await expect(stats.requestsFinished > 40, 'All requests finished');+await expect(stats.requestsSucceeded > 40, 'All requests finished');await expect(datasetItems.length > 40, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');diff --git a/test/e2e/playwright-default/test.mjs b/test/e2e/playwright-default/test.mjsindex 9aa375ea5..a31ab4059 100644--- a/test/e2e/playwright-default/test.mjs+++ b/test/e2e/playwright-default/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished > 15, 'All requests finished');+await expect(stats.requestsSucceeded > 15, 'All requests finished');await expect(datasetItems.length > 15 && datasetItems.length < 30, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');diff --git a/test/e2e/playwright-initial-cookies/test.mjs b/test/e2e/playwright-initial-cookies/test.mjsindex 012966452..32ebb53f5 100644--- a/test/e2e/playwright-initial-cookies/test.mjs+++ b/test/e2e/playwright-initial-cookies/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished === 1, 'All requests finished');+await expect(stats.requestsSucceeded === 1, 'All requests finished');await expect(datasetItems[0].numberOfMatchingCookies === 3, 'Number of page cookies');await expect(datasetItems[0].numberOfMatchingCookies === datasetItems[0].initialCookiesLength,diff --git a/test/e2e/playwright-introduction-guide/test.mjs b/test/e2e/playwright-introduction-guide/test.mjsindex 93a2a1609..1735a2a22 100644--- a/test/e2e/playwright-introduction-guide/test.mjs+++ b/test/e2e/playwright-introduction-guide/test.mjs@@ -5,4 +5,4 @@ await initialize(testActorDirname);const { stats } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished >= 10, 'All requests finished');+await expect(stats.requestsSucceeded >= 10, 'All requests finished');diff --git a/test/e2e/playwright-robots-file/test.mjs b/test/e2e/playwright-robots-file/test.mjsindex b8f384d4e..d87d8d494 100644--- a/test/e2e/playwright-robots-file/test.mjs+++ b/test/e2e/playwright-robots-file/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished >= 1, 'All requests finished');+await expect(stats.requestsSucceeded >= 1, 'All requests finished');const paths = datasetItems.map((item) => new URL(item.url).pathname);diff --git a/test/e2e/proxy-rotation/test.mjs b/test/e2e/proxy-rotation/test.mjsindex 36a82f8ff..a1653625e 100644--- a/test/e2e/proxy-rotation/test.mjs+++ b/test/e2e/proxy-rotation/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished === 5, 'All requests finished');+await expect(stats.requestsSucceeded === 5, 'All requests finished');await expect(datasetItems.length === 5, 'Number of dataset items');await expect(validateDataset(datasetItems, ['clientIp']), 'Dataset items validation');diff --git a/test/e2e/puppeteer-default/test.mjs b/test/e2e/puppeteer-default/test.mjsindex 9aa375ea5..a31ab4059 100644--- a/test/e2e/puppeteer-default/test.mjs+++ b/test/e2e/puppeteer-default/test.mjs@@ -5,6 +5,6 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished > 15, 'All requests finished');+await expect(stats.requestsSucceeded > 15, 'All requests finished');await expect(datasetItems.length > 15 && datasetItems.length < 30, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'pageTitle']), 'Dataset items validation');diff --git a/test/e2e/puppeteer-ignore-ssl-errors/test.mjs b/test/e2e/puppeteer-ignore-ssl-errors/test.mjsindex 5a500dbf9..418edd311 100644--- a/test/e2e/puppeteer-ignore-ssl-errors/test.mjs+++ b/test/e2e/puppeteer-ignore-ssl-errors/test.mjs@@ -8,6 +8,6 @@ const { stats, datasetItems } = await runActor(testActorDirname, 16384);// Of badssl.com's ~31 "bad" links, ~10 use ciphers/protocols modern Chrome removed// (3des, rc4, dh*, null, …) and can never load regardless of acceptInsecureCerts, so the// ceiling is ~20. Assert a comfortable floor that still proves cert errors are bypassed.-await expect(stats.requestsFinished > 10, 'All requests finished');+await expect(stats.requestsSucceeded > 10, 'All requests finished');await expect(datasetItems.length > 10, 'Minimum number of dataset items');await expect(validateDataset(datasetItems, ['url', 'title']), 'Dataset items validation');diff --git a/test/e2e/puppeteer-initial-cookies/test.mjs b/test/e2e/puppeteer-initial-cookies/test.mjsindex 012966452..32ebb53f5 100644--- a/test/e2e/puppeteer-initial-cookies/test.mjs+++ b/test/e2e/puppeteer-initial-cookies/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished === 1, 'All requests finished');+await expect(stats.requestsSucceeded === 1, 'All requests finished');await expect(datasetItems[0].numberOfMatchingCookies === 3, 'Number of page cookies');await expect(datasetItems[0].numberOfMatchingCookies === datasetItems[0].initialCookiesLength,diff --git a/test/e2e/puppeteer-page-info/test.mjs b/test/e2e/puppeteer-page-info/test.mjsindex ed362948f..07c44cdc0 100644--- a/test/e2e/puppeteer-page-info/test.mjs+++ b/test/e2e/puppeteer-page-info/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished === 2, 'All requests finished');+await expect(stats.requestsSucceeded === 2, 'All requests finished');await expect(datasetItems.length === 1, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'title', 'uniqueIdentifier', 'description', 'modifiedDate']),diff --git a/test/e2e/puppeteer-store-pagination-jquery/test.mjs b/test/e2e/puppeteer-store-pagination-jquery/test.mjsindex 830cd72ae..a3c3e7d7a 100644--- a/test/e2e/puppeteer-store-pagination-jquery/test.mjs+++ b/test/e2e/puppeteer-store-pagination-jquery/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished >= 10, 'All requests finished');+await expect(stats.requestsSucceeded >= 10, 'All requests finished');await expect(datasetItems.length > 5 && datasetItems.length < 15, 'Number of dataset items');await expect(validateDataset(datasetItems, ['manufacturer', 'title', 'sku', 'currentPrice', 'availableInStock']),diff --git a/test/e2e/puppeteer-store-pagination/test.mjs b/test/e2e/puppeteer-store-pagination/test.mjsindex 830cd72ae..a3c3e7d7a 100644--- a/test/e2e/puppeteer-store-pagination/test.mjs+++ b/test/e2e/puppeteer-store-pagination/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished >= 10, 'All requests finished');+await expect(stats.requestsSucceeded >= 10, 'All requests finished');await expect(datasetItems.length > 5 && datasetItems.length < 15, 'Number of dataset items');await expect(validateDataset(datasetItems, ['manufacturer', 'title', 'sku', 'currentPrice', 'availableInStock']),diff --git a/test/e2e/puppeteer-throw-on-ssl-errors/test.mjs b/test/e2e/puppeteer-throw-on-ssl-errors/test.mjsindex 725448fca..2103ce0a5 100644--- a/test/e2e/puppeteer-throw-on-ssl-errors/test.mjs+++ b/test/e2e/puppeteer-throw-on-ssl-errors/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished >= 5, 'All requests finished');+await expect(stats.requestsSucceeded >= 5, 'All requests finished');await expect(stats.requestsFailed > 20 && stats.requestsFailed < 30, 'Number of failed requests');await expect(datasetItems.length >= 5 && datasetItems.length < 10, 'Number of dataset items');await expect(validateDataset(datasetItems, ['url', 'title']), 'Dataset items validation');diff --git a/test/e2e/request-queue-zero-concurrency/test.mjs b/test/e2e/request-queue-zero-concurrency/test.mjsindex 0ad1ce2ef..622258300 100644--- a/test/e2e/request-queue-zero-concurrency/test.mjs+++ b/test/e2e/request-queue-zero-concurrency/test.mjs@@ -9,7 +9,7 @@ await initialize(testActorDirname);const { stats } = await runActor(testActorDirname);-await expect(stats.requestsFinished === 3, 'All requests finished');+await expect(stats.requestsSucceeded === 3, 'All requests finished');await expect(stats.crawlerRuntimeMillis > 30 * 1e3 && stats.crawlerRuntimeMillis < 35 * 1e3,'RequestQueue triggers auto-reset after being stuck with requests in progress',diff --git a/test/e2e/stagehand-claude/test.mjs b/test/e2e/stagehand-claude/test.mjsindex 1601de14c..3e57cf4cf 100644--- a/test/e2e/stagehand-claude/test.mjs+++ b/test/e2e/stagehand-claude/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished === 1, 'Request finished');+await expect(stats.requestsSucceeded === 1, 'Request finished');await expect(datasetItems.length === 1, 'One dataset item');await expect(validateDataset(datasetItems, ['url', 'codeJs', 'codePython']), 'Dataset items validation');await expect(datasetItems[0].codeJs && datasetItems[0].codeJs.length > 0, 'JS code extracted');diff --git a/test/e2e/stagehand-concurrent/test.mjs b/test/e2e/stagehand-concurrent/test.mjsindex cdc33c8f2..1ed4bff28 100644--- a/test/e2e/stagehand-concurrent/test.mjs+++ b/test/e2e/stagehand-concurrent/test.mjs@@ -5,7 +5,7 @@ await initialize(testActorDirname);const { stats, datasetItems } = await runActor(testActorDirname, 16384);-await expect(stats.requestsFinished === 3, 'All 3 requests finished');+await expect(stats.requestsSucceeded === 3, 'All 3 requests finished');await expect(stats.requestsFailed === 0, 'No requests failed');await expect(datasetItems.length === 3, 'Three dataset items');await expect(validateDataset(datasetItems, ['url', 'title', 'browserId']), 'Dataset items validation');diff --git a/test/e2e/tools.mjs b/test/e2e/tools.mjsindex ef515bfd9..57664bf04 100644--- a/test/e2e/tools.mjs+++ b/test/e2e/tools.mjs@@ -237,7 +237,7 @@ export async function runActor(dirName, memory = 4096) {// The statistics record is persisted during the crawler teardown and the platform KVS is// eventually consistent, so a single lookup right after the run can race the write and crash- // the whole test on `stats.requestsFinished`. Retry briefly and fall back to an empty object,+ // the whole test on `stats.requestsSucceeded`. Retry briefly and fall back to an empty object,// so a genuinely missing record fails the assertions instead of throwing a TypeError.let statsRecord;for (let attempt = 0; attempt < 10 && !statsRecord; attempt++) {