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