@crawlee/playwright 4.0.0-beta.3 → 4.0.0-beta.300
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 +18 -14
- package/index.d.ts +4 -3
- package/index.js +2 -2
- package/internals/adaptive-playwright-crawler.d.ts +149 -94
- package/internals/adaptive-playwright-crawler.js +561 -274
- package/internals/enqueue-links/click-elements.d.ts +37 -55
- package/internals/enqueue-links/click-elements.js +65 -55
- package/internals/playwright-browser-pool.d.ts +55 -0
- package/internals/playwright-browser-pool.js +34 -0
- package/internals/playwright-crawler.d.ts +184 -172
- package/internals/playwright-crawler.js +125 -60
- package/internals/playwright-launcher.d.ts +30 -20
- package/internals/playwright-launcher.js +24 -18
- package/internals/utils/playwright-utils.d.ts +74 -48
- package/internals/utils/playwright-utils.js +159 -158
- package/internals/utils/rendering-type-prediction.d.ts +41 -16
- package/internals/utils/rendering-type-prediction.js +101 -37
- package/package.json +19 -18
- 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
|
@@ -1,100 +1,49 @@
|
|
|
1
|
-
import type { BrowserCrawlerOptions, BrowserCrawlingContext, BrowserHook,
|
|
2
|
-
import { BrowserCrawler
|
|
3
|
-
import type { PlaywrightController, PlaywrightPlugin } from '@crawlee/browser-pool';
|
|
1
|
+
import type { BrowserCrawlerOptions, BrowserCrawlingContext, BrowserHook, GetUserDataFromRequest, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/browser';
|
|
2
|
+
import { BrowserCrawler } from '@crawlee/browser';
|
|
4
3
|
import type { Dictionary } from '@crawlee/types';
|
|
5
4
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
6
|
-
import type {
|
|
5
|
+
import type { Page, Response } from 'playwright';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { type PlaywrightRemoteBrowserOptions } from './playwright-browser-pool.js';
|
|
7
8
|
import type { PlaywrightLaunchContext } from './playwright-launcher.js';
|
|
8
|
-
import type { DirectNavigationOptions, PlaywrightContextUtils } from './utils/playwright-utils.js';
|
|
9
|
-
export
|
|
9
|
+
import type { DirectNavigationOptions, HandleCloudflareChallengeOptions, PlaywrightContextUtils } from './utils/playwright-utils.js';
|
|
10
|
+
export type PlaywrightGotoOptions = NonNullable<Parameters<Page['goto']>[1]>;
|
|
11
|
+
export interface PlaywrightCrawlingContext<UserData extends Dictionary = any> extends BrowserCrawlingContext<Page, Response, UserData, PlaywrightGotoOptions>, PlaywrightContextUtils {
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
export interface
|
|
13
|
-
}
|
|
14
|
-
export interface PlaywrightRequestHandler extends BrowserRequestHandler<LoadedContext<PlaywrightCrawlingContext>> {
|
|
15
|
-
}
|
|
16
|
-
export type PlaywrightGotoOptions = Parameters<Page['goto']>[1];
|
|
17
|
-
export interface PlaywrightCrawlerOptions extends BrowserCrawlerOptions<PlaywrightCrawlingContext, {
|
|
18
|
-
browserPlugins: [PlaywrightPlugin];
|
|
19
|
-
}> {
|
|
13
|
+
export type PlaywrightHook<UserData extends Dictionary = any> = BrowserHook<PlaywrightCrawlingContext<UserData>>;
|
|
14
|
+
export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<PlaywrightCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends BrowserCrawlerOptions<Page, Response, PlaywrightCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
20
15
|
/**
|
|
21
16
|
* The same options as used by {@link launchPlaywright}.
|
|
22
17
|
*/
|
|
23
18
|
launchContext?: PlaywrightLaunchContext;
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* The function receives the {@link PlaywrightCrawlingContext} as an argument, where:
|
|
28
|
-
* - `request` is an instance of the {@link Request} object with details about the URL to open, HTTP method etc.
|
|
29
|
-
* - `page` is an instance of the `Playwright`
|
|
30
|
-
* [`Page`](https://playwright.dev/docs/api/class-page)
|
|
31
|
-
* - `browserController` is an instance of the
|
|
32
|
-
* [`BrowserController`](https://github.com/apify/browser-pool#browsercontroller),
|
|
33
|
-
* - `response` is an instance of the `Playwright`
|
|
34
|
-
* [`Response`](https://playwright.dev/docs/api/class-response),
|
|
35
|
-
* which is the main resource response as returned by `page.goto(request.url)`.
|
|
36
|
-
*
|
|
37
|
-
* The function must return a promise, which is then awaited by the crawler.
|
|
38
|
-
*
|
|
39
|
-
* If the function throws an exception, the crawler will try to re-crawl the
|
|
40
|
-
* request later, up to `option.maxRequestRetries` times.
|
|
41
|
-
* If all the retries fail, the crawler calls the function
|
|
42
|
-
* provided to the `failedRequestHandler` parameter.
|
|
43
|
-
* To make this work, you should **always**
|
|
44
|
-
* let your function throw exceptions rather than catch them.
|
|
45
|
-
* The exceptions are logged to the request using the
|
|
46
|
-
* {@link Request.pushErrorMessage} function.
|
|
20
|
+
* Whether to run browser in headless mode. Defaults to `true`.
|
|
21
|
+
* Can be also set via {@link Configuration}.
|
|
47
22
|
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
* The function receives the {@link PlaywrightCrawlingContext} as an argument, where:
|
|
53
|
-
* - `request` is an instance of the {@link Request} object with details about the URL to open, HTTP method etc.
|
|
54
|
-
* - `page` is an instance of the `Playwright`
|
|
55
|
-
* [`Page`](https://playwright.dev/docs/api/class-page)
|
|
56
|
-
* - `browserController` is an instance of the
|
|
57
|
-
* [`BrowserController`](https://github.com/apify/browser-pool#browsercontroller),
|
|
58
|
-
* - `response` is an instance of the `Playwright`
|
|
59
|
-
* [`Response`](https://playwright.dev/docs/api/class-response),
|
|
60
|
-
* which is the main resource response as returned by `page.goto(request.url)`.
|
|
61
|
-
*
|
|
62
|
-
* The function must return a promise, which is then awaited by the crawler.
|
|
63
|
-
*
|
|
64
|
-
* If the function throws an exception, the crawler will try to re-crawl the
|
|
65
|
-
* request later, up to `option.maxRequestRetries` times.
|
|
66
|
-
* If all the retries fail, the crawler calls the function
|
|
67
|
-
* provided to the `failedRequestHandler` parameter.
|
|
68
|
-
* To make this work, you should **always**
|
|
69
|
-
* let your function throw exceptions rather than catch them.
|
|
70
|
-
* The exceptions are logged to the request using the
|
|
71
|
-
* {@link Request.pushErrorMessage} function.
|
|
72
|
-
*
|
|
73
|
-
* @deprecated `handlePageFunction` has been renamed to `requestHandler` and will be removed in a future version.
|
|
74
|
-
* @ignore
|
|
75
|
-
*/
|
|
76
|
-
handlePageFunction?: PlaywrightRequestHandler;
|
|
23
|
+
headless?: boolean;
|
|
24
|
+
/** See {@link BrowserCrawlerOptions.remoteBrowser}; Playwright additionally lets you pick the `protocol`. */
|
|
25
|
+
remoteBrowser?: PlaywrightRemoteBrowserOptions;
|
|
77
26
|
/**
|
|
78
27
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
79
|
-
* or browser properties before navigation. The function
|
|
80
|
-
*
|
|
28
|
+
* or browser properties before navigation. The function receives the `crawlingContext`; the options object
|
|
29
|
+
* forwarded to `page.goto()` is available as `crawlingContext.gotoOptions` and can be mutated in place.
|
|
30
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context
|
|
31
|
+
* (e.g. to override context members for subsequent hooks and pipeline stages).
|
|
81
32
|
* Example:
|
|
82
33
|
* ```
|
|
83
34
|
* preNavigationHooks: [
|
|
84
|
-
* async (
|
|
85
|
-
* const { page } = crawlingContext;
|
|
35
|
+
* async ({ page, gotoOptions }) => {
|
|
86
36
|
* await page.evaluate((attr) => { window.foo = attr; }, 'bar');
|
|
37
|
+
* gotoOptions.timeout = 60_000;
|
|
87
38
|
* },
|
|
88
39
|
* ]
|
|
89
40
|
* ```
|
|
90
|
-
*
|
|
91
|
-
* Modyfing `pageOptions` is supported only in Playwright incognito.
|
|
92
|
-
* See {@link PrePageCreateHook}
|
|
93
41
|
*/
|
|
94
|
-
preNavigationHooks?:
|
|
42
|
+
preNavigationHooks?: BrowserHook<PlaywrightCrawlingContext<GetUserDataFromRequest<ExtendedContext['request']>>, ContextExtension>[];
|
|
95
43
|
/**
|
|
96
44
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
97
|
-
* The function accepts `crawlingContext` as the only parameter.
|
|
45
|
+
* The function accepts `crawlingContext` as the only parameter. A hook may optionally return a partial object
|
|
46
|
+
* whose properties are merged into the crawling context (e.g. to override `response` after solving a challenge).
|
|
98
47
|
* Example:
|
|
99
48
|
* ```
|
|
100
49
|
* postNavigationHooks: [
|
|
@@ -107,7 +56,7 @@ export interface PlaywrightCrawlerOptions extends BrowserCrawlerOptions<Playwrig
|
|
|
107
56
|
* ]
|
|
108
57
|
* ```
|
|
109
58
|
*/
|
|
110
|
-
postNavigationHooks?:
|
|
59
|
+
postNavigationHooks?: BrowserHook<PlaywrightCrawlingContext<GetUserDataFromRequest<ExtendedContext['request']>>, ContextExtension>[];
|
|
111
60
|
}
|
|
112
61
|
/**
|
|
113
62
|
* Provides a simple framework for parallel crawling of web pages
|
|
@@ -120,24 +69,26 @@ export interface PlaywrightCrawlerOptions extends BrowserCrawlerOptions<Playwrig
|
|
|
120
69
|
* If the target website doesn't need JavaScript, consider using {@link CheerioCrawler},
|
|
121
70
|
* which downloads the pages using raw HTTP requests and is about 10x faster.
|
|
122
71
|
*
|
|
123
|
-
* The source URLs are represented using {@link Request} objects that are fed from
|
|
124
|
-
* {@link
|
|
125
|
-
*
|
|
72
|
+
* The source URLs are represented using {@link Request} objects that are fed from the
|
|
73
|
+
* {@link IRequestManager|request manager} provided via the {@link PlaywrightCrawlerOptions.requestManager|`requestManager`}
|
|
74
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). To read from a read-only source such
|
|
75
|
+
* as a {@link RequestList} while still being able to enqueue new requests, combine it with a queue into a
|
|
76
|
+
* {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`} and pass the
|
|
77
|
+
* result as `requestManager`.
|
|
126
78
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
|
|
79
|
+
* > The {@link PlaywrightCrawlerOptions.requestList|`requestList`} and {@link PlaywrightCrawlerOptions.requestQueue|`requestQueue`}
|
|
80
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
130
81
|
*
|
|
131
82
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
132
83
|
*
|
|
133
84
|
* `PlaywrightCrawler` opens a new Chrome page (i.e. tab) for each {@link Request} object to crawl
|
|
134
85
|
* and then calls the function provided by user as the {@link PlaywrightCrawlerOptions.requestHandler} option.
|
|
135
86
|
*
|
|
136
|
-
* New pages are only opened when there is enough free CPU and memory available,
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* {@link
|
|
87
|
+
* New pages are only opened when there is enough free CPU and memory available, as judged by the crawler's
|
|
88
|
+
* {@link ConcurrencySystem}.
|
|
89
|
+
* Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
|
|
90
|
+
* `PlaywrightCrawler` constructor, or, for finer control, by injecting a pre-configured
|
|
91
|
+
* {@link ConcurrencySystem|`concurrencySystem`}.
|
|
141
92
|
*
|
|
142
93
|
* Note that the pool of Playwright instances is internally managed by the [BrowserPool](https://github.com/apify/browser-pool) class.
|
|
143
94
|
*
|
|
@@ -172,94 +123,155 @@ export interface PlaywrightCrawlerOptions extends BrowserCrawlerOptions<Playwrig
|
|
|
172
123
|
* ```
|
|
173
124
|
* @category Crawlers
|
|
174
125
|
*/
|
|
175
|
-
export declare class PlaywrightCrawler extends BrowserCrawler<{
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
126
|
+
export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<PlaywrightCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends BrowserCrawler<Page, Response, PlaywrightCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
127
|
+
#private;
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
180
131
|
protected static optionsShape: {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
212
|
-
|
|
213
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
239
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
240
|
-
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
241
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
242
|
-
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
243
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
244
|
-
maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
245
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
246
|
-
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
247
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
248
|
-
keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
249
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
250
|
-
log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
251
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
252
|
-
experiments: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
253
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
254
|
-
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
132
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
133
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
134
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
135
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
136
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
137
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
138
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
139
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
140
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
141
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
142
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
143
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
144
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
145
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
146
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
147
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
148
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
149
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
150
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
151
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
152
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
153
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
154
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
155
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
156
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
157
|
+
deferred: "deferred";
|
|
158
|
+
writeThrough: "writeThrough";
|
|
159
|
+
}>>;
|
|
160
|
+
}, z.core.$strict>]>>;
|
|
161
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
162
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
163
|
+
httpClient: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/http-client").BaseHttpClient>>;
|
|
164
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
165
|
+
configuration: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").Configuration>>;
|
|
166
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
167
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
168
|
+
eventManager: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").EventManager>>;
|
|
169
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
170
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
171
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
172
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
173
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
174
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
175
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
176
|
+
id: z.ZodOptional<z.ZodString>;
|
|
177
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
178
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
179
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
180
|
+
browserPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
181
|
+
browserPoolBuilder: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
182
|
+
remoteBrowser: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
183
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
184
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
185
|
+
ignoreIframes: z.ZodDefault<z.ZodBoolean>;
|
|
186
|
+
ignoreShadowRoots: z.ZodDefault<z.ZodBoolean>;
|
|
187
|
+
launchContext: z.ZodDefault<z.ZodCustom<Dictionary, Dictionary>>;
|
|
188
|
+
headless: z.ZodOptional<z.ZodBoolean>;
|
|
255
189
|
};
|
|
190
|
+
/** @internal */
|
|
191
|
+
protected static optionsSchema: z.ZodObject<{
|
|
192
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
193
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
194
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
195
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
196
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
197
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
198
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
199
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
200
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
201
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
202
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
203
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
204
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
205
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
206
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
207
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
208
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
209
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
210
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
211
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
212
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
213
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
214
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
215
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
216
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
217
|
+
deferred: "deferred";
|
|
218
|
+
writeThrough: "writeThrough";
|
|
219
|
+
}>>;
|
|
220
|
+
}, z.core.$strict>]>>;
|
|
221
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
222
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
223
|
+
httpClient: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/http-client").BaseHttpClient>>;
|
|
224
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
225
|
+
configuration: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").Configuration>>;
|
|
226
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
227
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
228
|
+
eventManager: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").EventManager>>;
|
|
229
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
230
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
231
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
232
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
233
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
234
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
235
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
236
|
+
id: z.ZodOptional<z.ZodString>;
|
|
237
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
238
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
239
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
240
|
+
browserPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
241
|
+
browserPoolBuilder: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
242
|
+
remoteBrowser: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
243
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
244
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
245
|
+
ignoreIframes: z.ZodDefault<z.ZodBoolean>;
|
|
246
|
+
ignoreShadowRoots: z.ZodDefault<z.ZodBoolean>;
|
|
247
|
+
launchContext: z.ZodDefault<z.ZodCustom<Dictionary, Dictionary>>;
|
|
248
|
+
headless: z.ZodOptional<z.ZodBoolean>;
|
|
249
|
+
}, z.core.$strict>;
|
|
256
250
|
/**
|
|
257
251
|
* All `PlaywrightCrawler` parameters are passed via an options object.
|
|
258
252
|
*/
|
|
259
|
-
constructor(options?: PlaywrightCrawlerOptions,
|
|
260
|
-
protected
|
|
261
|
-
protected _navigationHandler(crawlingContext: PlaywrightCrawlingContext, gotoOptions: DirectNavigationOptions): Promise<Response | null>;
|
|
253
|
+
constructor(options?: PlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes, StatisticStateExtension>);
|
|
254
|
+
protected navigationHandler(crawlingContext: PlaywrightCrawlingContext, gotoOptions: DirectNavigationOptions): Promise<Response | null>;
|
|
262
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Returns a `postNavigationHooks`-ready hook that runs {@link PlaywrightContextUtils.handleCloudflareChallenge}
|
|
258
|
+
* and propagates the post-challenge {@link Response} back into the crawling context via its return value.
|
|
259
|
+
*
|
|
260
|
+
* Cloudflare serves its challenge pages with a 403 status, which is part of the default `blockedStatusCodes`.
|
|
261
|
+
* Keep it there - the hook runs before the blocked-status check and replaces the response on a solved
|
|
262
|
+
* challenge, so solved requests pass it, while unsolved or undetected challenges keep the 403 and get
|
|
263
|
+
* retried with a fresh session.
|
|
264
|
+
*
|
|
265
|
+
* **Example usage**
|
|
266
|
+
* ```ts
|
|
267
|
+
* import { PlaywrightCrawler, handleCloudflareChallengeHook } from 'crawlee';
|
|
268
|
+
*
|
|
269
|
+
* const crawler = new PlaywrightCrawler({
|
|
270
|
+
* postNavigationHooks: [handleCloudflareChallengeHook()],
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export declare function handleCloudflareChallengeHook(options?: HandleCloudflareChallengeOptions): PlaywrightHook;
|
|
263
275
|
/**
|
|
264
276
|
* Creates new {@link Router} instance that works based on request labels.
|
|
265
277
|
* This instance can then serve as a `requestHandler` of your {@link PlaywrightCrawler}.
|
|
@@ -284,6 +296,6 @@ export declare class PlaywrightCrawler extends BrowserCrawler<{
|
|
|
284
296
|
* await crawler.run();
|
|
285
297
|
* ```
|
|
286
298
|
*/
|
|
287
|
-
|
|
288
|
-
export declare function createPlaywrightRouter<Context extends PlaywrightCrawlingContext = PlaywrightCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData
|
|
289
|
-
|
|
299
|
+
export declare function createPlaywrightRouter<Context extends PlaywrightCrawlingContext = PlaywrightCrawlingContext, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>>(routes?: RouterRoutes<Context, Routes>): RouterHandler<Context, Routes>;
|
|
300
|
+
export declare function createPlaywrightRouter<Context extends PlaywrightCrawlingContext = PlaywrightCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, Record<string, UserData>>): RouterHandler<Context, Record<string, UserData>>;
|
|
301
|
+
export declare function createPlaywrightRouter<Context extends PlaywrightCrawlingContext = PlaywrightCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|