@crawlee/playwright 4.0.0-beta.16 → 4.0.0-beta.161

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 +14 -14
  2. package/index.d.ts +2 -2
  3. package/index.js +1 -1
  4. package/internals/adaptive-playwright-crawler.d.ts +116 -63
  5. package/internals/adaptive-playwright-crawler.js +324 -266
  6. package/internals/enqueue-links/click-elements.d.ts +36 -64
  7. package/internals/enqueue-links/click-elements.js +65 -67
  8. package/internals/playwright-browser-pool.d.ts +71 -0
  9. package/internals/playwright-browser-pool.js +61 -0
  10. package/internals/playwright-crawler.d.ts +180 -125
  11. package/internals/playwright-crawler.js +68 -63
  12. package/internals/playwright-launcher.d.ts +32 -18
  13. package/internals/playwright-launcher.js +23 -17
  14. package/internals/utils/playwright-utils.d.ts +54 -41
  15. package/internals/utils/playwright-utils.js +110 -121
  16. package/internals/utils/rendering-type-prediction.d.ts +25 -11
  17. package/internals/utils/rendering-type-prediction.js +81 -27
  18. package/package.json +14 -18
  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.**
@@ -89,7 +89,7 @@ By default, Crawlee stores data to `./storage` in the current working directory.
89
89
  We provide automated beta builds for every merged code change in Crawlee. You can find them in the npm [list of releases](https://www.npmjs.com/package/crawlee?activeTab=versions). If you want to test new features or bug fixes before we release them, feel free to install a beta build like this:
90
90
 
91
91
  ```bash
92
- npm install crawlee@3.12.3-beta.13
92
+ npm install crawlee@next
93
93
  ```
94
94
 
95
95
  If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need to specify dependency overrides in your `package.json` file so that you don't end up with multiple versions of Crawlee installed:
@@ -98,9 +98,9 @@ If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need
98
98
  {
99
99
  "overrides": {
100
100
  "apify": {
101
- "@crawlee/core": "3.12.3-beta.13",
102
- "@crawlee/types": "3.12.3-beta.13",
103
- "@crawlee/utils": "3.12.3-beta.13"
101
+ "@crawlee/core": "$crawlee",
102
+ "@crawlee/types": "$crawlee",
103
+ "@crawlee/utils": "$crawlee"
104
104
  }
105
105
  }
106
106
  }
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from '@crawlee/browser';
2
+ export * from './internals/playwright-browser-pool.js';
2
3
  export * from './internals/playwright-crawler.js';
3
4
  export * from './internals/playwright-launcher.js';
4
5
  export * from './internals/adaptive-playwright-crawler.js';
@@ -6,5 +7,4 @@ export { RenderingTypePredictor } from './internals/utils/rendering-type-predict
6
7
  export * as playwrightUtils from './internals/utils/playwright-utils.js';
7
8
  export * as playwrightClickElements from './internals/enqueue-links/click-elements.js';
8
9
  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
10
+ 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
4
  export * 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,31 +1,39 @@
1
+ import type { BrowserHook, LoadedRequest, Request, RouterHandler, RouteSchemas, RoutesFromSchemas } from '@crawlee/browser';
2
+ import type { BasicCrawlerOptions } from '@crawlee/basic';
1
3
  import { BasicCrawler } from '@crawlee/basic';
2
- import type { BasicCrawlerOptions, BrowserHook, LoadedRequest, Request } from '@crawlee/browser';
3
- import type { CrawlingContext, EnqueueLinksOptions, GetUserDataFromRequest, RestrictedCrawlingContext, RouterRoutes, StatisticsOptions, StatisticState } from '@crawlee/core';
4
- import { Configuration, 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 type { ContextPipeline, CrawlingContext, EnqueueLinksOptions, GetUserDataFromRequest, RouterRoutes, StorageTransactionView } from '@crawlee/core';
5
+ import type { Dictionary, Awaitable } from '@crawlee/types';
6
+ import { type Cheerio, type CheerioAPI } from 'cheerio';
8
7
  import type { AnyNode } from 'domhandler';
9
8
  // @ts-ignore optional peer dependency or compatibility with es2022
10
9
  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> {
10
+ import { z } from 'zod';
11
+ import type { PlaywrightCrawlerOptions, PlaywrightCrawlingContext, PlaywrightGotoOptions } from './playwright-crawler.js';
12
+ import { type IRenderingTypePredictor } from './utils/rendering-type-prediction.js';
13
+ declare const adaptiveStatisticStateSchema: z.ZodObject<{
14
+ httpOnlyRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
15
+ browserRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
16
+ renderingTypeMispredictions: z.ZodDefault<z.ZodNumber>;
17
+ }, z.core.$strip>;
18
+ /**
19
+ * The extra statistics fields {@link AdaptivePlaywrightCrawler} tracks on top of the built-in
20
+ * {@link StatisticState} ones. They are available on `crawler.statistics.state` and are persisted with the rest of
21
+ * the statistics.
22
+ */
23
+ export type AdaptivePlaywrightCrawlerStatisticState = z.infer<typeof adaptiveStatisticStateSchema>;
24
+ /**
25
+ * The {@link AdaptivePlaywrightCrawlerStatisticState} fields as a {@link Statistics} state extension, defaults
26
+ * and all. A {@link Statistics} instance to be injected into an {@link AdaptivePlaywrightCrawler} has to carry
27
+ * them - `deserialize.extend()` your own fields onto this one and pass the result as `stateExtension`.
28
+ */
29
+ export declare const adaptivePlaywrightCrawlerStatisticState: {
30
+ deserialize: z.ZodObject<{
31
+ httpOnlyRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
32
+ browserRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
33
+ renderingTypeMispredictions: z.ZodDefault<z.ZodNumber>;
34
+ }, z.core.$strip>;
35
+ };
36
+ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
29
37
  request: LoadedRequest<Request<UserData>>;
30
38
  /**
31
39
  * The HTTP response, either from the HTTP client or from the initial request from playwright's navigation.
@@ -36,10 +44,15 @@ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary =
36
44
  */
37
45
  page: Page;
38
46
  /**
39
- * Wait for an element matching the selector to appear and return a Cheerio object of matched elements.
47
+ * Wait for an element matching the selector to appear and return a Cheerio object of the first matched element.
40
48
  * Timeout defaults to 5s.
41
49
  */
42
50
  querySelector(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
51
+ /**
52
+ * Wait for an element matching the selector to appear and return a Cheerio object of all matched elements.
53
+ * Timeout defaults to 5s.
54
+ */
55
+ querySelectorAll(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
43
56
  /**
44
57
  * Wait for an element matching the selector to appear.
45
58
  * Timeout defaults to 5s.
@@ -66,38 +79,60 @@ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary =
66
79
  * });
67
80
  * ```
68
81
  */
69
- parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioRoot>;
70
- enqueueLinks(options?: EnqueueLinksOptions): Promise<void>;
82
+ parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
83
+ enqueueLinks(options?: EnqueueLinksOptions): Promise<unknown>;
71
84
  }
72
- interface AdaptiveHook extends BrowserHook<Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log'> & {
85
+ interface AdaptiveHookContext extends Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log'> {
73
86
  page?: Page;
74
87
  request: Request;
75
- }, PlaywrightGotoOptions> {
88
+ gotoOptions?: PlaywrightGotoOptions;
76
89
  }
77
- export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ExtendedContext>, 'preNavigationHooks' | 'postNavigationHooks'> {
90
+ type AdaptiveHook<ContextExtension = Dictionary<never>> = BrowserHook<AdaptiveHookContext, ContextExtension>;
91
+ type AdaptivePostNavigationHook<ContextExtension = Dictionary<never>> = BrowserHook<Omit<AdaptiveHookContext, 'request'> & {
92
+ request: LoadedRequest<Request>;
93
+ }, ContextExtension>;
94
+ 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'>, Pick<PlaywrightCrawlerOptions, 'launchContext' | 'headless' | 'browserPool' | 'remoteBrowser'> {
78
95
  /**
79
96
  * Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies.
80
97
  * The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
81
98
  * an exception will be thrown. If it's not caught, the request will be transparently retried in a browser.
99
+ *
100
+ * A hook may optionally return a partial object whose properties are merged into the crawling context,
101
+ * allowing the hook to override context members for subsequent hooks and pipeline stages.
82
102
  */
83
- preNavigationHooks?: AdaptiveHook[];
103
+ preNavigationHooks?: AdaptiveHook<ContextExtension>[];
84
104
  /**
85
105
  * Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
86
106
  * The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
87
107
  * an exception will be thrown. If it's not caught, the request will be transparently retried in a browser.
108
+ *
109
+ * A hook may optionally return a partial object whose properties are merged into the crawling context
110
+ * (e.g. to override `response` after solving a challenge).
88
111
  */
89
- postNavigationHooks?: AdaptiveHook[];
112
+ postNavigationHooks?: AdaptivePostNavigationHook<ContextExtension>[];
90
113
  /**
91
114
  * Specifies the frequency of rendering type detection checks - 0.1 means roughly 10% of requests.
92
115
  * Defaults to 0.1 (so 10%).
93
116
  */
94
117
  renderingTypeDetectionRatio?: number;
95
118
  /**
96
- * An optional callback that is called on dataset items found by the request handler in plain HTTP mode.
119
+ * An optional callback that is called on the storage writes recorded by the request handler in plain
120
+ * HTTP mode (exposed as a read-only {@link StorageTransactionView}).
97
121
  * If it returns false, the request is retried in a browser.
98
- * If no callback is specified, every dataset item is considered valid.
122
+ * If no callback is specified, every result is considered valid.
123
+ */
124
+ resultChecker?: (result: StorageTransactionView) => boolean;
125
+ /**
126
+ * An optional callback that decides whether an error thrown during the plain HTTP request handler
127
+ * should be propagated (instead of falling back to browser navigation).
128
+ *
129
+ * If the callback returns `true`, the error is thrown, triggering the standard retry mechanism.
130
+ * If the callback returns `false` (or is not provided), the error is logged and the crawler
131
+ * falls back to browser navigation (default behavior).
132
+ *
133
+ * @default () => false
99
134
  */
100
- resultChecker?: (result: RequestHandlerResult) => boolean;
135
+ shouldPropagateError?: (error: Error, context: PlaywrightCrawlingContext) => Awaitable<boolean>;
101
136
  /**
102
137
  * 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
138
  * If a callback is provided, the contract is as follows:
@@ -106,17 +141,16 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
106
141
  * If it returns 'inconclusive', the detection result won't be used.
107
142
  * If no result comparator is specified, but there is a `resultChecker`, any site where the `resultChecker` returns true is considered static.
108
143
  * If neither `resultComparator` nor `resultChecker` are specified, a deep comparison of returned dataset items is used as a default.
144
+ *
145
+ * For a stricter, ready-made comparator that also takes enqueued requests and key-value store changes into account, see {@link fullResultComparator}.
109
146
  */
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'>;
147
+ resultComparator?: (resultA: StorageTransactionView, resultB: StorageTransactionView) => boolean | 'equal' | 'different' | 'inconclusive';
115
148
  /**
116
- * Prevent direct access to storage in request handlers (only allow using context helpers).
117
- * Defaults to `true`
149
+ * A custom rendering type predictor. A predictor passed here is borrowed - the crawler never drives its
150
+ * lifecycle, so set it up yourself (the built-in {@link RenderingTypePredictor} needs `initialize()`).
151
+ * Omit the option and the crawler builds its own from `renderingTypeDetectionRatio` - and initializes it.
118
152
  */
119
- preventDirectStorageAccess?: boolean;
153
+ renderingTypePredictor?: IRenderingTypePredictor;
120
154
  }
121
155
  /**
122
156
  * 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.
@@ -147,31 +181,50 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
147
181
  *
148
182
  * @experimental
149
183
  */
150
- export declare class AdaptivePlaywrightCrawler<ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ExtendedContext> {
151
- readonly config: Configuration;
152
- private renderingTypePredictor;
153
- private resultChecker;
154
- private resultComparator;
155
- private preventDirectStorageAccess;
156
- private staticContextPipeline;
157
- private browserContextPipeline;
158
- private individualRequestHandlerTimeoutMillis;
159
- readonly stats: AdaptivePlaywrightCrawlerStatistics;
160
- private resultObjects;
161
- private teardownHooks;
162
- constructor(options?: AdaptivePlaywrightCrawlerOptions<ExtendedContext>, config?: Configuration);
163
- protected _init(): Promise<void>;
184
+ 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> {
185
+ #private;
186
+ constructor(options?: AdaptivePlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes, StatisticStateExtension>);
187
+ protected init(): Promise<void>;
188
+ protected buildContextPipeline(): ContextPipeline<CrawlingContext, AdaptivePlaywrightCrawlerContext>;
164
189
  private adaptCheerioContext;
165
190
  private adaptPlaywrightContext;
191
+ /**
192
+ * Runs one request handler attempt inside its own {@link StorageTransaction}, wrapping the inner
193
+ * (static or browser) context pipeline. The transaction is pushed to `transactions` *at creation
194
+ * time, before the `try`* - the `ok: false` branch of the returned {@link Result} carries no
195
+ * result, and failed attempts are routine here. The caller owns the outcome and disposal.
196
+ */
166
197
  private crawlOne;
167
198
  protected runRequestHandler(crawlingContext: CrawlingContext): Promise<void>;
168
- protected commitResult(crawlingContext: CrawlingContext, { calls, keyValueStoreChanges }: RequestHandlerResult): Promise<void>;
169
- protected allowStorageAccess<R, TArgs extends any[]>(func: (...args: TArgs) => Promise<R>): (...args: TArgs) => Promise<R>;
170
- protected enqueueLinks(options: SetRequired<EnqueueLinksOptions, 'urls'>, request: RestrictedCrawlingContext['request'], result: RequestHandlerResult): Promise<BatchAddRequestsResult>;
199
+ private enqueueLinks;
171
200
  private createLogProxy;
172
201
  teardown(): Promise<void>;
173
202
  }
174
- // @ts-ignore optional peer dependency or compatibility with es2022
175
- export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData>): import("@crawlee/basic").RouterHandler<Context>;
203
+ 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>;
204
+ 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>>;
205
+ export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
206
+ /**
207
+ * An opt-in {@link AdaptivePlaywrightCrawlerOptions.resultComparator|`resultComparator`} that considers two
208
+ * request handler results equal only if *all* of their observable effects match - the pushed dataset items, the
209
+ * enqueued requests, and the key-value store changes. This is stricter than the default comparator, which only
210
+ * compares dataset items.
211
+ *
212
+ * **Beware:** enqueued URLs are compared exactly. The same page rendered in a browser and via plain HTTP often
213
+ * yields links that differ only in tracking query parameters, for example:
214
+ * - `https://sdk.apify.com/docs/guides/getting-started`
215
+ * - `https://sdk.apify.com/docs/guides/getting-started?__hsfp=1136113150&__hssc=7591405.1.173549427712`
216
+ *
217
+ * Such links are treated as *different*, which will make the crawler favor browser rendering for those pages.
218
+ *
219
+ * **Example usage:**
220
+ * ```ts
221
+ * const crawler = new AdaptivePlaywrightCrawler({
222
+ * resultComparator: fullResultComparator,
223
+ * async requestHandler({ pushData, enqueueLinks }) {
224
+ * // ...
225
+ * },
226
+ * });
227
+ * ```
228
+ */
229
+ export declare function fullResultComparator(resultA: StorageTransactionView, resultB: StorageTransactionView): boolean;
176
230
  export {};
177
- //# sourceMappingURL=adaptive-playwright-crawler.d.ts.map