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