@crawlee/playwright 4.0.0-beta.9 → 4.0.0-beta.91
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.
- package/README.md +17 -13
- package/index.d.ts +1 -2
- package/index.js +0 -1
- package/internals/adaptive-playwright-crawler.d.ts +117 -63
- package/internals/adaptive-playwright-crawler.js +354 -214
- package/internals/enqueue-links/click-elements.d.ts +32 -14
- package/internals/enqueue-links/click-elements.js +57 -25
- package/internals/playwright-crawler.d.ts +104 -83
- package/internals/playwright-crawler.js +85 -41
- package/internals/playwright-launcher.d.ts +6 -5
- package/internals/playwright-launcher.js +10 -11
- package/internals/utils/playwright-utils.d.ts +58 -21
- package/internals/utils/playwright-utils.js +99 -86
- package/internals/utils/rendering-type-prediction.d.ts +27 -12
- package/internals/utils/rendering-type-prediction.js +67 -26
- package/package.json +16 -11
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/internals/adaptive-playwright-crawler.d.ts.map +0 -1
- package/internals/adaptive-playwright-crawler.js.map +0 -1
- package/internals/enqueue-links/click-elements.d.ts.map +0 -1
- package/internals/enqueue-links/click-elements.js.map +0 -1
- package/internals/playwright-crawler.d.ts.map +0 -1
- package/internals/playwright-crawler.js.map +0 -1
- package/internals/playwright-launcher.d.ts.map +0 -1
- package/internals/playwright-launcher.js.map +0 -1
- package/internals/utils/playwright-utils.d.ts.map +0 -1
- package/internals/utils/playwright-utils.js.map +0 -1
- package/internals/utils/rendering-type-prediction.d.ts.map +0 -1
- package/internals/utils/rendering-type-prediction.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,19 +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://
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
</p>
|
|
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" /></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>
|
|
17
21
|
</p>
|
|
18
22
|
|
|
19
23
|
Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
|
|
@@ -24,7 +28,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
|
|
|
24
28
|
|
|
25
29
|
> 👉 **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)** 👈
|
|
26
30
|
|
|
27
|
-
>
|
|
31
|
+
> Do you prefer 🐍 Python instead of JavaScript? [👉 Checkout Crawlee for Python 👈](https://github.com/apify/crawlee-python).
|
|
28
32
|
|
|
29
33
|
## Installation
|
|
30
34
|
|
|
@@ -85,7 +89,7 @@ By default, Crawlee stores data to `./storage` in the current working directory.
|
|
|
85
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:
|
|
86
90
|
|
|
87
91
|
```bash
|
|
88
|
-
npm install crawlee@
|
|
92
|
+
npm install crawlee@next
|
|
89
93
|
```
|
|
90
94
|
|
|
91
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:
|
|
@@ -94,9 +98,9 @@ If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need
|
|
|
94
98
|
{
|
|
95
99
|
"overrides": {
|
|
96
100
|
"apify": {
|
|
97
|
-
"@crawlee/core": "
|
|
98
|
-
"@crawlee/types": "
|
|
99
|
-
"@crawlee/utils": "
|
|
101
|
+
"@crawlee/core": "$crawlee",
|
|
102
|
+
"@crawlee/types": "$crawlee",
|
|
103
|
+
"@crawlee/utils": "$crawlee"
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
}
|
package/index.d.ts
CHANGED
|
@@ -6,5 +6,4 @@ export { RenderingTypePredictor } from './internals/utils/rendering-type-predict
|
|
|
6
6
|
export * as playwrightUtils from './internals/utils/playwright-utils.js';
|
|
7
7
|
export * as playwrightClickElements from './internals/enqueue-links/click-elements.js';
|
|
8
8
|
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
|
|
9
|
+
export type { IRenderingTypePredictor, RenderingType } from './internals/utils/rendering-type-prediction.js';
|
package/index.js
CHANGED
|
@@ -5,4 +5,3 @@ export * from './internals/adaptive-playwright-crawler.js';
|
|
|
5
5
|
export { RenderingTypePredictor } from './internals/utils/rendering-type-prediction.js';
|
|
6
6
|
export * as playwrightUtils from './internals/utils/playwright-utils.js';
|
|
7
7
|
export * as playwrightClickElements from './internals/enqueue-links/click-elements.js';
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import type { BrowserHook,
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
1
|
+
import type { BrowserHook, LoadedRequest, Request, RouterHandler, RouteSchemas, RoutesFromSchemas } from '@crawlee/browser';
|
|
2
|
+
import type { BasicCrawlerOptions } from '@crawlee/basic';
|
|
3
|
+
import { BasicCrawler } from '@crawlee/basic';
|
|
4
|
+
import type { ContextPipeline, CrawlingContext, EnqueueLinksOptions, GetUserDataFromRequest, RouterRoutes, StatisticsOptions, StatisticState } from '@crawlee/core';
|
|
5
|
+
import { RequestHandlerResult, Statistics } from '@crawlee/core';
|
|
6
|
+
import type { Dictionary, Awaitable } from '@crawlee/types';
|
|
5
7
|
import { type CheerioRoot } from '@crawlee/utils';
|
|
6
8
|
import { type Cheerio } from 'cheerio';
|
|
9
|
+
import type { AnyNode } from 'domhandler';
|
|
7
10
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
8
11
|
import type { Page } from 'playwright';
|
|
9
|
-
import type {
|
|
10
|
-
import
|
|
11
|
-
import { PlaywrightCrawler } from './playwright-crawler.js';
|
|
12
|
-
import { RenderingTypePredictor } from './utils/rendering-type-prediction.js';
|
|
13
|
-
type Result<TResult> = {
|
|
14
|
-
result: TResult;
|
|
15
|
-
ok: true;
|
|
16
|
-
logs?: LogProxyCall[];
|
|
17
|
-
} | {
|
|
18
|
-
error: unknown;
|
|
19
|
-
ok: false;
|
|
20
|
-
logs?: LogProxyCall[];
|
|
21
|
-
};
|
|
12
|
+
import type { PlaywrightCrawlingContext, PlaywrightGotoOptions } from './playwright-crawler.js';
|
|
13
|
+
import { type IRenderingTypePredictor } from './utils/rendering-type-prediction.js';
|
|
22
14
|
interface AdaptivePlaywrightCrawlerStatisticState extends StatisticState {
|
|
23
15
|
httpOnlyRequestHandlerRuns?: number;
|
|
24
16
|
browserRequestHandlerRuns?: number;
|
|
@@ -28,25 +20,31 @@ declare class AdaptivePlaywrightCrawlerStatistics extends Statistics {
|
|
|
28
20
|
state: AdaptivePlaywrightCrawlerStatisticState;
|
|
29
21
|
constructor(options?: StatisticsOptions);
|
|
30
22
|
reset(): void;
|
|
31
|
-
protected
|
|
23
|
+
protected maybeLoadStatistics(): Promise<void>;
|
|
32
24
|
trackHttpOnlyRequestHandlerRun(): void;
|
|
33
25
|
trackBrowserRequestHandlerRun(): void;
|
|
34
26
|
trackRenderingTypeMisprediction(): void;
|
|
35
27
|
}
|
|
36
|
-
export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary = Dictionary> extends
|
|
28
|
+
export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary = Dictionary> extends CrawlingContext<UserData> {
|
|
29
|
+
request: LoadedRequest<Request<UserData>>;
|
|
37
30
|
/**
|
|
38
31
|
* The HTTP response, either from the HTTP client or from the initial request from playwright's navigation.
|
|
39
32
|
*/
|
|
40
|
-
response:
|
|
33
|
+
response: Response;
|
|
41
34
|
/**
|
|
42
35
|
* Playwright Page object. If accessed in HTTP-only rendering, this will throw an error and make the AdaptivePlaywrightCrawlerContext retry the request in a browser.
|
|
43
36
|
*/
|
|
44
37
|
page: Page;
|
|
45
38
|
/**
|
|
46
|
-
* Wait for an element matching the selector to appear and return a Cheerio object of matched
|
|
39
|
+
* Wait for an element matching the selector to appear and return a Cheerio object of the first matched element.
|
|
47
40
|
* Timeout defaults to 5s.
|
|
48
41
|
*/
|
|
49
|
-
querySelector
|
|
42
|
+
querySelector(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
|
|
43
|
+
/**
|
|
44
|
+
* Wait for an element matching the selector to appear and return a Cheerio object of all matched elements.
|
|
45
|
+
* Timeout defaults to 5s.
|
|
46
|
+
*/
|
|
47
|
+
querySelectorAll(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
|
|
50
48
|
/**
|
|
51
49
|
* Wait for an element matching the selector to appear.
|
|
52
50
|
* Timeout defaults to 5s.
|
|
@@ -74,36 +72,36 @@ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary =
|
|
|
74
72
|
* ```
|
|
75
73
|
*/
|
|
76
74
|
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioRoot>;
|
|
75
|
+
enqueueLinks(options?: EnqueueLinksOptions): Promise<unknown>;
|
|
77
76
|
}
|
|
78
|
-
interface
|
|
77
|
+
interface AdaptiveHookContext extends Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log'> {
|
|
79
78
|
page?: Page;
|
|
80
|
-
|
|
79
|
+
request: Request;
|
|
80
|
+
gotoOptions?: PlaywrightGotoOptions;
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* other than the methods of the crawling context. Any other side effects may be invoked repeatedly by the crawler, which can lead to inconsistent results.
|
|
88
|
-
*
|
|
89
|
-
* The function must return a promise, which is then awaited by the crawler.
|
|
90
|
-
*
|
|
91
|
-
* If the function throws an exception, the crawler will try to re-crawl the
|
|
92
|
-
* request later, up to `option.maxRequestRetries` times.
|
|
93
|
-
*/
|
|
94
|
-
requestHandler?: (crawlingContext: LoadedContext<AdaptivePlaywrightCrawlerContext>) => Awaitable<void>;
|
|
82
|
+
type AdaptiveHook<ContextExtension = Dictionary<never>> = BrowserHook<AdaptiveHookContext, ContextExtension>;
|
|
83
|
+
type AdaptivePostNavigationHook<ContextExtension = Dictionary<never>> = BrowserHook<Omit<AdaptiveHookContext, 'request'> & {
|
|
84
|
+
request: LoadedRequest<Request>;
|
|
85
|
+
}, ContextExtension>;
|
|
86
|
+
export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes>, 'preNavigationHooks' | 'postNavigationHooks'> {
|
|
95
87
|
/**
|
|
96
88
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies.
|
|
97
89
|
* The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
|
|
98
90
|
* an exception will be thrown. If it's not caught, the request will be transparently retried in a browser.
|
|
91
|
+
*
|
|
92
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
93
|
+
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
99
94
|
*/
|
|
100
|
-
preNavigationHooks?: AdaptiveHook[];
|
|
95
|
+
preNavigationHooks?: AdaptiveHook<ContextExtension>[];
|
|
101
96
|
/**
|
|
102
97
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
103
98
|
* The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
|
|
104
99
|
* an exception will be thrown. If it's not caught, the request will be transparently retried in a browser.
|
|
100
|
+
*
|
|
101
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context
|
|
102
|
+
* (e.g. to override `response` after solving a challenge).
|
|
105
103
|
*/
|
|
106
|
-
postNavigationHooks?:
|
|
104
|
+
postNavigationHooks?: AdaptivePostNavigationHook<ContextExtension>[];
|
|
107
105
|
/**
|
|
108
106
|
* Specifies the frequency of rendering type detection checks - 0.1 means roughly 10% of requests.
|
|
109
107
|
* Defaults to 0.1 (so 10%).
|
|
@@ -115,25 +113,41 @@ export interface AdaptivePlaywrightCrawlerOptions extends Omit<PlaywrightCrawler
|
|
|
115
113
|
* If no callback is specified, every dataset item is considered valid.
|
|
116
114
|
*/
|
|
117
115
|
resultChecker?: (result: RequestHandlerResult) => boolean;
|
|
116
|
+
/**
|
|
117
|
+
* An optional callback that decides whether an error thrown during the plain HTTP request handler
|
|
118
|
+
* should be propagated (instead of falling back to browser navigation).
|
|
119
|
+
*
|
|
120
|
+
* If the callback returns `true`, the error is thrown, triggering the standard retry mechanism.
|
|
121
|
+
* If the callback returns `false` (or is not provided), the error is logged and the crawler
|
|
122
|
+
* falls back to browser navigation (default behavior).
|
|
123
|
+
*
|
|
124
|
+
* @default () => false
|
|
125
|
+
*/
|
|
126
|
+
shouldPropagateError?: (error: Error, context: PlaywrightCrawlingContext) => Awaitable<boolean>;
|
|
118
127
|
/**
|
|
119
128
|
* 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.
|
|
120
|
-
* If
|
|
129
|
+
* If a callback is provided, the contract is as follows:
|
|
130
|
+
* It the callback returns true or 'equal', the results are considered equal and the target site is considered static.
|
|
131
|
+
* If it returns false or 'different', the target site is considered client-rendered.
|
|
132
|
+
* If it returns 'inconclusive', the detection result won't be used.
|
|
121
133
|
* If no result comparator is specified, but there is a `resultChecker`, any site where the `resultChecker` returns true is considered static.
|
|
122
134
|
* If neither `resultComparator` nor `resultChecker` are specified, a deep comparison of returned dataset items is used as a default.
|
|
135
|
+
*
|
|
136
|
+
* For a stricter, ready-made comparator that also takes enqueued requests and key-value store changes into account, see {@link fullResultComparator}.
|
|
123
137
|
*/
|
|
124
|
-
resultComparator?: (resultA: RequestHandlerResult, resultB: RequestHandlerResult) => boolean;
|
|
138
|
+
resultComparator?: (resultA: RequestHandlerResult, resultB: RequestHandlerResult) => boolean | 'equal' | 'different' | 'inconclusive';
|
|
125
139
|
/**
|
|
126
|
-
* A custom rendering type predictor
|
|
140
|
+
* A custom rendering type predictor. A predictor passed here is borrowed - the crawler never drives its
|
|
141
|
+
* lifecycle, so set it up yourself (the built-in {@link RenderingTypePredictor} needs `initialize()`).
|
|
142
|
+
* Omit the option and the crawler builds its own from `renderingTypeDetectionRatio` - and initializes it.
|
|
127
143
|
*/
|
|
128
|
-
renderingTypePredictor?:
|
|
144
|
+
renderingTypePredictor?: IRenderingTypePredictor;
|
|
129
145
|
/**
|
|
130
146
|
* Prevent direct access to storage in request handlers (only allow using context helpers).
|
|
131
147
|
* Defaults to `true`
|
|
132
148
|
*/
|
|
133
149
|
preventDirectStorageAccess?: boolean;
|
|
134
150
|
}
|
|
135
|
-
declare const proxyLogMethods: readonly ["error", "exception", "softFail", "info", "debug", "perf", "warningOnce", "deprecated"];
|
|
136
|
-
type LogProxyCall = [log: Log, method: (typeof proxyLogMethods)[number], ...args: unknown[]];
|
|
137
151
|
/**
|
|
138
152
|
* 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.
|
|
139
153
|
*
|
|
@@ -163,31 +177,71 @@ type LogProxyCall = [log: Log, method: (typeof proxyLogMethods)[number], ...args
|
|
|
163
177
|
*
|
|
164
178
|
* @experimental
|
|
165
179
|
*/
|
|
166
|
-
export declare class AdaptivePlaywrightCrawler extends
|
|
167
|
-
readonly config: Configuration;
|
|
168
|
-
private adaptiveRequestHandler;
|
|
180
|
+
export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes> {
|
|
169
181
|
private renderingTypePredictor;
|
|
170
182
|
private resultChecker;
|
|
183
|
+
private shouldPropagateError;
|
|
171
184
|
private resultComparator;
|
|
172
185
|
private preventDirectStorageAccess;
|
|
186
|
+
private staticContextPipeline;
|
|
187
|
+
private browserContextPipeline;
|
|
188
|
+
private individualRequestHandlerTimeoutMillis;
|
|
173
189
|
readonly stats: AdaptivePlaywrightCrawlerStatistics;
|
|
190
|
+
private resultObjects;
|
|
191
|
+
private inFlightRenderingTypeDetections;
|
|
192
|
+
private teardownHooks;
|
|
193
|
+
constructor(options?: AdaptivePlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes>);
|
|
194
|
+
protected _init(): Promise<void>;
|
|
195
|
+
protected buildContextPipeline(): ContextPipeline<CrawlingContext<Dictionary>, CrawlingContext<Dictionary> & {
|
|
196
|
+
readonly request: LoadedRequest<Request<Dictionary>>;
|
|
197
|
+
readonly response: Response;
|
|
198
|
+
readonly page: Page;
|
|
199
|
+
readonly querySelector: AdaptivePlaywrightCrawlerContext["querySelector"];
|
|
200
|
+
readonly querySelectorAll: AdaptivePlaywrightCrawlerContext["querySelectorAll"];
|
|
201
|
+
readonly waitForSelector: AdaptivePlaywrightCrawlerContext["waitForSelector"];
|
|
202
|
+
readonly parseWithCheerio: AdaptivePlaywrightCrawlerContext["parseWithCheerio"];
|
|
203
|
+
}>;
|
|
204
|
+
private adaptCheerioContext;
|
|
205
|
+
private adaptPlaywrightContext;
|
|
206
|
+
private crawlOne;
|
|
207
|
+
protected runRequestHandler(crawlingContext: CrawlingContext): Promise<void>;
|
|
208
|
+
private commitResult;
|
|
209
|
+
private allowStorageAccess;
|
|
174
210
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
211
|
+
* Reading the pending request count queries the underlying request manager, which counts as storage access.
|
|
212
|
+
* Since this is internal crawler bookkeeping used to compute the `enqueueLinks` limit (not user-initiated storage
|
|
213
|
+
* access), it must be allowed even while a request handler runs inside the storage-access guard.
|
|
177
214
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
constructor(options?: AdaptivePlaywrightCrawlerOptions, config?: Configuration);
|
|
181
|
-
protected _runRequestHandler(crawlingContext: PlaywrightCrawlingContext): Promise<void>;
|
|
182
|
-
protected commitResult(crawlingContext: PlaywrightCrawlingContext, { calls, keyValueStoreChanges }: RequestHandlerResult): Promise<void>;
|
|
183
|
-
protected allowStorageAccess<R, TArgs extends any[]>(func: (...args: TArgs) => Promise<R>): (...args: TArgs) => Promise<R>;
|
|
184
|
-
protected runRequestHandlerInBrowser(crawlingContext: PlaywrightCrawlingContext): Promise<{
|
|
185
|
-
result: Result<RequestHandlerResult>;
|
|
186
|
-
initialStateCopy?: Record<string, unknown>;
|
|
187
|
-
}>;
|
|
188
|
-
protected runRequestHandlerWithPlainHTTP(crawlingContext: PlaywrightCrawlingContext, oldStateCopy?: Dictionary): Promise<Result<RequestHandlerResult>>;
|
|
215
|
+
protected getPendingRequestCountApproximation(): Promise<number>;
|
|
216
|
+
private enqueueLinks;
|
|
189
217
|
private createLogProxy;
|
|
218
|
+
teardown(): Promise<void>;
|
|
190
219
|
}
|
|
191
|
-
export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext,
|
|
220
|
+
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>;
|
|
221
|
+
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>>;
|
|
222
|
+
export declare function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|
|
223
|
+
/**
|
|
224
|
+
* An opt-in {@link AdaptivePlaywrightCrawlerOptions.resultComparator|`resultComparator`} that considers two
|
|
225
|
+
* request handler results equal only if *all* of their observable effects match - the pushed dataset items, the
|
|
226
|
+
* enqueued requests, and the key-value store changes. This is stricter than the default comparator, which only
|
|
227
|
+
* compares dataset items.
|
|
228
|
+
*
|
|
229
|
+
* **Beware:** enqueued URLs are compared exactly. The same page rendered in a browser and via plain HTTP often
|
|
230
|
+
* yields links that differ only in tracking query parameters, for example:
|
|
231
|
+
* - `https://sdk.apify.com/docs/guides/getting-started`
|
|
232
|
+
* - `https://sdk.apify.com/docs/guides/getting-started?__hsfp=1136113150&__hssc=7591405.1.173549427712`
|
|
233
|
+
*
|
|
234
|
+
* Such links are treated as *different*, which will make the crawler favor browser rendering for those pages.
|
|
235
|
+
*
|
|
236
|
+
* **Example usage:**
|
|
237
|
+
* ```ts
|
|
238
|
+
* const crawler = new AdaptivePlaywrightCrawler({
|
|
239
|
+
* resultComparator: fullResultComparator,
|
|
240
|
+
* async requestHandler({ pushData, enqueueLinks }) {
|
|
241
|
+
* // ...
|
|
242
|
+
* },
|
|
243
|
+
* });
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export declare function fullResultComparator(resultA: RequestHandlerResult, resultB: RequestHandlerResult): boolean;
|
|
192
247
|
export {};
|
|
193
|
-
//# sourceMappingURL=adaptive-playwright-crawler.d.ts.map
|