@crawlee/browser 3.0.0-alpha.1 → 3.0.0-alpha.4
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/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +7 -0
- package/index.js.map +1 -0
- package/index.mjs +69 -0
- package/internals/browser-crawler.d.ts +329 -0
- package/internals/browser-crawler.d.ts.map +1 -0
- package/internals/browser-crawler.js +405 -0
- package/internals/browser-crawler.js.map +1 -0
- package/internals/browser-launcher.d.ts +60 -0
- package/internals/browser-launcher.d.ts.map +1 -0
- package/internals/browser-launcher.js +189 -0
- package/internals/browser-launcher.js.map +1 -0
- package/package.json +2 -5
- package/tsconfig.build.tsbuildinfo +1 -0
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("@crawlee/basic"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./internals/browser-crawler"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./internals/browser-launcher"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,sEAA4C;AAC5C,uEAA6C"}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import mod from "./index.js";
|
|
2
|
+
|
|
3
|
+
export default mod;
|
|
4
|
+
export const API_PROCESSED_REQUESTS_DELAY_MILLIS = mod.API_PROCESSED_REQUESTS_DELAY_MILLIS;
|
|
5
|
+
export const AutoscaledPool = mod.AutoscaledPool;
|
|
6
|
+
export const BASIC_CRAWLER_TIMEOUT_BUFFER_SECS = mod.BASIC_CRAWLER_TIMEOUT_BUFFER_SECS;
|
|
7
|
+
export const BasicCrawler = mod.BasicCrawler;
|
|
8
|
+
export const BrowserCrawler = mod.BrowserCrawler;
|
|
9
|
+
export const BrowserLauncher = mod.BrowserLauncher;
|
|
10
|
+
export const Configuration = mod.Configuration;
|
|
11
|
+
export const CookieParseError = mod.CookieParseError;
|
|
12
|
+
export const CrawlerExtension = mod.CrawlerExtension;
|
|
13
|
+
export const DATASET_ITERATORS_DEFAULT_LIMIT = mod.DATASET_ITERATORS_DEFAULT_LIMIT;
|
|
14
|
+
export const Dataset = mod.Dataset;
|
|
15
|
+
export const EVENT_SESSION_RETIRED = mod.EVENT_SESSION_RETIRED;
|
|
16
|
+
export const EnqueueStrategy = mod.EnqueueStrategy;
|
|
17
|
+
export const EventManager = mod.EventManager;
|
|
18
|
+
export const EventType = mod.EventType;
|
|
19
|
+
export const KeyValueStore = mod.KeyValueStore;
|
|
20
|
+
export const LocalEventManager = mod.LocalEventManager;
|
|
21
|
+
export const Log = mod.Log;
|
|
22
|
+
export const LogLevel = mod.LogLevel;
|
|
23
|
+
export const Logger = mod.Logger;
|
|
24
|
+
export const LoggerJson = mod.LoggerJson;
|
|
25
|
+
export const LoggerText = mod.LoggerText;
|
|
26
|
+
export const MAX_QUERIES_FOR_CONSISTENCY = mod.MAX_QUERIES_FOR_CONSISTENCY;
|
|
27
|
+
export const ProxyConfiguration = mod.ProxyConfiguration;
|
|
28
|
+
export const QUERY_HEAD_BUFFER = mod.QUERY_HEAD_BUFFER;
|
|
29
|
+
export const QUERY_HEAD_MIN_LENGTH = mod.QUERY_HEAD_MIN_LENGTH;
|
|
30
|
+
export const REQUESTS_PERSISTENCE_KEY = mod.REQUESTS_PERSISTENCE_KEY;
|
|
31
|
+
export const Request = mod.Request;
|
|
32
|
+
export const RequestList = mod.RequestList;
|
|
33
|
+
export const RequestQueue = mod.RequestQueue;
|
|
34
|
+
export const STATE_PERSISTENCE_KEY = mod.STATE_PERSISTENCE_KEY;
|
|
35
|
+
export const STATUS_CODES_BLOCKED = mod.STATUS_CODES_BLOCKED;
|
|
36
|
+
export const STORAGE_CONSISTENCY_DELAY_MILLIS = mod.STORAGE_CONSISTENCY_DELAY_MILLIS;
|
|
37
|
+
export const Session = mod.Session;
|
|
38
|
+
export const SessionPool = mod.SessionPool;
|
|
39
|
+
export const Snapshotter = mod.Snapshotter;
|
|
40
|
+
export const Statistics = mod.Statistics;
|
|
41
|
+
export const StorageManager = mod.StorageManager;
|
|
42
|
+
export const SystemStatus = mod.SystemStatus;
|
|
43
|
+
export const basicCrawlerEnqueueLinks = mod.basicCrawlerEnqueueLinks;
|
|
44
|
+
export const browserCrawlerEnqueueLinks = mod.browserCrawlerEnqueueLinks;
|
|
45
|
+
export const checkAndSerialize = mod.checkAndSerialize;
|
|
46
|
+
export const chunkBySize = mod.chunkBySize;
|
|
47
|
+
export const constructGlobObjectsFromGlobs = mod.constructGlobObjectsFromGlobs;
|
|
48
|
+
export const constructRegExpObjectsFromPseudoUrls = mod.constructRegExpObjectsFromPseudoUrls;
|
|
49
|
+
export const constructRegExpObjectsFromRegExps = mod.constructRegExpObjectsFromRegExps;
|
|
50
|
+
export const createDeserialize = mod.createDeserialize;
|
|
51
|
+
export const createRequestOptions = mod.createRequestOptions;
|
|
52
|
+
export const createRequests = mod.createRequests;
|
|
53
|
+
export const deserializeArray = mod.deserializeArray;
|
|
54
|
+
export const diffCookies = mod.diffCookies;
|
|
55
|
+
export const enqueueLinks = mod.enqueueLinks;
|
|
56
|
+
export const getCookiesFromResponse = mod.getCookiesFromResponse;
|
|
57
|
+
export const getRequestId = mod.getRequestId;
|
|
58
|
+
export const handleRequestTimeout = mod.handleRequestTimeout;
|
|
59
|
+
export const log = mod.log;
|
|
60
|
+
export const maybeStringify = mod.maybeStringify;
|
|
61
|
+
export const mergeCookies = mod.mergeCookies;
|
|
62
|
+
export const openDataset = mod.openDataset;
|
|
63
|
+
export const pushData = mod.pushData;
|
|
64
|
+
export const serializeArray = mod.serializeArray;
|
|
65
|
+
export const storage = mod.storage;
|
|
66
|
+
export const throwOnBlockedRequest = mod.throwOnBlockedRequest;
|
|
67
|
+
export const updateEnqueueLinksPatternCache = mod.updateEnqueueLinksPatternCache;
|
|
68
|
+
export const validateGlobPattern = mod.validateGlobPattern;
|
|
69
|
+
export const validators = mod.validators;
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { EnqueueLinksOptions, CrawlerHandleFailedRequestInput, CrawlingContext, ProxyConfiguration, RequestQueue, storage } from '@crawlee/core';
|
|
2
|
+
import { BasicCrawler, BasicCrawlerOptions } from '@crawlee/basic';
|
|
3
|
+
import { Awaitable, Dictionary } from '@crawlee/utils';
|
|
4
|
+
import { BrowserController, BrowserPlugin, BrowserPool, BrowserPoolHooks, BrowserPoolOptions, CommonPage, InferBrowserPluginArray, LaunchContext } from '@crawlee/browser-pool';
|
|
5
|
+
import { BrowserLaunchContext } from './browser-launcher';
|
|
6
|
+
export interface BrowserCrawlingContext<Page extends CommonPage = CommonPage, Response = Dictionary<any>, ProvidedController = BrowserController> extends CrawlingContext {
|
|
7
|
+
browserController: ProvidedController;
|
|
8
|
+
page: Page;
|
|
9
|
+
response?: Response;
|
|
10
|
+
crawler: BrowserCrawler;
|
|
11
|
+
enqueueLinks: (options?: BrowserCrawlerEnqueueLinksOptions) => Promise<storage.BatchAddRequestsResult>;
|
|
12
|
+
}
|
|
13
|
+
export interface BrowserCrawlerHandleFailedRequestInput extends CrawlerHandleFailedRequestInput {
|
|
14
|
+
crawler: BrowserCrawler;
|
|
15
|
+
}
|
|
16
|
+
export declare type BrowserCrawlerHandleFailedRequest = (inputs: BrowserCrawlerHandleFailedRequestInput) => Awaitable<void>;
|
|
17
|
+
export declare type BrowserCrawlerHandleRequest<Context extends BrowserCrawlingContext = BrowserCrawlingContext> = (inputs: Context) => Awaitable<void>;
|
|
18
|
+
export declare type BrowserCrawlerEnqueueLinksOptions = Omit<EnqueueLinksOptions, 'requestQueue' | 'urls'>;
|
|
19
|
+
export declare type BrowserHook<Context = BrowserCrawlingContext, GoToOptions extends Record<PropertyKey, any> | undefined = Dictionary> = (crawlingContext: Context, gotoOptions: GoToOptions) => Awaitable<void>;
|
|
20
|
+
export declare type GotoFunction<Context = BrowserCrawlingContext, GoToOptions extends Record<PropertyKey, any> | undefined = Dictionary> = (context: Context, gotoOptions?: GoToOptions) => Awaitable<any>;
|
|
21
|
+
export interface BrowserCrawlerOptions<Context extends BrowserCrawlingContext = BrowserCrawlingContext, GoToOptions extends Record<PropertyKey, any> | undefined = Dictionary, 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' | 'handleRequestFunction' | 'failedRequestHandler' | 'handleFailedRequestFunction'> {
|
|
22
|
+
/**
|
|
23
|
+
* Function that is called to process each request.
|
|
24
|
+
* It is passed an object with the following fields:
|
|
25
|
+
*
|
|
26
|
+
* ```
|
|
27
|
+
* {
|
|
28
|
+
* request: Request,
|
|
29
|
+
* response: Response,
|
|
30
|
+
* page: Page,
|
|
31
|
+
* session: Session,
|
|
32
|
+
* browserController: BrowserController,
|
|
33
|
+
* proxyInfo: ProxyInfo,
|
|
34
|
+
* crawler: BrowserCrawler,
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* `request` is an instance of the {@link Request} object with details about the URL to open, HTTP method etc.
|
|
39
|
+
* `page` is an instance of the `Puppeteer`
|
|
40
|
+
* [`Page`](https://pptr.dev/#?product=Puppeteer&show=api-class-page) or `Playwright`
|
|
41
|
+
* [`Page`](https://playwright.dev/docs/api/class-page)
|
|
42
|
+
* `browserPool` is an instance of the
|
|
43
|
+
* [`BrowserPool`](https://github.com/apify/browser-pool#BrowserPool),
|
|
44
|
+
* `browserController` is an instance of the
|
|
45
|
+
* [`BrowserController`](https://github.com/apify/browser-pool#browsercontroller),
|
|
46
|
+
* `response` is an instance of the `Puppeteer`
|
|
47
|
+
* [`Response`](https://pptr.dev/#?product=Puppeteer&show=api-class-response) or `Playwright`
|
|
48
|
+
* [`Response`](https://playwright.dev/docs/api/class-response),
|
|
49
|
+
* which is the main resource response as returned by `page.goto(request.url)`.
|
|
50
|
+
* The function must return a promise, which is then awaited by the crawler.
|
|
51
|
+
*
|
|
52
|
+
* If the function throws an exception, the crawler will try to re-crawl the
|
|
53
|
+
* request later, up to `option.maxRequestRetries` times.
|
|
54
|
+
* If all the retries fail, the crawler calls the function
|
|
55
|
+
* provided to the `handleFailedRequestFunction` parameter.
|
|
56
|
+
* To make this work, you should **always**
|
|
57
|
+
* let your function throw exceptions rather than catch them.
|
|
58
|
+
* The exceptions are logged to the request using the
|
|
59
|
+
* {@link Request.pushErrorMessage} function.
|
|
60
|
+
*/
|
|
61
|
+
requestHandler: BrowserCrawlerHandleRequest<Context>;
|
|
62
|
+
/**
|
|
63
|
+
* Function that is called to process each request.
|
|
64
|
+
* It is passed an object with the following fields:
|
|
65
|
+
*
|
|
66
|
+
* ```
|
|
67
|
+
* {
|
|
68
|
+
* request: Request,
|
|
69
|
+
* response: Response,
|
|
70
|
+
* page: Page,
|
|
71
|
+
* session: Session,
|
|
72
|
+
* browserController: BrowserController,
|
|
73
|
+
* proxyInfo: ProxyInfo,
|
|
74
|
+
* crawler: BrowserCrawler,
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* `request` is an instance of the {@link Request} object with details about the URL to open, HTTP method etc.
|
|
79
|
+
* `page` is an instance of the `Puppeteer`
|
|
80
|
+
* [`Page`](https://pptr.dev/#?product=Puppeteer&show=api-class-page) or `Playwright`
|
|
81
|
+
* [`Page`](https://playwright.dev/docs/api/class-page)
|
|
82
|
+
* `browserPool` is an instance of the
|
|
83
|
+
* [`BrowserPool`](https://github.com/apify/browser-pool#BrowserPool),
|
|
84
|
+
* `browserController` is an instance of the
|
|
85
|
+
* [`BrowserController`](https://github.com/apify/browser-pool#browsercontroller),
|
|
86
|
+
* `response` is an instance of the `Puppeteer`
|
|
87
|
+
* [`Response`](https://pptr.dev/#?product=Puppeteer&show=api-class-response) or `Playwright`
|
|
88
|
+
* [`Response`](https://playwright.dev/docs/api/class-response),
|
|
89
|
+
* which is the main resource response as returned by `page.goto(request.url)`.
|
|
90
|
+
* The function must return a promise, which is then awaited by the crawler.
|
|
91
|
+
*
|
|
92
|
+
* If the function throws an exception, the crawler will try to re-crawl the
|
|
93
|
+
* request later, up to `option.maxRequestRetries` times.
|
|
94
|
+
* If all the retries fail, the crawler calls the function
|
|
95
|
+
* provided to the `handleFailedRequestFunction` parameter.
|
|
96
|
+
* To make this work, you should **always**
|
|
97
|
+
* let your function throw exceptions rather than catch them.
|
|
98
|
+
* The exceptions are logged to the request using the
|
|
99
|
+
* {@link Request.pushErrorMessage} function.
|
|
100
|
+
*
|
|
101
|
+
* @deprecated `handlePageFunction` has been renamed to `requestHandler` and will be removed in a future version.
|
|
102
|
+
*/
|
|
103
|
+
handlePageFunction?: BrowserCrawlerHandleRequest<Context>;
|
|
104
|
+
/**
|
|
105
|
+
* Navigation function for corresponding library. `page.goto(url)` is supported by both `playwright` and `puppeteer`.
|
|
106
|
+
*/
|
|
107
|
+
gotoFunction?: GotoFunction<Context, GoToOptions>;
|
|
108
|
+
/**
|
|
109
|
+
* A function to handle requests that failed more than `option.maxRequestRetries` times.
|
|
110
|
+
*
|
|
111
|
+
* The function receives the following object as an argument:
|
|
112
|
+
* ```
|
|
113
|
+
* {
|
|
114
|
+
* request: Request,
|
|
115
|
+
* response: Response,
|
|
116
|
+
* page: Page,
|
|
117
|
+
* browserPool: BrowserPool,
|
|
118
|
+
* autoscaledPool: AutoscaledPool,
|
|
119
|
+
* session: Session,
|
|
120
|
+
* browserController: BrowserController,
|
|
121
|
+
* proxyInfo: ProxyInfo,
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
* Where the {@link Request} instance corresponds to the failed request, and the `Error` instance
|
|
125
|
+
* represents the last error thrown during processing of the request.
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
failedRequestHandler?: BrowserCrawlerHandleFailedRequest;
|
|
129
|
+
/**
|
|
130
|
+
* A function to handle requests that failed more than `option.maxRequestRetries` times.
|
|
131
|
+
*
|
|
132
|
+
* The function receives the following object as an argument:
|
|
133
|
+
* ```
|
|
134
|
+
* {
|
|
135
|
+
* request: Request,
|
|
136
|
+
* response: Response,
|
|
137
|
+
* page: Page,
|
|
138
|
+
* browserPool: BrowserPool,
|
|
139
|
+
* autoscaledPool: AutoscaledPool,
|
|
140
|
+
* session: Session,
|
|
141
|
+
* browserController: BrowserController,
|
|
142
|
+
* proxyInfo: ProxyInfo,
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
* Where the {@link Request} instance corresponds to the failed request, and the `Error` instance
|
|
146
|
+
* represents the last error thrown during processing of the request.
|
|
147
|
+
*
|
|
148
|
+
* @deprecated `handleFailedRequestFunction` has been renamed to `failedRequestHandler` and will be removed in a future version.
|
|
149
|
+
*/
|
|
150
|
+
handleFailedRequestFunction?: BrowserCrawlerHandleFailedRequest;
|
|
151
|
+
/**
|
|
152
|
+
* Custom options passed to the underlying [`BrowserPool`](https://github.com/apify/browser-pool#BrowserPool) constructor.
|
|
153
|
+
* You can tweak those to fine-tune browser management.
|
|
154
|
+
*/
|
|
155
|
+
browserPoolOptions?: Partial<BrowserPoolOptions> & Partial<BrowserPoolHooks<__BrowserControllerReturn, __LaunchContextReturn>>;
|
|
156
|
+
/**
|
|
157
|
+
* If set, the crawler will be configured for all connections to use
|
|
158
|
+
* [Apify Proxy](https://console.apify.com/proxy) or your own Proxy URLs provided and rotated according to the configuration.
|
|
159
|
+
* For more information, see the [documentation](https://docs.apify.com/proxy).
|
|
160
|
+
*/
|
|
161
|
+
proxyConfiguration?: ProxyConfiguration;
|
|
162
|
+
/**
|
|
163
|
+
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
164
|
+
* or browser properties before navigation. The function accepts two parameters, `crawlingContext` and `gotoOptions`,
|
|
165
|
+
* which are passed to the `page.goto()` function the crawler calls to navigate.
|
|
166
|
+
* Example:
|
|
167
|
+
* ```
|
|
168
|
+
* preNavigationHooks: [
|
|
169
|
+
* async (crawlingContext, gotoOptions) => {
|
|
170
|
+
* const { page } = crawlingContext;
|
|
171
|
+
* await page.evaluate((attr) => { window.foo = attr; }, 'bar');
|
|
172
|
+
* },
|
|
173
|
+
* ]
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
preNavigationHooks?: BrowserHook<Context>[];
|
|
177
|
+
/**
|
|
178
|
+
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
179
|
+
* The function accepts `crawlingContext` as the only parameter.
|
|
180
|
+
* Example:
|
|
181
|
+
* ```
|
|
182
|
+
* postNavigationHooks: [
|
|
183
|
+
* async (crawlingContext) => {
|
|
184
|
+
* const { page } = crawlingContext;
|
|
185
|
+
* if (hasCaptcha(page)) {
|
|
186
|
+
* await solveCaptcha (page);
|
|
187
|
+
* }
|
|
188
|
+
* },
|
|
189
|
+
* ]
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
postNavigationHooks?: BrowserHook<Context>[];
|
|
193
|
+
/**
|
|
194
|
+
* Timeout in which page navigation needs to finish, in seconds.
|
|
195
|
+
*/
|
|
196
|
+
navigationTimeoutSecs?: number;
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated Use `navigationTimeoutSecs` instead
|
|
199
|
+
*/
|
|
200
|
+
gotoTimeoutSecs?: number;
|
|
201
|
+
/**
|
|
202
|
+
* If cookies should be persisted between sessions.
|
|
203
|
+
* This can only be used when `useSessionPool` is set to `true`.
|
|
204
|
+
*/
|
|
205
|
+
persistCookiesPerSession?: boolean;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Provides a simple framework for parallel crawling of web pages
|
|
209
|
+
* using headless browsers with [Puppeteer](https://github.com/puppeteer/puppeteer)
|
|
210
|
+
* and [Playwright](https://github.com/microsoft/playwright).
|
|
211
|
+
* The URLs to crawl are fed either from a static list of URLs
|
|
212
|
+
* or from a dynamic queue of URLs enabling recursive crawling of websites.
|
|
213
|
+
*
|
|
214
|
+
* Since `BrowserCrawler` uses headless or even headfull browsers to download web pages and extract data,
|
|
215
|
+
* it is useful for crawling of websites that require to execute JavaScript.
|
|
216
|
+
* If the target website doesn't need JavaScript, consider using {@link CheerioCrawler},
|
|
217
|
+
* which downloads the pages using raw HTTP requests and is about 10x faster.
|
|
218
|
+
*
|
|
219
|
+
* The source URLs are represented using {@link Request} objects that are fed from
|
|
220
|
+
* {@link RequestList} or {@link RequestQueue} instances provided by the {@link BrowserCrawlerOptions.requestList}
|
|
221
|
+
* or {@link BrowserCrawlerOptions.requestQueue} constructor options, respectively.
|
|
222
|
+
*
|
|
223
|
+
* If both {@link BrowserCrawlerOptions.requestList} and {@link BrowserCrawlerOptions.requestQueue} are used,
|
|
224
|
+
* the instance first processes URLs from the {@link RequestList} and automatically enqueues all of them
|
|
225
|
+
* to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
|
|
226
|
+
*
|
|
227
|
+
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
228
|
+
*
|
|
229
|
+
* `BrowserCrawler` opens a new browser page (i.e. tab or window) for each {@link Request} object to crawl
|
|
230
|
+
* and then calls the function provided by user as the {@link BrowserCrawlerOptions.handlePageFunction} option.
|
|
231
|
+
*
|
|
232
|
+
* New pages are only opened when there is enough free CPU and memory available,
|
|
233
|
+
* using the functionality provided by the {@link AutoscaledPool} class.
|
|
234
|
+
* All {@link AutoscaledPool} configuration options can be passed to the {@link BrowserCrawlerOptions.autoscaledPoolOptions}
|
|
235
|
+
* parameter of the `BrowserCrawler` constructor. For user convenience, the `minConcurrency` and `maxConcurrency`
|
|
236
|
+
* {@link AutoscaledPoolOptions} are available directly in the `BrowserCrawler` constructor.
|
|
237
|
+
*
|
|
238
|
+
* Note that the pool of browser instances is internally managed by the [BrowserPool](https://github.com/apify/browser-pool) class.
|
|
239
|
+
* ```js
|
|
240
|
+
* await crawler.run();
|
|
241
|
+
* ```
|
|
242
|
+
* @category Crawlers
|
|
243
|
+
*/
|
|
244
|
+
export declare abstract class BrowserCrawler<InternalBrowserPoolOptions extends BrowserPoolOptions = BrowserPoolOptions, LaunchOptions = Dictionary, Context extends BrowserCrawlingContext = BrowserCrawlingContext, GoToOptions extends Record<PropertyKey, any> = Dictionary> extends BasicCrawler<Context> {
|
|
245
|
+
/**
|
|
246
|
+
* A reference to the underlying {@link ProxyConfiguration} class that manages the crawler's proxies.
|
|
247
|
+
* Only available if used by the crawler.
|
|
248
|
+
*/
|
|
249
|
+
proxyConfiguration?: ProxyConfiguration;
|
|
250
|
+
/**
|
|
251
|
+
* A reference to the underlying `BrowserPool` class that manages the crawler's browsers.
|
|
252
|
+
* For more information about it, see the [`browser-pool` module](https://github.com/apify/browser-pool).
|
|
253
|
+
* @todo the type is almost unusable with so many generic arguments, what should go there? we need inference
|
|
254
|
+
*/
|
|
255
|
+
browserPool: BrowserPool<InternalBrowserPoolOptions>;
|
|
256
|
+
launchContext?: BrowserLaunchContext<LaunchOptions, unknown>;
|
|
257
|
+
protected userProvidedRequestHandler: BrowserCrawlerHandleRequest<Context>;
|
|
258
|
+
protected navigationTimeoutMillis: number;
|
|
259
|
+
protected gotoFunction?: GotoFunction<Context, GoToOptions>;
|
|
260
|
+
protected defaultGotoOptions: GoToOptions;
|
|
261
|
+
protected preNavigationHooks: BrowserHook<Context>[];
|
|
262
|
+
protected postNavigationHooks: BrowserHook<Context>[];
|
|
263
|
+
protected persistCookiesPerSession: boolean;
|
|
264
|
+
protected static optionsShape: {
|
|
265
|
+
handlePageFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
266
|
+
gotoFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
267
|
+
gotoTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
268
|
+
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
269
|
+
preNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
270
|
+
postNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
271
|
+
browserPoolOptions: import("ow").ObjectPredicate<object>;
|
|
272
|
+
sessionPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
273
|
+
persistCookiesPerSession: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
274
|
+
useSessionPool: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
275
|
+
proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
276
|
+
requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
277
|
+
requestQueue: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
278
|
+
requestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
279
|
+
handleRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
280
|
+
requestHandlerTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
281
|
+
handleRequestTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
282
|
+
failedRequestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
283
|
+
handleFailedRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
284
|
+
maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
285
|
+
maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
286
|
+
autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
287
|
+
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
288
|
+
maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
289
|
+
log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* All `BrowserCrawler` parameters are passed via an options object.
|
|
293
|
+
*/
|
|
294
|
+
protected constructor(options: BrowserCrawlerOptions<Context, GoToOptions>);
|
|
295
|
+
/**
|
|
296
|
+
* Wrapper around handlePageFunction that opens and closes pages etc.
|
|
297
|
+
*/
|
|
298
|
+
protected _runRequestHandler(crawlingContext: Context): Promise<void>;
|
|
299
|
+
protected _enhanceCrawlingContextWithPageInfo(crawlingContext: Context, page: CommonPage, useIncognitoPages?: boolean): void;
|
|
300
|
+
protected _handleNavigation(crawlingContext: Context): Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* Marks session bad in case of navigation timeout.
|
|
303
|
+
*/
|
|
304
|
+
protected _handleNavigationTimeout(crawlingContext: Context, error: Error): void;
|
|
305
|
+
protected _navigationHandler(crawlingContext: Context, gotoOptions: GoToOptions): Promise<any>;
|
|
306
|
+
/**
|
|
307
|
+
* Should be overridden in case of different automation library that does not support this response API.
|
|
308
|
+
* @todo: This can be also done as a postNavigation hook except the loadedUrl marking.
|
|
309
|
+
*/
|
|
310
|
+
protected _responseHandler(crawlingContext: Context): Promise<void>;
|
|
311
|
+
protected _extendLaunchContext(_pageId: string, launchContext: LaunchContext): Promise<void>;
|
|
312
|
+
protected _maybeAddSessionRetiredListener(_pageId: string, browserController: Context['browserController']): void;
|
|
313
|
+
/**
|
|
314
|
+
* Function for cleaning up after all request are processed.
|
|
315
|
+
* @ignore
|
|
316
|
+
*/
|
|
317
|
+
teardown(): Promise<void>;
|
|
318
|
+
}
|
|
319
|
+
/** @internal */
|
|
320
|
+
interface EnqueueLinksInternalOptions {
|
|
321
|
+
options?: BrowserCrawlerEnqueueLinksOptions;
|
|
322
|
+
page: CommonPage;
|
|
323
|
+
requestQueue?: RequestQueue;
|
|
324
|
+
defaultBaseUrl?: string;
|
|
325
|
+
}
|
|
326
|
+
/** @internal */
|
|
327
|
+
export declare function browserCrawlerEnqueueLinks({ options, page, requestQueue, defaultBaseUrl }: EnqueueLinksInternalOptions): Promise<storage.BatchAddRequestsResult>;
|
|
328
|
+
export {};
|
|
329
|
+
//# sourceMappingURL=browser-crawler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-crawler.d.ts","sourceRoot":"","sources":["../../src/internals/browser-crawler.ts"],"names":[],"mappings":"AACA,OAAO,EACH,mBAAmB,EACnB,+BAA+B,EAC/B,eAAe,EAIf,kBAAkB,EAElB,YAAY,EAIZ,OAAO,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAEH,YAAY,EACZ,mBAAmB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAEH,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,uBAAuB,EACvB,aAAa,EAChB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,C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