@crawlee/playwright 4.0.0-beta.34 → 4.0.0-beta.341

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +15 -11
  2. package/index.d.ts +4 -3
  3. package/index.js +2 -2
  4. package/internals/adaptive-playwright-crawler.d.ts +156 -82
  5. package/internals/adaptive-playwright-crawler.js +561 -300
  6. package/internals/enqueue-links/click-elements.d.ts +21 -58
  7. package/internals/enqueue-links/click-elements.js +48 -61
  8. package/internals/playwright-browser-pool.d.ts +55 -0
  9. package/internals/playwright-browser-pool.js +34 -0
  10. package/internals/playwright-crawler.d.ts +177 -171
  11. package/internals/playwright-crawler.js +121 -77
  12. package/internals/playwright-launcher.d.ts +30 -22
  13. package/internals/playwright-launcher.js +24 -18
  14. package/internals/utils/playwright-utils.d.ts +66 -54
  15. package/internals/utils/playwright-utils.js +128 -137
  16. package/internals/utils/rendering-type-prediction.d.ts +42 -13
  17. package/internals/utils/rendering-type-prediction.js +83 -50
  18. package/package.json +20 -23
  19. package/index.d.ts.map +0 -1
  20. package/index.js.map +0 -1
  21. package/internals/adaptive-playwright-crawler.d.ts.map +0 -1
  22. package/internals/adaptive-playwright-crawler.js.map +0 -1
  23. package/internals/enqueue-links/click-elements.d.ts.map +0 -1
  24. package/internals/enqueue-links/click-elements.js.map +0 -1
  25. package/internals/playwright-crawler.d.ts.map +0 -1
  26. package/internals/playwright-crawler.js.map +0 -1
  27. package/internals/playwright-launcher.d.ts.map +0 -1
  28. package/internals/playwright-launcher.js.map +0 -1
  29. package/internals/utils/playwright-utils.d.ts.map +0 -1
  30. package/internals/utils/playwright-utils.js.map +0 -1
  31. package/internals/utils/rendering-type-prediction.d.ts.map +0 -1
  32. package/internals/utils/rendering-type-prediction.js.map +0 -1
package/README.md CHANGED
@@ -1,23 +1,23 @@
1
1
  <h1 align="center">
2
2
  <a href="https://crawlee.dev">
3
3
  <picture>
4
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true">
5
- <img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500">
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true" />
5
+ <img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500" />
6
6
  </picture>
7
7
  </a>
8
- <br>
8
+ <br />
9
9
  <small>A web scraping and browser automation library</small>
10
10
  </h1>
11
11
 
12
- <p align=center>
13
- <a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
12
+ <p align="center">
13
+ <a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift" width="250" height="55"/></a>
14
14
  </p>
15
15
 
16
- <p align=center>
17
- <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" style="max-width: 100%;"></a>
18
- <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" style="max-width: 100%;"></a>
19
- <a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" style="max-width: 100%;"></a>
20
- <a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status" style="max-width: 100%;"></a>
16
+ <p align="center">
17
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" /></a>
18
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" /></a>
19
+ <a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" /></a>
20
+ <a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status" /></a>
21
21
  </p>
22
22
 
23
23
  Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
@@ -34,7 +34,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
34
34
 
35
35
  We recommend visiting the [Introduction tutorial](https://crawlee.dev/js/docs/introduction) in Crawlee documentation for more information.
36
36
 
37
- > Crawlee requires **Node.js 16 or higher**.
37
+ > Crawlee requires **Node.js 22.13 or higher**.
38
38
 
39
39
  ### With Crawlee CLI
40
40
 
@@ -144,6 +144,10 @@ Crawlee is open-source and runs anywhere, but since it's developed by [Apify](ht
144
144
 
145
145
  If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/crawlee/issues). For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
146
146
 
147
+ ## Supported versions
148
+
149
+ New features and bug fixes land in the latest major version. The previous major version keeps receiving fixes for high and critical severity vulnerabilities for 12 months after the next major is released, and reaches end of life after that. See the [security policy](https://github.com/apify/crawlee/security/policy) for the current status of each version and for how to report a vulnerability.
150
+
147
151
  ## Contributing
148
152
 
149
153
  Your code contributions are welcome, and you'll be praised to eternity! If you have any ideas for improvements, either submit an issue or create a pull request. For contribution guidelines and the code of conduct, see [CONTRIBUTING.md](https://github.com/apify/crawlee/blob/master/CONTRIBUTING.md).
package/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export * from '@crawlee/browser';
2
+ export * from './internals/playwright-browser-pool.js';
2
3
  export * from './internals/playwright-crawler.js';
3
- export * from './internals/playwright-launcher.js';
4
+ export { launchPlaywright } from './internals/playwright-launcher.js';
5
+ export type { PlaywrightLaunchContext } from './internals/playwright-launcher.js';
4
6
  export * from './internals/adaptive-playwright-crawler.js';
5
7
  export { RenderingTypePredictor } from './internals/utils/rendering-type-prediction.js';
6
8
  export * as playwrightUtils from './internals/utils/playwright-utils.js';
7
9
  export * as playwrightClickElements from './internals/enqueue-links/click-elements.js';
8
10
  export type { DirectNavigationOptions as PlaywrightDirectNavigationOptions } from './internals/utils/playwright-utils.js';
9
- export type { RenderingType } from './internals/utils/rendering-type-prediction.js';
10
- //# sourceMappingURL=index.d.ts.map
11
+ export type { IRenderingTypePredictor, RenderingType } from './internals/utils/rendering-type-prediction.js';
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export * from '@crawlee/browser';
2
+ export * from './internals/playwright-browser-pool.js';
2
3
  export * from './internals/playwright-crawler.js';
3
- export * from './internals/playwright-launcher.js';
4
+ export { launchPlaywright } from './internals/playwright-launcher.js';
4
5
  export * from './internals/adaptive-playwright-crawler.js';
5
6
  export { RenderingTypePredictor } from './internals/utils/rendering-type-prediction.js';
6
7
  export * as playwrightUtils from './internals/utils/playwright-utils.js';
7
8
  export * as playwrightClickElements from './internals/enqueue-links/click-elements.js';
8
- //# sourceMappingURL=index.js.map
@@ -1,32 +1,41 @@
1
+ import type { BrowserHook, LoadedRequest, RouterHandler, RouteSchemas, RoutesFromSchemas } from '@crawlee/browser';
2
+ import type { BasicCrawlerOptions, CrawlingContext, EnqueueLinksOptions, ExtractLinksOptions, GetUserDataFromRequest, RouterRoutes } from '@crawlee/basic';
1
3
  import { BasicCrawler } from '@crawlee/basic';
2
- import type { BasicCrawlerOptions, BrowserHook, LoadedRequest, Request } from '@crawlee/browser';
3
- import type { ContextPipeline, CrawlingContext, EnqueueLinksOptions, GetUserDataFromRequest, RestrictedCrawlingContext, RouterRoutes, StatisticsOptions, StatisticState } from '@crawlee/core';
4
- import { RequestHandlerResult, Statistics } from '@crawlee/core';
5
- import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
6
- import { type CheerioRoot } from '@crawlee/utils';
7
- import { type Cheerio } from 'cheerio';
4
+ import { CrawlingRequest } from '@crawlee/browser';
5
+ import type { AddRequestsBatchedResult, StorageTransactionView } from '@crawlee/core';
6
+ import type { Dictionary, Awaitable } from '@crawlee/types';
7
+ import { type Cheerio, type CheerioAPI } from 'cheerio';
8
8
  import type { AnyNode } from 'domhandler';
9
9
  // @ts-ignore optional peer dependency or compatibility with es2022
10
10
  import type { Page } from 'playwright';
11
- import type { SetRequired } from 'type-fest';
12
- import type { PlaywrightGotoOptions } from './playwright-crawler.js';
13
- import { RenderingTypePredictor } from './utils/rendering-type-prediction.js';
14
- interface AdaptivePlaywrightCrawlerStatisticState extends StatisticState {
15
- httpOnlyRequestHandlerRuns?: number;
16
- browserRequestHandlerRuns?: number;
17
- renderingTypeMispredictions?: number;
18
- }
19
- declare class AdaptivePlaywrightCrawlerStatistics extends Statistics {
20
- state: AdaptivePlaywrightCrawlerStatisticState;
21
- constructor(options?: StatisticsOptions);
22
- reset(): void;
23
- protected _maybeLoadStatistics(): Promise<void>;
24
- trackHttpOnlyRequestHandlerRun(): void;
25
- trackBrowserRequestHandlerRun(): void;
26
- trackRenderingTypeMisprediction(): void;
27
- }
28
- export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary = Dictionary> extends CrawlingContext<UserData> {
29
- request: LoadedRequest<Request<UserData>>;
11
+ import { z } from 'zod';
12
+ import type { PlaywrightCrawlerOptions, PlaywrightCrawlingContext, PlaywrightGotoOptions } from './playwright-crawler.js';
13
+ import { type IRenderingTypePredictor } from './utils/rendering-type-prediction.js';
14
+ declare const adaptiveStatisticStateSchema: z.ZodObject<{
15
+ httpOnlyRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
16
+ browserRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
17
+ renderingTypeMispredictions: z.ZodDefault<z.ZodNumber>;
18
+ }, z.core.$strip>;
19
+ /**
20
+ * The extra statistics fields {@link AdaptivePlaywrightCrawler} tracks on top of the built-in
21
+ * {@link StatisticState} ones. They are available on `crawler.statistics.state` and are persisted with the rest of
22
+ * the statistics.
23
+ */
24
+ export type AdaptivePlaywrightCrawlerStatisticState = z.infer<typeof adaptiveStatisticStateSchema>;
25
+ /**
26
+ * The {@link AdaptivePlaywrightCrawlerStatisticState} fields as a {@link Statistics} state extension, defaults
27
+ * and all. A {@link Statistics} instance to be injected into an {@link AdaptivePlaywrightCrawler} has to carry
28
+ * them - `deserialize.extend()` your own fields onto this one and pass the result as `stateExtension`.
29
+ */
30
+ export declare const adaptivePlaywrightCrawlerStatisticState: {
31
+ deserialize: z.ZodObject<{
32
+ httpOnlyRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
33
+ browserRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
34
+ renderingTypeMispredictions: z.ZodDefault<z.ZodNumber>;
35
+ }, z.core.$strip>;
36
+ };
37
+ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
38
+ request: LoadedRequest<CrawlingRequest<UserData>>;
30
39
  /**
31
40
  * The HTTP response, either from the HTTP client or from the initial request from playwright's navigation.
32
41
  */
@@ -36,10 +45,16 @@ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary =
36
45
  */
37
46
  page: Page;
38
47
  /**
39
- * Wait for an element matching the selector to appear and return a Cheerio object of matched elements.
48
+ * Wait for an element matching the selector to appear and return a Cheerio object of all matched elements.
49
+ * Throws when nothing matches - in the HTTP-only run, that makes the crawler retry the request in a browser.
40
50
  * Timeout defaults to 5s.
41
51
  */
42
- querySelector(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
52
+ querySelectorAll(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
53
+ /**
54
+ * Like {@link AdaptivePlaywrightCrawlerContext.querySelectorAll|`querySelectorAll`}, but returns only the
55
+ * first match.
56
+ */
57
+ querySelectorOne(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
43
58
  /**
44
59
  * Wait for an element matching the selector to appear.
45
60
  * Timeout defaults to 5s.
@@ -66,38 +81,82 @@ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary =
66
81
  * });
67
82
  * ```
68
83
  */
69
- parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioRoot>;
70
- enqueueLinks(options?: EnqueueLinksOptions): Promise<unknown>;
84
+ parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
85
+ /**
86
+ * Extracts URLs from the current page, without adding them to the request queue.
87
+ * In a browser, it first waits for an element matching the selector, with a 5s timeout.
88
+ */
89
+ extractLinks(options?: ExtractLinksOptions): Promise<string[]>;
90
+ /**
91
+ * Extracts URLs from the current page and adds them to the request queue.
92
+ *
93
+ * By default, the requests are buffered until the crawler settles on this attempt's result, so the returned
94
+ * `requestId` of a newly added request is provisional, and nothing is added when the attempt is discarded.
95
+ */
96
+ enqueueLinks(options?: EnqueueLinksOptions): Promise<AddRequestsBatchedResult>;
71
97
  }
72
- interface AdaptiveHook extends BrowserHook<Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log'> & {
98
+ interface AdaptiveHookContext extends Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log' | 'extendTimeout'> {
73
99
  page?: Page;
74
- request: Request;
75
- }, PlaywrightGotoOptions> {
100
+ request: CrawlingRequest;
101
+ gotoOptions?: PlaywrightGotoOptions;
102
+ }
103
+ type AdaptiveHook<ContextExtension = Dictionary<never>> = BrowserHook<AdaptiveHookContext, ContextExtension>;
104
+ type AdaptivePostNavigationHook<ContextExtension = Dictionary<never>> = BrowserHook<Omit<AdaptiveHookContext, 'request'> & {
105
+ request: LoadedRequest<CrawlingRequest>;
106
+ }, ContextExtension>;
107
+ /** Passed to {@link AdaptivePlaywrightCrawlerOptions.resultChecker} and `resultComparator` alongside the results. */
108
+ export interface AdaptiveResultContext {
109
+ /** The request whose handler produced the results. */
110
+ request: CrawlingRequest;
76
111
  }
77
- export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ExtendedContext>, 'preNavigationHooks' | 'postNavigationHooks'> {
112
+ export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>, StatisticStateExtension extends AdaptivePlaywrightCrawlerStatisticState = AdaptivePlaywrightCrawlerStatisticState> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension>, 'preNavigationHooks' | 'postNavigationHooks' | 'contextPipelineBuilder'>, Pick<PlaywrightCrawlerOptions, 'launchContext' | 'headless' | 'browserPool' | 'remoteBrowser'> {
113
+ /**
114
+ * Timeout for the navigation phase of each attempt, in seconds, shared by the `preNavigationHooks`, the
115
+ * navigation and the `postNavigationHooks`. Applies to both the HTTP-only and the browser attempt. When not
116
+ * set, each attempt keeps its own default: 30 seconds for HTTP-only and 60 seconds for the browser.
117
+ */
118
+ navigationTimeoutSecs?: number;
78
119
  /**
79
120
  * Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies.
80
121
  * The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
81
122
  * an exception will be thrown. If it's not caught, the request will be transparently retried in a browser.
123
+ *
124
+ * A hook may optionally return a partial object whose properties are merged into the crawling context,
125
+ * allowing the hook to override context members for subsequent hooks and pipeline stages.
82
126
  */
83
- preNavigationHooks?: AdaptiveHook[];
127
+ preNavigationHooks?: AdaptiveHook<ContextExtension>[];
84
128
  /**
85
129
  * Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
86
130
  * The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
87
131
  * an exception will be thrown. If it's not caught, the request will be transparently retried in a browser.
132
+ *
133
+ * A hook may optionally return a partial object whose properties are merged into the crawling context
134
+ * (e.g. to override `response` after solving a challenge).
88
135
  */
89
- postNavigationHooks?: AdaptiveHook[];
136
+ postNavigationHooks?: AdaptivePostNavigationHook<ContextExtension>[];
90
137
  /**
91
138
  * Specifies the frequency of rendering type detection checks - 0.1 means roughly 10% of requests.
92
139
  * Defaults to 0.1 (so 10%).
93
140
  */
94
141
  renderingTypeDetectionRatio?: number;
95
142
  /**
96
- * An optional callback that is called on dataset items found by the request handler in plain HTTP mode.
143
+ * An optional callback that is called on the storage writes recorded by the request handler in plain
144
+ * HTTP mode (exposed as a read-only {@link StorageTransactionView}).
97
145
  * If it returns false, the request is retried in a browser.
98
- * If no callback is specified, every dataset item is considered valid.
146
+ * If no callback is specified, every result is considered valid.
147
+ */
148
+ resultChecker?: (result: StorageTransactionView, context: AdaptiveResultContext) => boolean;
149
+ /**
150
+ * An optional callback that decides whether an error thrown during the plain HTTP request handler
151
+ * should be propagated (instead of falling back to browser navigation).
152
+ *
153
+ * If the callback returns `true`, the error is thrown, triggering the standard retry mechanism.
154
+ * If the callback returns `false` (or is not provided), the error is logged and the crawler
155
+ * falls back to browser navigation (default behavior).
156
+ *
157
+ * @default () => false
99
158
  */
100
- resultChecker?: (result: RequestHandlerResult) => boolean;
159
+ shouldPropagateError?: (error: Error, context: PlaywrightCrawlingContext) => Awaitable<boolean>;
101
160
  /**
102
161
  * An optional callback used in rendering type detection. On each detection, the result of the plain HTTP run is compared to that of the browser one.
103
162
  * If a callback is provided, the contract is as follows:
@@ -106,17 +165,16 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
106
165
  * If it returns 'inconclusive', the detection result won't be used.
107
166
  * If no result comparator is specified, but there is a `resultChecker`, any site where the `resultChecker` returns true is considered static.
108
167
  * If neither `resultComparator` nor `resultChecker` are specified, a deep comparison of returned dataset items is used as a default.
168
+ *
169
+ * For a stricter, ready-made comparator that also takes enqueued requests and key-value store changes into account, see {@link fullResultComparator}.
109
170
  */
110
- resultComparator?: (resultA: RequestHandlerResult, resultB: RequestHandlerResult) => boolean | 'equal' | 'different' | 'inconclusive';
111
- /**
112
- * A custom rendering type predictor
113
- */
114
- renderingTypePredictor?: Pick<RenderingTypePredictor, 'predict' | 'storeResult' | 'initialize'>;
171
+ resultComparator?: (resultA: StorageTransactionView, resultB: StorageTransactionView, context: AdaptiveResultContext) => boolean | 'equal' | 'different' | 'inconclusive';
115
172
  /**
116
- * Prevent direct access to storage in request handlers (only allow using context helpers).
117
- * Defaults to `true`
173
+ * A custom rendering type predictor. A predictor passed here is borrowed - the crawler never drives its
174
+ * lifecycle, so set it up yourself (the built-in {@link RenderingTypePredictor} needs `initialize()`).
175
+ * Omit the option and the crawler builds its own from `renderingTypeDetectionRatio` - and initializes it.
118
176
  */
119
- preventDirectStorageAccess?: boolean;
177
+ renderingTypePredictor?: IRenderingTypePredictor;
120
178
  }
121
179
  /**
122
180
  * An extension of {@link PlaywrightCrawler} that uses a more limited request handler interface so that it is able to switch to HTTP-only crawling when it detects it may be possible.
@@ -126,9 +184,9 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
126
184
  * ```javascript
127
185
  * const crawler = new AdaptivePlaywrightCrawler({
128
186
  * renderingTypeDetectionRatio: 0.1,
129
- * async requestHandler({ querySelector, pushData, enqueueLinks, request, log }) {
187
+ * async requestHandler({ querySelectorAll, pushData, enqueueLinks, request, log }) {
130
188
  * // This function is called to extract data from a single web page
131
- * const $prices = await querySelector('span.price')
189
+ * const $prices = await querySelectorAll('span.price')
132
190
  *
133
191
  * await pushData({
134
192
  * url: request.url,
@@ -144,42 +202,58 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
144
202
  * 'http://www.example.com/page-2',
145
203
  * ]);
146
204
  * ```
147
- *
148
- * @experimental
149
205
  */
150
- export declare class AdaptivePlaywrightCrawler<ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ExtendedContext> {
151
- private renderingTypePredictor;
152
- private resultChecker;
153
- private resultComparator;
154
- private preventDirectStorageAccess;
155
- private staticContextPipeline;
156
- private browserContextPipeline;
157
- private individualRequestHandlerTimeoutMillis;
158
- readonly stats: AdaptivePlaywrightCrawlerStatistics;
159
- private resultObjects;
160
- private inFlightRenderingTypeDetections;
161
- private teardownHooks;
162
- constructor(options?: AdaptivePlaywrightCrawlerOptions<ExtendedContext>);
163
- protected _init(): Promise<void>;
164
- protected buildContextPipeline(): ContextPipeline<CrawlingContext<Dictionary>, CrawlingContext<Dictionary> & {
165
- readonly request: LoadedRequest<Request<Dictionary>>;
166
- readonly response: Response;
167
- readonly page: Page;
168
- readonly querySelector: AdaptivePlaywrightCrawlerContext["querySelector"];
169
- readonly waitForSelector: AdaptivePlaywrightCrawlerContext["waitForSelector"];
170
- readonly parseWithCheerio: AdaptivePlaywrightCrawlerContext["parseWithCheerio"];
171
- }>;
172
- private adaptCheerioContext;
173
- private adaptPlaywrightContext;
174
- private crawlOne;
206
+ export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>, StatisticStateExtension extends AdaptivePlaywrightCrawlerStatisticState = AdaptivePlaywrightCrawlerStatisticState> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
207
+ #private;
208
+ constructor(options?: AdaptivePlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes, StatisticStateExtension>);
209
+ protected init(): Promise<void>;
175
210
  protected runRequestHandler(crawlingContext: CrawlingContext): Promise<void>;
176
- protected commitResult(crawlingContext: CrawlingContext, { calls, keyValueStoreChanges }: RequestHandlerResult): Promise<void>;
177
- protected allowStorageAccess<R, TArgs extends any[]>(func: (...args: TArgs) => Promise<R>): (...args: TArgs) => Promise<R>;
178
- protected enqueueLinks(options: SetRequired<EnqueueLinksOptions, 'urls'>, request: RestrictedCrawlingContext['request'], result: RequestHandlerResult): Promise<BatchAddRequestsResult>;
179
- private createLogProxy;
211
+ /**
212
+ * Number of rendering type detections that have not settled yet, including results the predictor is
213
+ * still persisting.
214
+ */
215
+ get inFlightRenderingTypeDetectionCount(): number;
216
+ /**
217
+ * Waits for in-flight rendering type detections to settle, bounded by `timeoutMillis` (defaults to the
218
+ * internal timeout).
219
+ */
220
+ drainRenderingDetections({ timeoutMillis }?: {
221
+ timeoutMillis?: number;
222
+ }): Promise<void>;
223
+ /**
224
+ * Stops the crawler immediately, but not before rendering type detections already under way (and results
225
+ * the predictor is still persisting) have settled - see
226
+ * {@link AdaptivePlaywrightCrawler.drainRenderingDetections|`drainRenderingDetections()`}. Requests
227
+ * that are still running are not waited for, unlike {@link BasicCrawler.stop|`stop()`}.
228
+ */
180
229
  teardown(): Promise<void>;
230
+ destroy(): Promise<void>;
181
231
  }
182
- // @ts-ignore optional peer dependency or compatibility with es2022
183
- export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData>): import("@crawlee/basic").RouterHandler<Context>;
232
+ export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>>(routes?: RouterRoutes<Context, Routes>): RouterHandler<Context, Routes>;
233
+ export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, Record<string, UserData>>): RouterHandler<Context, Record<string, UserData>>;
234
+ export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
235
+ /**
236
+ * An opt-in {@link AdaptivePlaywrightCrawlerOptions.resultComparator|`resultComparator`} that considers two
237
+ * request handler results equal only if *all* of their observable effects match - the pushed dataset items, the
238
+ * enqueued requests, and the key-value store changes. This is stricter than the default comparator, which only
239
+ * compares dataset items.
240
+ *
241
+ * **Beware:** enqueued URLs are compared exactly. The same page rendered in a browser and via plain HTTP often
242
+ * yields links that differ only in tracking query parameters, for example:
243
+ * - `https://sdk.apify.com/docs/guides/getting-started`
244
+ * - `https://sdk.apify.com/docs/guides/getting-started?__hsfp=1136113150&__hssc=7591405.1.173549427712`
245
+ *
246
+ * Such links are treated as *different*, which will make the crawler favor browser rendering for those pages.
247
+ *
248
+ * **Example usage:**
249
+ * ```ts
250
+ * const crawler = new AdaptivePlaywrightCrawler({
251
+ * resultComparator: fullResultComparator,
252
+ * async requestHandler({ pushData, enqueueLinks }) {
253
+ * // ...
254
+ * },
255
+ * });
256
+ * ```
257
+ */
258
+ export declare function fullResultComparator(resultA: StorageTransactionView, resultB: StorageTransactionView): boolean;
184
259
  export {};
185
- //# sourceMappingURL=adaptive-playwright-crawler.d.ts.map