@crawlee/browser 4.0.0-beta.12 → 4.0.0-beta.120
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 +0 -1
- package/index.js +0 -1
- package/internals/browser-crawler.d.ts +145 -75
- package/internals/browser-crawler.js +283 -193
- package/internals/browser-launcher.d.ts +14 -8
- package/internals/browser-launcher.js +14 -14
- package/package.json +8 -8
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/internals/browser-crawler.d.ts.map +0 -1
- package/internals/browser-crawler.js.map +0 -1
- package/internals/browser-launcher.d.ts.map +0 -1
- package/internals/browser-launcher.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
package/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { BasicCrawler,
|
|
3
|
-
import type { BrowserController, BrowserPlugin, BrowserPoolHooks, BrowserPoolOptions, CommonPage, InferBrowserPluginArray, LaunchContext } from '@crawlee/browser-pool';
|
|
4
|
-
import {
|
|
5
|
-
import type { BatchAddRequestsResult } from '@crawlee/types';
|
|
1
|
+
import type { BasicCrawlerOptions, BasicCrawlingContext, CrawlingContext, EnqueueLinksOptions, ErrorHandler, GetUserDataFromRequest, IRequestManager, LoadedRequest, Request, RequestHandler, RouterHandler, SkippedRequestCallback } from '@crawlee/basic';
|
|
2
|
+
import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
|
|
3
|
+
import type { BrowserController, BrowserPlugin, BrowserPoolHooks, BrowserPoolOptions, CommonPage, CrawlerRemoteBrowserOptions, InferBrowserPluginArray, LaunchContext } from '@crawlee/browser-pool';
|
|
4
|
+
import type { Awaitable, BatchAddRequestsResult, Dictionary, IBrowserPool } from '@crawlee/types';
|
|
6
5
|
import type { RobotsTxtFile } from '@crawlee/utils';
|
|
7
6
|
import type { ReadonlyDeep } from 'type-fest';
|
|
8
7
|
import type { BrowserLaunchContext } from './browser-launcher.js';
|
|
9
8
|
interface BaseResponse {
|
|
10
9
|
status(): number;
|
|
10
|
+
/** Optional because only Playwright and Puppeteer responses are guaranteed to carry it. */
|
|
11
|
+
headers?(): Record<string, string>;
|
|
11
12
|
}
|
|
12
|
-
export interface BrowserCrawlingContext<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse,
|
|
13
|
-
|
|
14
|
-
* An instance of the {@link BrowserController} that manages the browser instance and provides access to its API.
|
|
15
|
-
*/
|
|
16
|
-
browserController: ProvidedController;
|
|
13
|
+
export interface BrowserCrawlingContext<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse, UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
14
|
+
GoToOptions extends Dictionary = Dictionary> extends CrawlingContext<UserData> {
|
|
17
15
|
/**
|
|
18
16
|
* The browser page object where the web page is loaded and rendered.
|
|
19
17
|
*/
|
|
@@ -26,14 +24,37 @@ export interface BrowserCrawlingContext<Page extends CommonPage = CommonPage, Re
|
|
|
26
24
|
* The HTTP response object returned by the browser's navigation.
|
|
27
25
|
*/
|
|
28
26
|
response: Response;
|
|
27
|
+
/**
|
|
28
|
+
* Options object passed to the underlying `page.goto()` call. `preNavigationHooks` can mutate this
|
|
29
|
+
* object (or return `{ gotoOptions: ... }`) to influence the navigation.
|
|
30
|
+
*/
|
|
31
|
+
gotoOptions: GoToOptions;
|
|
29
32
|
/**
|
|
30
33
|
* Helper function for extracting URLs from the current page and adding them to the request queue.
|
|
31
34
|
*/
|
|
32
35
|
enqueueLinks: (options?: EnqueueLinksOptions) => Promise<BatchAddRequestsResult>;
|
|
33
36
|
}
|
|
34
|
-
export type BrowserHook<Context = BrowserCrawlingContext,
|
|
35
|
-
export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse,
|
|
37
|
+
export type BrowserHook<Context = BrowserCrawlingContext, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
38
|
+
export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse, Context extends BrowserCrawlingContext<Page, Response> = BrowserCrawlingContext<Page, Response>, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, InternalBrowserPoolOptions extends BrowserPoolOptions = BrowserPoolOptions, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>, __BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<InternalBrowserPoolOptions['browserPlugins']>, __BrowserControllerReturn extends BrowserController = ReturnType<__BrowserPlugins[number]['createController']>, __LaunchContextReturn extends LaunchContext = ReturnType<__BrowserPlugins[number]['createLaunchContext']>> extends Omit<BasicCrawlerOptions<Context, ContextExtension, ExtendedContext>, 'requestHandler' | 'failedRequestHandler' | 'errorHandler'> {
|
|
36
39
|
launchContext?: BrowserLaunchContext<any, any>;
|
|
40
|
+
/**
|
|
41
|
+
* An existing browser pool instance to use. When provided, the crawler will use this pool directly instead of
|
|
42
|
+
* constructing a new one from `browserPoolOptions`, enabling browser sharing across multiple crawlers. The crawler
|
|
43
|
+
* will not tear down a shared pool — the caller is responsible for its lifecycle.
|
|
44
|
+
*/
|
|
45
|
+
browserPool?: IBrowserPool<Page>;
|
|
46
|
+
/**
|
|
47
|
+
* Connect to a remote browser service (Browserbase, Browserless, Steel, …) instead of launching locally.
|
|
48
|
+
*
|
|
49
|
+
* The crawler builds a {@link RemoteBrowserPool} around its own browser plugin, so the connection is
|
|
50
|
+
* always for the right browser — there is no plugin to construct and no way to mismatch the pool with the
|
|
51
|
+
* crawler. Supply the connection details only: a static `endpoint` URL, a function returning one per launch,
|
|
52
|
+
* or a {@link RemoteBrowserProvider}.
|
|
53
|
+
*
|
|
54
|
+
* Ignored when `browserPool` is set. For sharing a remote pool across crawlers, construct a
|
|
55
|
+
* {@link RemoteBrowserPool} yourself and pass it as `browserPool` instead.
|
|
56
|
+
*/
|
|
57
|
+
remoteBrowser?: CrawlerRemoteBrowserOptions;
|
|
37
58
|
/**
|
|
38
59
|
* Function that is called to process each request.
|
|
39
60
|
*
|
|
@@ -44,7 +65,6 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
44
65
|
* - {@link BrowserCrawlingContext.page|`page`} is an instance of the
|
|
45
66
|
* Puppeteer [Page](https://pptr.dev/api/puppeteer.page) or
|
|
46
67
|
* Playwright [Page](https://playwright.dev/docs/api/class-page);
|
|
47
|
-
* - {@link BrowserCrawlingContext.browserController|`browserController`} is an instance of the {@link BrowserController};
|
|
48
68
|
* - {@link BrowserCrawlingContext.response|`response`} is an instance of the
|
|
49
69
|
* Puppeteer [Response](https://pptr.dev/api/puppeteer.httpresponse) or
|
|
50
70
|
* Playwright [Response](https://playwright.dev/docs/api/class-response),
|
|
@@ -61,7 +81,7 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
61
81
|
* The exceptions are logged to the request using the
|
|
62
82
|
* {@link Request.pushErrorMessage|`Request.pushErrorMessage()`} function.
|
|
63
83
|
*/
|
|
64
|
-
requestHandler?: RequestHandler<ExtendedContext>;
|
|
84
|
+
requestHandler?: RouterHandler<ExtendedContext, Routes> | RequestHandler<ExtendedContext>;
|
|
65
85
|
/**
|
|
66
86
|
* User-provided function that allows modifying the request object before it gets retried by the crawler.
|
|
67
87
|
* It's executed before each retry for the requests that failed less than {@link BrowserCrawlerOptions.maxRequestRetries|`maxRequestRetries`} times.
|
|
@@ -90,15 +110,14 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
90
110
|
browserPoolOptions?: Partial<BrowserPoolOptions> & Partial<BrowserPoolHooks<__BrowserControllerReturn, __LaunchContextReturn>>;
|
|
91
111
|
/**
|
|
92
112
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
93
|
-
* or browser properties before navigation. The function
|
|
94
|
-
*
|
|
113
|
+
* or browser properties before navigation. The function receives the `crawlingContext`; the options object
|
|
114
|
+
* forwarded to `page.goto()` is available as `crawlingContext.gotoOptions` and can be mutated in place.
|
|
95
115
|
*
|
|
96
116
|
* **Example:**
|
|
97
117
|
*
|
|
98
118
|
* ```js
|
|
99
119
|
* preNavigationHooks: [
|
|
100
|
-
* async (
|
|
101
|
-
* const { page } = crawlingContext;
|
|
120
|
+
* async ({ page, gotoOptions }) => {
|
|
102
121
|
* await page.evaluate((attr) => { window.foo = attr; }, 'bar');
|
|
103
122
|
* gotoOptions.timeout = 60_000;
|
|
104
123
|
* gotoOptions.waitUntil = 'domcontentloaded';
|
|
@@ -106,14 +125,22 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
106
125
|
* ]
|
|
107
126
|
* ```
|
|
108
127
|
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
128
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
129
|
+
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
130
|
+
*
|
|
131
|
+
* The context is built up in the following order: base context (`request`, `session`, helpers, ...) ->
|
|
132
|
+
* `extendContext` -> `preNavigationHooks` -> navigation -> `postNavigationHooks` -> `requestHandler`.
|
|
133
|
+
* This means the members added by `extendContext` are already available here, but navigation-dependent
|
|
134
|
+
* members (e.g. `page`, `response`) are not.
|
|
111
135
|
*/
|
|
112
|
-
preNavigationHooks?: BrowserHook<Context>[];
|
|
136
|
+
preNavigationHooks?: BrowserHook<Context, ContextExtension>[];
|
|
113
137
|
/**
|
|
114
138
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
115
139
|
* The function accepts `crawlingContext` as the only parameter.
|
|
116
140
|
*
|
|
141
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context.
|
|
142
|
+
* This is useful for overriding context members (e.g. `response`) after solving a challenge.
|
|
143
|
+
*
|
|
117
144
|
* **Example:**
|
|
118
145
|
*
|
|
119
146
|
* ```js
|
|
@@ -124,19 +151,27 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
124
151
|
* await solveCaptcha(page);
|
|
125
152
|
* }
|
|
126
153
|
* },
|
|
154
|
+
* async (crawlingContext) => {
|
|
155
|
+
* if (await needsRevalidation(crawlingContext)) {
|
|
156
|
+
* return { response: await crawlingContext.page.reload() };
|
|
157
|
+
* }
|
|
158
|
+
* },
|
|
127
159
|
* ]
|
|
128
160
|
* ```
|
|
129
161
|
*/
|
|
130
|
-
postNavigationHooks?: BrowserHook<Context>[];
|
|
162
|
+
postNavigationHooks?: BrowserHook<Context, ContextExtension>[];
|
|
131
163
|
/**
|
|
132
|
-
* Timeout
|
|
164
|
+
* Timeout for the whole navigation phase, in seconds. A single window shared by the `preNavigationHooks`,
|
|
165
|
+
* the page navigation, and the `postNavigationHooks` - so a slow hook eats into the same budget the
|
|
166
|
+
* navigation uses. Separate from the
|
|
167
|
+
* {@link BasicCrawlerOptions.requestHandlerTimeoutSecs|`requestHandlerTimeoutSecs`}, which times only the
|
|
168
|
+
* request handler.
|
|
133
169
|
*/
|
|
134
170
|
navigationTimeoutSecs?: number;
|
|
135
171
|
/**
|
|
136
|
-
* Defines whether the cookies should be persisted for sessions.
|
|
137
|
-
* This can only be used when `useSessionPool` is set to `true`.
|
|
172
|
+
* Defines whether the cookies should be persisted for sessions. Enabled by default.
|
|
138
173
|
*/
|
|
139
|
-
|
|
174
|
+
saveResponseCookies?: boolean;
|
|
140
175
|
/**
|
|
141
176
|
* Whether to run browser in headless mode. Defaults to `true`.
|
|
142
177
|
* Can be also set via {@link Configuration}.
|
|
@@ -165,46 +200,44 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
165
200
|
* If the target website doesn't need JavaScript, we should consider using the {@link CheerioCrawler},
|
|
166
201
|
* which downloads the pages using raw HTTP requests and is about 10x faster.
|
|
167
202
|
*
|
|
168
|
-
* The source URLs are represented by the {@link Request} objects that are fed from the
|
|
169
|
-
*
|
|
170
|
-
* constructor
|
|
203
|
+
* The source URLs are represented by the {@link Request} objects that are fed from the
|
|
204
|
+
* {@link IRequestManager|request manager} provided via the {@link BrowserCrawlerOptions.requestManager|`requestManager`}
|
|
205
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). If no `requestManager` is provided,
|
|
171
206
|
* the crawler will open the default request queue either when the {@link BrowserCrawler.addRequests|`crawler.addRequests()`} function is called,
|
|
172
207
|
* or if `requests` parameter (representing the initial requests) of the {@link BrowserCrawler.run|`crawler.run()`} function is provided.
|
|
173
208
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
209
|
+
* To read from a read-only source such as a {@link RequestList} while still being able to enqueue new requests,
|
|
210
|
+
* combine it with a queue into a {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`}
|
|
211
|
+
* and pass the result as `requestManager`.
|
|
212
|
+
*
|
|
213
|
+
* > The {@link BrowserCrawlerOptions.requestList|`requestList`} and {@link BrowserCrawlerOptions.requestQueue|`requestQueue`}
|
|
214
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
177
215
|
*
|
|
178
216
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
179
217
|
*
|
|
180
218
|
* `BrowserCrawler` opens a new browser page (i.e. tab or window) for each {@link Request} object to crawl
|
|
181
219
|
* and then calls the function provided by user as the {@link BrowserCrawlerOptions.requestHandler|`requestHandler`} option.
|
|
182
220
|
*
|
|
183
|
-
* New pages are only opened when there is enough free CPU and memory available,
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* {@link AutoscaledPoolOptions.maxConcurrency|`maxConcurrency`} options of the
|
|
189
|
-
* underlying {@link AutoscaledPool} constructor are available directly in the `BrowserCrawler` constructor.
|
|
221
|
+
* New pages are only opened when there is enough free CPU and memory available, as judged by the crawler's
|
|
222
|
+
* {@link ConcurrencySystem}.
|
|
223
|
+
* Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
|
|
224
|
+
* `BrowserCrawler` constructor, or, for finer control, by injecting a pre-configured
|
|
225
|
+
* {@link ConcurrencySystem|`concurrencySystem`}.
|
|
190
226
|
*
|
|
191
227
|
* > *NOTE:* the pool of browser instances is internally managed by the {@link BrowserPool} class.
|
|
192
228
|
*
|
|
193
229
|
* @category Crawlers
|
|
194
230
|
*/
|
|
195
|
-
export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse,
|
|
196
|
-
|
|
231
|
+
export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse, InternalBrowserPoolOptions extends BrowserPoolOptions = BrowserPoolOptions, LaunchOptions extends Dictionary | undefined = Dictionary, Context extends BrowserCrawlingContext<Page, Response> = BrowserCrawlingContext<Page, Response>, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>, GoToOptions extends Dictionary = Dictionary> extends BasicCrawler<Context, ContextExtension, ExtendedContext, Routes> {
|
|
232
|
+
#private;
|
|
197
233
|
/**
|
|
198
|
-
* A reference to the underlying
|
|
234
|
+
* A reference to the underlying browser pool that manages the crawler's browsers. Typed as
|
|
235
|
+
* {@link IBrowserPool} so custom implementations can be plugged in via the `browserPool` constructor option.
|
|
199
236
|
*/
|
|
200
|
-
browserPool:
|
|
237
|
+
get browserPool(): IBrowserPool<Page>;
|
|
201
238
|
launchContext: BrowserLaunchContext<LaunchOptions, unknown>;
|
|
202
239
|
protected readonly ignoreShadowRoots: boolean;
|
|
203
240
|
protected readonly ignoreIframes: boolean;
|
|
204
|
-
protected navigationTimeoutMillis: number;
|
|
205
|
-
protected preNavigationHooks: BrowserHook<Context>[];
|
|
206
|
-
protected postNavigationHooks: BrowserHook<Context>[];
|
|
207
|
-
protected persistCookiesPerSession: boolean;
|
|
208
241
|
protected static optionsShape: {
|
|
209
242
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
210
243
|
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
@@ -217,13 +250,13 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
217
250
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
218
251
|
headless: import("ow").AnyPredicate<string | boolean>;
|
|
219
252
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
220
|
-
|
|
253
|
+
browserPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
221
254
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
222
|
-
|
|
255
|
+
remoteBrowser: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
223
256
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
224
|
-
|
|
257
|
+
browserPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
225
258
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
226
|
-
|
|
259
|
+
saveResponseCookies: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
227
260
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
228
261
|
proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
229
262
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -234,6 +267,8 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
234
267
|
requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
235
268
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
236
269
|
requestQueue: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
270
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
271
|
+
requestManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
237
272
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
238
273
|
requestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
239
274
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -246,24 +281,44 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
246
281
|
maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
247
282
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
248
283
|
sameDomainDelaySecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
249
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
250
|
-
maxSessionRotations: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
251
284
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
252
285
|
maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
253
286
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
254
|
-
|
|
287
|
+
maxCrawlDepth: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
288
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
289
|
+
taskLoopOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
290
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
291
|
+
concurrencySystem: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
292
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
293
|
+
sessionPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
255
294
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
256
295
|
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
257
296
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
258
297
|
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
298
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
299
|
+
additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
300
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
301
|
+
ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
302
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
303
|
+
blockedStatusCodes: import("ow").ArrayPredicate<number>;
|
|
259
304
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
260
305
|
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
261
306
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
262
|
-
respectRobotsTxtFile: import("ow").
|
|
307
|
+
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
308
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
309
|
+
transactionalStorage: import("ow").BasePredicate<boolean | Partial<import("@crawlee/basic").StorageWritePolicy> | undefined>;
|
|
263
310
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
264
311
|
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
265
312
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
266
313
|
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
314
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
315
|
+
configuration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
316
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
317
|
+
storageBackend: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
318
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
319
|
+
eventManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
320
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
321
|
+
logger: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
267
322
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
268
323
|
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
269
324
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -273,38 +328,46 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
273
328
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
274
329
|
keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
275
330
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
276
|
-
|
|
331
|
+
statistics: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
277
332
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
278
|
-
|
|
279
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
280
|
-
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
333
|
+
id: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
281
334
|
};
|
|
282
335
|
/**
|
|
283
336
|
* All `BrowserCrawler` parameters are passed via an options object.
|
|
284
337
|
*/
|
|
285
|
-
protected constructor(options: BrowserCrawlerOptions<Page, Response,
|
|
338
|
+
protected constructor(options: BrowserCrawlerOptions<Page, Response, Context, ContextExtension, ExtendedContext> & {
|
|
286
339
|
contextPipelineBuilder: () => ContextPipeline<CrawlingContext, Context>;
|
|
287
|
-
}
|
|
288
|
-
protected
|
|
340
|
+
});
|
|
341
|
+
protected getNavigationTimeoutMillis(): number;
|
|
342
|
+
protected buildContextPipeline(): ContextPipeline<CrawlingContext, BrowserCrawlingContext<Page, Response, Dictionary>>;
|
|
289
343
|
private containsSelectors;
|
|
290
|
-
|
|
344
|
+
private isRequestBlocked;
|
|
291
345
|
private preparePage;
|
|
292
|
-
private
|
|
346
|
+
private prepareNavigation;
|
|
347
|
+
private navigate;
|
|
348
|
+
private finalizeNavigation;
|
|
349
|
+
/**
|
|
350
|
+
* Copies cookies from the live browser page into the session cookie jar.
|
|
351
|
+
*/
|
|
352
|
+
private persistCookiesFromPage;
|
|
353
|
+
/**
|
|
354
|
+
* Runs the user request handler, then re-reads browser cookies so login flows /
|
|
355
|
+
* `page.setCookie` / XHR `Set-Cookie` updates are stored for later requests.
|
|
356
|
+
*/
|
|
357
|
+
protected runRequestHandler(crawlingContext: ExtendedContext): Promise<void>;
|
|
293
358
|
private handleBlockedRequestByContent;
|
|
294
359
|
private restoreRequestState;
|
|
295
|
-
|
|
360
|
+
private applyCookies;
|
|
296
361
|
/**
|
|
297
|
-
* Marks session bad in
|
|
362
|
+
* Marks session bad on navigation timeout, and stops in-flight page loading on any navigation error.
|
|
298
363
|
*/
|
|
299
|
-
|
|
364
|
+
private handleNavigationTimeout;
|
|
300
365
|
/**
|
|
301
366
|
* Transforms proxy-related errors to `SessionError`.
|
|
302
367
|
*/
|
|
303
|
-
|
|
304
|
-
protected abstract
|
|
368
|
+
private throwIfProxyError;
|
|
369
|
+
protected abstract navigationHandler(crawlingContext: BrowserCrawlingContext<Page, Response>, gotoOptions: GoToOptions): Promise<Context['response'] | null | undefined>;
|
|
305
370
|
private processResponse;
|
|
306
|
-
protected _extendLaunchContext(_pageId: string, launchContext: LaunchContext): Promise<void>;
|
|
307
|
-
protected _maybeAddSessionRetiredListener(_pageId: string, browserController: Context['browserController']): void;
|
|
308
371
|
/**
|
|
309
372
|
* Function for cleaning up after all requests are processed.
|
|
310
373
|
* @ignore
|
|
@@ -313,16 +376,24 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
313
376
|
}
|
|
314
377
|
/** @internal */
|
|
315
378
|
interface EnqueueLinksInternalOptions {
|
|
316
|
-
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, '
|
|
379
|
+
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, 'requestManager'>> & Pick<EnqueueLinksOptions, 'requestManager'>;
|
|
317
380
|
page: CommonPage;
|
|
318
|
-
|
|
381
|
+
requestManager: IRequestManager;
|
|
319
382
|
robotsTxtFile?: RobotsTxtFile;
|
|
320
383
|
onSkippedRequest?: SkippedRequestCallback;
|
|
321
384
|
originalRequestUrl: string;
|
|
322
385
|
finalRequestUrl?: string;
|
|
323
386
|
}
|
|
324
387
|
/** @internal */
|
|
325
|
-
|
|
388
|
+
interface BoundEnqueueLinksInternalOptions {
|
|
389
|
+
enqueueLinks: BasicCrawlingContext['enqueueLinks'];
|
|
390
|
+
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, 'requestManager'>> & Pick<EnqueueLinksOptions, 'requestManager'>;
|
|
391
|
+
originalRequestUrl: string;
|
|
392
|
+
finalRequestUrl?: string;
|
|
393
|
+
page: CommonPage;
|
|
394
|
+
}
|
|
395
|
+
/** @internal */
|
|
396
|
+
export declare function browserCrawlerEnqueueLinks(options: EnqueueLinksInternalOptions | BoundEnqueueLinksInternalOptions): Promise<unknown>;
|
|
326
397
|
/**
|
|
327
398
|
* Extracts URLs from a given page.
|
|
328
399
|
* @ignore
|
|
@@ -331,4 +402,3 @@ export declare function extractUrlsFromPage(page: {
|
|
|
331
402
|
$$eval: Function;
|
|
332
403
|
}, selector: string, baseUrl: string): Promise<string[]>;
|
|
333
404
|
export {};
|
|
334
|
-
//# sourceMappingURL=browser-crawler.d.ts.map
|