httpcloak 1.0.1 → 1.0.2
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/lib/index.js +78 -11
- package/npm/darwin-arm64/package.json +1 -1
- package/npm/darwin-x64/package.json +1 -1
- package/npm/linux-arm64/package.json +1 -1
- package/npm/linux-x64/package.json +1 -1
- package/npm/win32-arm64/package.json +1 -1
- package/npm/win32-x64/package.json +1 -1
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -20,6 +20,48 @@ class HTTPCloakError extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Available browser presets for TLS fingerprinting.
|
|
25
|
+
*
|
|
26
|
+
* Use these constants instead of typing preset strings manually:
|
|
27
|
+
* const httpcloak = require("httpcloak");
|
|
28
|
+
* httpcloak.configure({ preset: httpcloak.Preset.CHROME_143 });
|
|
29
|
+
*
|
|
30
|
+
* // Or with Session
|
|
31
|
+
* const session = new httpcloak.Session({ preset: httpcloak.Preset.FIREFOX_133 });
|
|
32
|
+
*/
|
|
33
|
+
const Preset = {
|
|
34
|
+
// Chrome 143 (latest)
|
|
35
|
+
CHROME_143: "chrome-143",
|
|
36
|
+
CHROME_143_WINDOWS: "chrome-143-windows",
|
|
37
|
+
CHROME_143_LINUX: "chrome-143-linux",
|
|
38
|
+
CHROME_143_MACOS: "chrome-143-macos",
|
|
39
|
+
|
|
40
|
+
// Chrome 131
|
|
41
|
+
CHROME_131: "chrome-131",
|
|
42
|
+
CHROME_131_WINDOWS: "chrome-131-windows",
|
|
43
|
+
CHROME_131_LINUX: "chrome-131-linux",
|
|
44
|
+
CHROME_131_MACOS: "chrome-131-macos",
|
|
45
|
+
|
|
46
|
+
// Firefox
|
|
47
|
+
FIREFOX_133: "firefox-133",
|
|
48
|
+
|
|
49
|
+
// Safari
|
|
50
|
+
SAFARI_18: "safari-18",
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get all available preset names
|
|
54
|
+
* @returns {string[]} List of all preset names
|
|
55
|
+
*/
|
|
56
|
+
all() {
|
|
57
|
+
return [
|
|
58
|
+
this.CHROME_143, this.CHROME_143_WINDOWS, this.CHROME_143_LINUX, this.CHROME_143_MACOS,
|
|
59
|
+
this.CHROME_131, this.CHROME_131_WINDOWS, this.CHROME_131_LINUX, this.CHROME_131_MACOS,
|
|
60
|
+
this.FIREFOX_133, this.SAFARI_18,
|
|
61
|
+
];
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
23
65
|
/**
|
|
24
66
|
* Response object returned from HTTP requests
|
|
25
67
|
*/
|
|
@@ -174,26 +216,45 @@ function getLib() {
|
|
|
174
216
|
const libPath = getLibPath();
|
|
175
217
|
const nativeLib = koffi.load(libPath);
|
|
176
218
|
|
|
219
|
+
// Use void* for string returns so we can free them properly
|
|
177
220
|
lib = {
|
|
178
221
|
httpcloak_session_new: nativeLib.func("httpcloak_session_new", "int64", ["str"]),
|
|
179
222
|
httpcloak_session_free: nativeLib.func("httpcloak_session_free", "void", ["int64"]),
|
|
180
|
-
httpcloak_get: nativeLib.func("httpcloak_get", "
|
|
181
|
-
httpcloak_post: nativeLib.func("httpcloak_post", "
|
|
182
|
-
httpcloak_request: nativeLib.func("httpcloak_request", "
|
|
183
|
-
httpcloak_get_cookies: nativeLib.func("httpcloak_get_cookies", "
|
|
223
|
+
httpcloak_get: nativeLib.func("httpcloak_get", "void*", ["int64", "str", "str"]),
|
|
224
|
+
httpcloak_post: nativeLib.func("httpcloak_post", "void*", ["int64", "str", "str", "str"]),
|
|
225
|
+
httpcloak_request: nativeLib.func("httpcloak_request", "void*", ["int64", "str"]),
|
|
226
|
+
httpcloak_get_cookies: nativeLib.func("httpcloak_get_cookies", "void*", ["int64"]),
|
|
184
227
|
httpcloak_set_cookie: nativeLib.func("httpcloak_set_cookie", "void", ["int64", "str", "str"]),
|
|
185
|
-
httpcloak_free_string: nativeLib.func("httpcloak_free_string", "void", ["
|
|
186
|
-
httpcloak_version: nativeLib.func("httpcloak_version", "
|
|
187
|
-
httpcloak_available_presets: nativeLib.func("httpcloak_available_presets", "
|
|
228
|
+
httpcloak_free_string: nativeLib.func("httpcloak_free_string", "void", ["void*"]),
|
|
229
|
+
httpcloak_version: nativeLib.func("httpcloak_version", "void*", []),
|
|
230
|
+
httpcloak_available_presets: nativeLib.func("httpcloak_available_presets", "void*", []),
|
|
188
231
|
};
|
|
189
232
|
}
|
|
190
233
|
return lib;
|
|
191
234
|
}
|
|
192
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Convert a C string pointer to JS string and free the memory
|
|
238
|
+
*/
|
|
239
|
+
function ptrToString(ptr) {
|
|
240
|
+
if (!ptr) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
// Decode the C string from the pointer
|
|
245
|
+
const str = koffi.decode(ptr, "str");
|
|
246
|
+
return str;
|
|
247
|
+
} finally {
|
|
248
|
+
// Always free the C string to prevent memory leaks
|
|
249
|
+
getLib().httpcloak_free_string(ptr);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
193
253
|
/**
|
|
194
254
|
* Parse response from the native library
|
|
195
255
|
*/
|
|
196
|
-
function parseResponse(
|
|
256
|
+
function parseResponse(resultPtr) {
|
|
257
|
+
const result = ptrToString(resultPtr);
|
|
197
258
|
if (!result) {
|
|
198
259
|
throw new HTTPCloakError("No response received");
|
|
199
260
|
}
|
|
@@ -345,7 +406,9 @@ function encodeMultipart(data, files) {
|
|
|
345
406
|
*/
|
|
346
407
|
function version() {
|
|
347
408
|
const nativeLib = getLib();
|
|
348
|
-
|
|
409
|
+
const resultPtr = nativeLib.httpcloak_version();
|
|
410
|
+
const result = ptrToString(resultPtr);
|
|
411
|
+
return result || "unknown";
|
|
349
412
|
}
|
|
350
413
|
|
|
351
414
|
/**
|
|
@@ -353,7 +416,8 @@ function version() {
|
|
|
353
416
|
*/
|
|
354
417
|
function availablePresets() {
|
|
355
418
|
const nativeLib = getLib();
|
|
356
|
-
const
|
|
419
|
+
const resultPtr = nativeLib.httpcloak_available_presets();
|
|
420
|
+
const result = ptrToString(resultPtr);
|
|
357
421
|
if (result) {
|
|
358
422
|
return JSON.parse(result);
|
|
359
423
|
}
|
|
@@ -689,7 +753,8 @@ class Session {
|
|
|
689
753
|
* @returns {Object} Cookies as key-value pairs
|
|
690
754
|
*/
|
|
691
755
|
getCookies() {
|
|
692
|
-
const
|
|
756
|
+
const resultPtr = this._lib.httpcloak_get_cookies(this._handle);
|
|
757
|
+
const result = ptrToString(resultPtr);
|
|
693
758
|
if (result) {
|
|
694
759
|
return JSON.parse(result);
|
|
695
760
|
}
|
|
@@ -891,6 +956,8 @@ module.exports = {
|
|
|
891
956
|
Session,
|
|
892
957
|
Response,
|
|
893
958
|
HTTPCloakError,
|
|
959
|
+
// Presets
|
|
960
|
+
Preset,
|
|
894
961
|
// Configuration
|
|
895
962
|
configure,
|
|
896
963
|
// Module-level functions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "httpcloak",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Browser fingerprint emulation HTTP client with HTTP/1.1, HTTP/2, and HTTP/3 support",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"koffi": "^2.9.0"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@httpcloak/linux-x64": "1.0.
|
|
39
|
-
"@httpcloak/linux-arm64": "1.0.
|
|
40
|
-
"@httpcloak/darwin-x64": "1.0.
|
|
41
|
-
"@httpcloak/darwin-arm64": "1.0.
|
|
42
|
-
"@httpcloak/win32-x64": "1.0.
|
|
43
|
-
"@httpcloak/win32-arm64": "1.0.
|
|
38
|
+
"@httpcloak/linux-x64": "1.0.2",
|
|
39
|
+
"@httpcloak/linux-arm64": "1.0.2",
|
|
40
|
+
"@httpcloak/darwin-x64": "1.0.2",
|
|
41
|
+
"@httpcloak/darwin-arm64": "1.0.2",
|
|
42
|
+
"@httpcloak/win32-x64": "1.0.2",
|
|
43
|
+
"@httpcloak/win32-arm64": "1.0.2"
|
|
44
44
|
}
|
|
45
45
|
}
|