@crawlee/impit-client 4.0.0-beta.99 → 4.0.0-rc.1

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
@@ -34,7 +34,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
34
34
 
35
35
  We recommend visiting the [Introduction tutorial](https://crawlee.dev/js/docs/introduction) in Crawlee documentation for more information.
36
36
 
37
- > Crawlee requires **Node.js 16 or higher**.
37
+ > Crawlee requires **Node.js 22.13 or higher**.
38
38
 
39
39
  ### With Crawlee CLI
40
40
 
package/index.d.ts CHANGED
@@ -3,29 +3,14 @@ import { BaseHttpClient } from '@crawlee/http-client';
3
3
  import type { CrawleeLogger } from '@crawlee/types';
4
4
  import { type ImpitOptions } from 'impit';
5
5
  export declare const Browser: {
6
- readonly Chrome: "chrome";
7
- readonly Firefox: "firefox";
6
+ readonly Chrome: 'chrome';
7
+ readonly Firefox: 'firefox';
8
8
  };
9
9
  /**
10
10
  * A HTTP client implementation based on the `impit` library.
11
11
  */
12
12
  export declare class ImpitHttpClient extends BaseHttpClient {
13
- private impitOptions;
14
- private cacheClients;
15
- /**
16
- * Enables reuse of `impit` clients for the same set of options.
17
- * This is useful for performance reasons, as creating
18
- * a new client for each request breaks TCP connection
19
- * (and other resources) reuse.
20
- */
21
- private clientCache;
22
- /**
23
- * Stable impit impersonation version per fingerprint object, so the same
24
- * session keeps impersonating the same browser version across requests
25
- * instead of rerolling on every call.
26
- */
27
- private impitBrowserByFingerprint;
28
- private getClient;
13
+ #private;
29
14
  /**
30
15
  * @param options.cacheClients Whether to cache `impit` clients between requests. Defaults to `true`.
31
16
  */
@@ -36,6 +21,5 @@ export declare class ImpitHttpClient extends BaseHttpClient {
36
21
  /**
37
22
  * @inheritDoc
38
23
  */
39
- fetch(request: Request, options?: RequestInit & CustomFetchOptions): Promise<Response>;
40
- private resolveImpitBrowser;
24
+ protected fetch(request: Request, options?: RequestInit & CustomFetchOptions): Promise<Response>;
41
25
  }
package/index.js CHANGED
@@ -29,33 +29,33 @@ export const Browser = {
29
29
  * A HTTP client implementation based on the `impit` library.
30
30
  */
31
31
  export class ImpitHttpClient extends BaseHttpClient {
32
- impitOptions;
33
- cacheClients;
32
+ #impitOptions;
33
+ #cacheClients;
34
34
  /**
35
35
  * Enables reuse of `impit` clients for the same set of options.
36
36
  * This is useful for performance reasons, as creating
37
37
  * a new client for each request breaks TCP connection
38
38
  * (and other resources) reuse.
39
39
  */
40
- clientCache = new LruCache({ maxLength: 10 });
40
+ #clientCache = new LruCache({ maxLength: 10 });
41
41
  /**
42
42
  * Stable impit impersonation version per fingerprint object, so the same
43
43
  * session keeps impersonating the same browser version across requests
44
44
  * instead of rerolling on every call.
45
45
  */
46
- impitBrowserByFingerprint = new WeakMap();
47
- getClient(options) {
48
- if (!this.cacheClients) {
46
+ #impitBrowserByFingerprint = new WeakMap();
47
+ #getClient(options) {
48
+ if (!this.#cacheClients) {
49
49
  return new Impit(options);
50
50
  }
51
51
  const { cookieJar, ...rest } = options;
52
52
  const cacheKey = JSON.stringify(rest);
53
- const existingClient = this.clientCache.get(cacheKey);
53
+ const existingClient = this.#clientCache.get(cacheKey);
54
54
  if (existingClient && (!cookieJar || existingClient.cookieJar === cookieJar)) {
55
55
  return existingClient.client;
56
56
  }
57
57
  const client = new Impit(options);
58
- this.clientCache.add(cacheKey, { client, cookieJar: cookieJar });
58
+ this.#clientCache.add(cacheKey, { client, cookieJar: cookieJar });
59
59
  return client;
60
60
  }
61
61
  /**
@@ -64,18 +64,21 @@ export class ImpitHttpClient extends BaseHttpClient {
64
64
  constructor(options) {
65
65
  super({ logger: options?.logger });
66
66
  const { cacheClients = true, logger: _logger, ...impitOptions } = options ?? {};
67
- this.impitOptions = impitOptions;
68
- this.cacheClients = cacheClients;
67
+ this.#impitOptions = impitOptions;
68
+ this.#cacheClients = cacheClients;
69
69
  }
70
70
  /**
71
71
  * @inheritDoc
72
72
  */
73
73
  async fetch(request, options) {
74
- const { proxyUrl, redirect, signal, fingerprint } = options ?? {};
75
- const impitBrowser = this.resolveImpitBrowser(fingerprint);
76
- const impit = this.getClient({
77
- ...this.impitOptions,
74
+ const { proxyUrl, redirect, signal, fingerprint, ignoreTlsErrors } = options ?? {};
75
+ const impitBrowser = this.#resolveImpitBrowser(fingerprint);
76
+ const impit = this.#getClient({
77
+ ...this.#impitOptions,
78
78
  ...(impitBrowser ? { browser: impitBrowser } : {}),
79
+ // The per-request flag (from the crawler option or a MITM proxy session)
80
+ // can only enable ignoring, never override a constructor-level `true`.
81
+ ...(ignoreTlsErrors ? { ignoreTlsErrors: true } : {}),
79
82
  proxyUrl,
80
83
  followRedirects: redirect === 'follow',
81
84
  });
@@ -83,10 +86,10 @@ export class ImpitHttpClient extends BaseHttpClient {
83
86
  // todo - cast shouldn't be needed here, impit returns `Uint8Array`
84
87
  return new ResponseWithUrl(response.body, response);
85
88
  }
86
- resolveImpitBrowser(fingerprint) {
89
+ #resolveImpitBrowser(fingerprint) {
87
90
  if (!fingerprint?.browser)
88
91
  return undefined;
89
- const cached = this.impitBrowserByFingerprint.get(fingerprint);
92
+ const cached = this.#impitBrowserByFingerprint.get(fingerprint);
90
93
  if (cached)
91
94
  return cached;
92
95
  // impit can only impersonate Chrome and Firefox. Map other (Chromium-based or
@@ -94,7 +97,7 @@ export class ImpitHttpClient extends BaseHttpClient {
94
97
  // carries realistic browser headers instead of impit's bare `*/*` defaults.
95
98
  const versions = IMPIT_VERSIONS_BY_BROWSER[fingerprint.browser] ?? IMPIT_VERSIONS_BY_BROWSER.chrome;
96
99
  const picked = versions[Math.floor(Math.random() * versions.length)];
97
- this.impitBrowserByFingerprint.set(fingerprint, picked);
100
+ this.#impitBrowserByFingerprint.set(fingerprint, picked);
98
101
  return picked;
99
102
  }
100
103
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@crawlee/impit-client",
3
- "version": "4.0.0-beta.99",
3
+ "version": "4.0.0-rc.1",
4
4
  "description": "impit-based HTTP client implementation for Crawlee. Impersonates browser requests to avoid bot detection.",
5
5
  "engines": {
6
- "node": ">=22.0.0"
6
+ "node": ">=22.13.0"
7
7
  },
8
8
  "type": "module",
9
9
  "exports": {
@@ -47,9 +47,9 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@apify/datastructures": "^2.0.3",
51
- "@crawlee/http-client": "4.0.0-beta.99",
52
- "@crawlee/types": "4.0.0-beta.99",
50
+ "@apify/datastructures": "^3.0.1",
51
+ "@crawlee/http-client": "4.0.0-rc.1",
52
+ "@crawlee/types": "4.0.0-rc.1",
53
53
  "impit": "^0.14.2",
54
54
  "tough-cookie": "^6.0.0"
55
55
  },
@@ -60,5 +60,5 @@
60
60
  }
61
61
  }
62
62
  },
63
- "gitHead": "ad2748380941842bb10cff100f4b4caad92049e3"
63
+ "gitHead": "f354ca5e943bed1a5c657a1fce1974c053f9fff0"
64
64
  }