@crawlee/impit-client 4.0.0-beta.98 → 4.0.0-rc.0

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.
Files changed (3) hide show
  1. package/index.d.ts +1 -15
  2. package/index.js +16 -13
  3. package/package.json +4 -4
package/index.d.ts CHANGED
@@ -10,21 +10,7 @@ export declare const Browser: {
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;
13
+ #private;
28
14
  private getClient;
29
15
  /**
30
16
  * @param options.cacheClients Whether to cache `impit` clients between requests. Defaults to `true`.
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();
46
+ #impitBrowserByFingerprint = new WeakMap();
47
47
  getClient(options) {
48
- if (!this.cacheClients) {
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 ?? {};
74
+ const { proxyUrl, redirect, signal, fingerprint, ignoreTlsErrors } = options ?? {};
75
75
  const impitBrowser = this.resolveImpitBrowser(fingerprint);
76
76
  const impit = this.getClient({
77
- ...this.impitOptions,
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
  });
@@ -86,7 +89,7 @@ export class ImpitHttpClient extends BaseHttpClient {
86
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/impit-client",
3
- "version": "4.0.0-beta.98",
3
+ "version": "4.0.0-rc.0",
4
4
  "description": "impit-based HTTP client implementation for Crawlee. Impersonates browser requests to avoid bot detection.",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -48,8 +48,8 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@apify/datastructures": "^2.0.3",
51
- "@crawlee/http-client": "4.0.0-beta.98",
52
- "@crawlee/types": "4.0.0-beta.98",
51
+ "@crawlee/http-client": "4.0.0-rc.0",
52
+ "@crawlee/types": "4.0.0-rc.0",
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": "3b8cd86b13e253ab5fc71e631e12a68f7465cee5"
63
+ "gitHead": "79ab33dacdacb83e0197e6516d145f3aceef80c7"
64
64
  }