@crawlee/browser 4.0.0-beta.8 → 4.0.0-beta.81
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 +144 -86
- package/internals/browser-crawler.js +236 -230
- package/internals/browser-launcher.d.ts +11 -5
- package/internals/browser-launcher.js +11 -11
- 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 { Awaitable, BasicCrawlerOptions, CrawlingContext, Dictionary, EnqueueLinksOptions, ErrorHandler,
|
|
2
|
-
import { BasicCrawler,
|
|
3
|
-
import type { BrowserController, BrowserPlugin, BrowserPoolHooks, BrowserPoolOptions, CommonPage, InferBrowserPluginArray, LaunchContext } from '@crawlee/browser-pool';
|
|
4
|
-
import {
|
|
1
|
+
import type { Awaitable, BasicCrawlerOptions, BasicCrawlingContext, CrawlingContext, Dictionary, EnqueueLinksOptions, ErrorHandler, IRequestManager, LoadedRequest, Request, RequestHandler, 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 { BatchAddRequestsResult, 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> = (crawlingContext: Context) => 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, __BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<InternalBrowserPoolOptions['browserPlugins']>, __BrowserControllerReturn extends BrowserController = ReturnType<__BrowserPlugins[number]['createController']>, __LaunchContextReturn extends LaunchContext = ReturnType<__BrowserPlugins[number]['createLaunchContext']>> extends Omit<BasicCrawlerOptions<Context, 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?: 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,17 @@ 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.
|
|
97
127
|
*/
|
|
98
128
|
preNavigationHooks?: BrowserHook<Context>[];
|
|
99
129
|
/**
|
|
100
130
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
101
131
|
* The function accepts `crawlingContext` as the only parameter.
|
|
102
132
|
*
|
|
133
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context.
|
|
134
|
+
* This is useful for overriding context members (e.g. `response`) after solving a challenge.
|
|
135
|
+
*
|
|
103
136
|
* **Example:**
|
|
104
137
|
*
|
|
105
138
|
* ```js
|
|
@@ -110,6 +143,11 @@ export interface BrowserCrawlerOptions<Context extends BrowserCrawlingContext =
|
|
|
110
143
|
* await solveCaptcha(page);
|
|
111
144
|
* }
|
|
112
145
|
* },
|
|
146
|
+
* async (crawlingContext) => {
|
|
147
|
+
* if (await needsRevalidation(crawlingContext)) {
|
|
148
|
+
* return { response: await crawlingContext.page.reload() };
|
|
149
|
+
* }
|
|
150
|
+
* },
|
|
113
151
|
* ]
|
|
114
152
|
* ```
|
|
115
153
|
*/
|
|
@@ -119,10 +157,9 @@ export interface BrowserCrawlerOptions<Context extends BrowserCrawlingContext =
|
|
|
119
157
|
*/
|
|
120
158
|
navigationTimeoutSecs?: number;
|
|
121
159
|
/**
|
|
122
|
-
* Defines whether the cookies should be persisted for sessions.
|
|
123
|
-
* This can only be used when `useSessionPool` is set to `true`.
|
|
160
|
+
* Defines whether the cookies should be persisted for sessions. Enabled by default.
|
|
124
161
|
*/
|
|
125
|
-
|
|
162
|
+
saveResponseCookies?: boolean;
|
|
126
163
|
/**
|
|
127
164
|
* Whether to run browser in headless mode. Defaults to `true`.
|
|
128
165
|
* Can be also set via {@link Configuration}.
|
|
@@ -151,15 +188,18 @@ export interface BrowserCrawlerOptions<Context extends BrowserCrawlingContext =
|
|
|
151
188
|
* If the target website doesn't need JavaScript, we should consider using the {@link CheerioCrawler},
|
|
152
189
|
* which downloads the pages using raw HTTP requests and is about 10x faster.
|
|
153
190
|
*
|
|
154
|
-
* The source URLs are represented by the {@link Request} objects that are fed from the
|
|
155
|
-
*
|
|
156
|
-
* constructor
|
|
191
|
+
* The source URLs are represented by the {@link Request} objects that are fed from the
|
|
192
|
+
* {@link IRequestManager|request manager} provided via the {@link BrowserCrawlerOptions.requestManager|`requestManager`}
|
|
193
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). If no `requestManager` is provided,
|
|
157
194
|
* the crawler will open the default request queue either when the {@link BrowserCrawler.addRequests|`crawler.addRequests()`} function is called,
|
|
158
195
|
* or if `requests` parameter (representing the initial requests) of the {@link BrowserCrawler.run|`crawler.run()`} function is provided.
|
|
159
196
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
197
|
+
* To read from a read-only source such as a {@link RequestList} while still being able to enqueue new requests,
|
|
198
|
+
* combine it with a queue into a {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`}
|
|
199
|
+
* and pass the result as `requestManager`.
|
|
200
|
+
*
|
|
201
|
+
* > The {@link BrowserCrawlerOptions.requestList|`requestList`} and {@link BrowserCrawlerOptions.requestQueue|`requestQueue`}
|
|
202
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
163
203
|
*
|
|
164
204
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
165
205
|
*
|
|
@@ -178,24 +218,25 @@ export interface BrowserCrawlerOptions<Context extends BrowserCrawlingContext =
|
|
|
178
218
|
*
|
|
179
219
|
* @category Crawlers
|
|
180
220
|
*/
|
|
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
|
-
readonly config: Configuration;
|
|
221
|
+
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, GoToOptions extends Dictionary = Dictionary> extends BasicCrawler<Context, ContextExtension, ExtendedContext> {
|
|
183
222
|
/**
|
|
184
|
-
* A reference to the underlying
|
|
185
|
-
*
|
|
223
|
+
* A reference to the underlying browser pool that manages the crawler's browsers. Typed as
|
|
224
|
+
* {@link IBrowserPool} so custom implementations can be plugged in via the `browserPool` constructor option.
|
|
186
225
|
*/
|
|
187
|
-
|
|
226
|
+
browserPool: IBrowserPool<Page>;
|
|
188
227
|
/**
|
|
189
|
-
*
|
|
228
|
+
* Set when the crawler constructed its own pool (a {@link BrowserPool}, or a {@link RemoteBrowserPool}
|
|
229
|
+
* built from the `remoteBrowser` option). Holds the same instance as `browserPool` but is the only reference
|
|
230
|
+
* the crawler tears down — a user-supplied `browserPool` is never owned and never destroyed by the crawler.
|
|
190
231
|
*/
|
|
191
|
-
|
|
232
|
+
private ownedBrowserPool?;
|
|
192
233
|
launchContext: BrowserLaunchContext<LaunchOptions, unknown>;
|
|
193
|
-
protected
|
|
194
|
-
protected
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
234
|
+
protected readonly ignoreShadowRoots: boolean;
|
|
235
|
+
protected readonly ignoreIframes: boolean;
|
|
236
|
+
private readonly navigationTimeoutMillis;
|
|
237
|
+
private readonly preNavigationHooks;
|
|
238
|
+
private readonly postNavigationHooks;
|
|
239
|
+
private readonly saveResponseCookies;
|
|
199
240
|
protected static optionsShape: {
|
|
200
241
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
201
242
|
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
@@ -208,19 +249,19 @@ export declare abstract class BrowserCrawler<InternalBrowserPoolOptions extends
|
|
|
208
249
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
209
250
|
headless: import("ow").AnyPredicate<string | boolean>;
|
|
210
251
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
211
|
-
|
|
252
|
+
browserPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
212
253
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
213
|
-
|
|
254
|
+
remoteBrowser: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
214
255
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
215
|
-
|
|
256
|
+
browserPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
216
257
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
217
|
-
|
|
258
|
+
saveResponseCookies: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
218
259
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
219
260
|
proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
220
261
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
221
|
-
|
|
262
|
+
contextPipelineBuilder: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
222
263
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
223
|
-
|
|
264
|
+
extendContext: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
224
265
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
225
266
|
requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
226
267
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -237,24 +278,40 @@ export declare abstract class BrowserCrawler<InternalBrowserPoolOptions extends
|
|
|
237
278
|
maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
238
279
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
239
280
|
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
281
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
243
282
|
maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
283
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
284
|
+
maxCrawlDepth: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
244
285
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
245
286
|
autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
287
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
288
|
+
sessionPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
246
289
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
247
290
|
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
248
291
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
249
292
|
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
293
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
294
|
+
additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
295
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
296
|
+
ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
297
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
298
|
+
blockedStatusCodes: import("ow").ArrayPredicate<number>;
|
|
250
299
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
251
300
|
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
252
301
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
253
|
-
respectRobotsTxtFile: import("ow").
|
|
302
|
+
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
254
303
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
255
304
|
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
256
305
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
257
306
|
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
307
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
308
|
+
configuration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
309
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
310
|
+
storageBackend: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
311
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
312
|
+
eventManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
313
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
314
|
+
logger: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
258
315
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
259
316
|
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
260
317
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -263,42 +320,37 @@ export declare abstract class BrowserCrawler<InternalBrowserPoolOptions extends
|
|
|
263
320
|
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
264
321
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
265
322
|
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
323
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
271
324
|
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
325
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
326
|
+
id: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
272
327
|
};
|
|
273
328
|
/**
|
|
274
329
|
* All `BrowserCrawler` parameters are passed via an options object.
|
|
275
330
|
*/
|
|
276
|
-
protected constructor(options
|
|
277
|
-
|
|
331
|
+
protected constructor(options: BrowserCrawlerOptions<Page, Response, Context, ContextExtension, ExtendedContext> & {
|
|
332
|
+
contextPipelineBuilder: () => ContextPipeline<CrawlingContext, Context>;
|
|
333
|
+
});
|
|
334
|
+
protected buildContextPipeline(): ContextPipeline<CrawlingContext, BrowserCrawlingContext<Page, Response, Dictionary>>;
|
|
278
335
|
private containsSelectors;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
336
|
+
private isRequestBlocked;
|
|
337
|
+
private preparePage;
|
|
338
|
+
private prepareNavigation;
|
|
339
|
+
private navigate;
|
|
340
|
+
private finalizeNavigation;
|
|
341
|
+
private handleBlockedRequestByContent;
|
|
342
|
+
private restoreRequestState;
|
|
343
|
+
private applyCookies;
|
|
287
344
|
/**
|
|
288
|
-
* Marks session bad in
|
|
345
|
+
* Marks session bad on navigation timeout, and stops in-flight page loading on any navigation error.
|
|
289
346
|
*/
|
|
290
|
-
|
|
347
|
+
private handleNavigationTimeout;
|
|
291
348
|
/**
|
|
292
349
|
* Transforms proxy-related errors to `SessionError`.
|
|
293
350
|
*/
|
|
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;
|
|
351
|
+
private throwIfProxyError;
|
|
352
|
+
protected abstract _navigationHandler(crawlingContext: BrowserCrawlingContext<Page, Response>, gotoOptions: GoToOptions): Promise<Context['response'] | null | undefined>;
|
|
353
|
+
private processResponse;
|
|
302
354
|
/**
|
|
303
355
|
* Function for cleaning up after all requests are processed.
|
|
304
356
|
* @ignore
|
|
@@ -307,17 +359,24 @@ export declare abstract class BrowserCrawler<InternalBrowserPoolOptions extends
|
|
|
307
359
|
}
|
|
308
360
|
/** @internal */
|
|
309
361
|
interface EnqueueLinksInternalOptions {
|
|
310
|
-
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, '
|
|
362
|
+
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, 'requestManager'>> & Pick<EnqueueLinksOptions, 'requestManager'>;
|
|
311
363
|
page: CommonPage;
|
|
312
|
-
|
|
364
|
+
requestManager: IRequestManager;
|
|
313
365
|
robotsTxtFile?: RobotsTxtFile;
|
|
314
366
|
onSkippedRequest?: SkippedRequestCallback;
|
|
315
367
|
originalRequestUrl: string;
|
|
316
368
|
finalRequestUrl?: string;
|
|
317
369
|
}
|
|
318
370
|
/** @internal */
|
|
319
|
-
|
|
320
|
-
|
|
371
|
+
interface BoundEnqueueLinksInternalOptions {
|
|
372
|
+
enqueueLinks: BasicCrawlingContext['enqueueLinks'];
|
|
373
|
+
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, 'requestManager'>> & Pick<EnqueueLinksOptions, 'requestManager'>;
|
|
374
|
+
originalRequestUrl: string;
|
|
375
|
+
finalRequestUrl?: string;
|
|
376
|
+
page: CommonPage;
|
|
377
|
+
}
|
|
378
|
+
/** @internal */
|
|
379
|
+
export declare function browserCrawlerEnqueueLinks(options: EnqueueLinksInternalOptions | BoundEnqueueLinksInternalOptions): Promise<unknown>;
|
|
321
380
|
/**
|
|
322
381
|
* Extracts URLs from a given page.
|
|
323
382
|
* @ignore
|
|
@@ -326,4 +385,3 @@ export declare function extractUrlsFromPage(page: {
|
|
|
326
385
|
$$eval: Function;
|
|
327
386
|
}, selector: string, baseUrl: string): Promise<string[]>;
|
|
328
387
|
export {};
|
|
329
|
-
//# sourceMappingURL=browser-crawler.d.ts.map
|