@crawlee/browser 4.0.0-beta.10 → 4.0.0-beta.100

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