@crawlee/http 4.0.0-beta.81 → 4.0.0-beta.82
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.
|
@@ -23,6 +23,11 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
23
23
|
*
|
|
24
24
|
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
25
25
|
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
26
|
+
*
|
|
27
|
+
* The context is built up in the following order: base context (`request`, `session`, helpers, ...) ->
|
|
28
|
+
* `extendContext` -> `preNavigationHooks` -> navigation -> `postNavigationHooks` -> `requestHandler`.
|
|
29
|
+
* This means the members added by `extendContext` are already available here, but navigation-dependent
|
|
30
|
+
* members (e.g. `response`, `body`, `$`) are not.
|
|
26
31
|
* Example:
|
|
27
32
|
* ```
|
|
28
33
|
* preNavigationHooks: [
|
|
@@ -32,7 +37,7 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
32
37
|
* ]
|
|
33
38
|
* ```
|
|
34
39
|
*/
|
|
35
|
-
preNavigationHooks?: InternalHttpHook<CrawlingContext>[];
|
|
40
|
+
preNavigationHooks?: InternalHttpHook<CrawlingContext, ContextExtension>[];
|
|
36
41
|
/**
|
|
37
42
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
38
43
|
* The function accepts `crawlingContext` as the only parameter.
|
|
@@ -50,7 +55,7 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
50
55
|
* ]
|
|
51
56
|
* ```
|
|
52
57
|
*/
|
|
53
|
-
postNavigationHooks?: ((crawlingContext: CrawlingContextWithResponse) => Awaitable<void | Partial<CrawlingContextWithResponse>>)[];
|
|
58
|
+
postNavigationHooks?: ((crawlingContext: CrawlingContextWithResponse & ContextExtension) => Awaitable<void | Partial<CrawlingContextWithResponse>>)[];
|
|
54
59
|
/**
|
|
55
60
|
* An array of [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types)
|
|
56
61
|
* you want the crawler to load and process. By default, only `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
@@ -90,7 +95,7 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
90
95
|
/**
|
|
91
96
|
* @internal
|
|
92
97
|
*/
|
|
93
|
-
export type InternalHttpHook<Context> = (crawlingContext: Context) => Awaitable<void | Partial<Context>>;
|
|
98
|
+
export type InternalHttpHook<Context, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
94
99
|
export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
95
100
|
JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
|
|
96
101
|
interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
@@ -94,6 +94,10 @@ const HTTP_OPTIMIZED_AUTOSCALED_POOL_OPTIONS = {
|
|
|
94
94
|
* @category Crawlers
|
|
95
95
|
*/
|
|
96
96
|
export class HttpCrawler extends BasicCrawler {
|
|
97
|
+
// Internal storage uses the base (non-extended) context types. The public option types are
|
|
98
|
+
// extension-aware for consumer DX, but internally the pipeline composes hooks against the
|
|
99
|
+
// concrete crawling context, which does not statically carry `ContextExtension`. The members
|
|
100
|
+
// added by `extendContext` are present at runtime regardless.
|
|
97
101
|
preNavigationHooks;
|
|
98
102
|
postNavigationHooks;
|
|
99
103
|
saveResponseCookies;
|
|
@@ -137,6 +141,9 @@ export class HttpCrawler extends BasicCrawler {
|
|
|
137
141
|
this.ignoreSslErrors = ignoreSslErrors;
|
|
138
142
|
this.suggestResponseEncoding = suggestResponseEncoding;
|
|
139
143
|
this.forceResponseEncoding = forceResponseEncoding;
|
|
144
|
+
// Cast away the extension-aware option types to the base internal storage types (see the field
|
|
145
|
+
// declarations above). This is sound - the hooks only ever receive the base context plus the
|
|
146
|
+
// members `extendContext` added at runtime.
|
|
140
147
|
this.preNavigationHooks = preNavigationHooks;
|
|
141
148
|
this.postNavigationHooks = [
|
|
142
149
|
({ request, response }) => this._abortDownloadOfBody(request, response),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/http",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.82",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/timeout": "^0.3.2",
|
|
51
51
|
"@apify/utilities": "^2.15.5",
|
|
52
|
-
"@crawlee/basic": "4.0.0-beta.
|
|
53
|
-
"@crawlee/core": "4.0.0-beta.
|
|
54
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
55
|
-
"@crawlee/types": "4.0.0-beta.
|
|
56
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
52
|
+
"@crawlee/basic": "4.0.0-beta.82",
|
|
53
|
+
"@crawlee/core": "4.0.0-beta.82",
|
|
54
|
+
"@crawlee/http-client": "4.0.0-beta.82",
|
|
55
|
+
"@crawlee/types": "4.0.0-beta.82",
|
|
56
|
+
"@crawlee/utils": "4.0.0-beta.82",
|
|
57
57
|
"@types/content-type": "^1.1.8",
|
|
58
58
|
"cheerio": "^1.0.0",
|
|
59
59
|
"content-type": "^1.0.5",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "eb1096f7c7743d124375ef011fbbadb19476822e"
|
|
74
74
|
}
|