tlsclientwrapper
Advanced tools
Comparing version 1.4.3 to 2.0.0
@@ -17,3 +17,3 @@ import Client from "./utils/client.js"; | ||
this.defaultOptions = { | ||
tlsClientIdentifier: 'chrome_120', | ||
tlsClientIdentifier: 'chrome_124', | ||
rotateSessions: false, | ||
@@ -29,3 +29,3 @@ catchPanics: false, | ||
defaultHeaders: { | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', | ||
}, | ||
@@ -337,3 +337,3 @@ insecureSkipVerify: false, | ||
* @param {string} url - The URL to add cookies for. | ||
* @param {Cookie[]} cookie - The cookies to add. | ||
* @param {import('./typedefs.js').Cookie[]} cookie - The cookies to add. | ||
* @returns {Promise<import('./typedefs.js').CookieResponse>} | ||
@@ -340,0 +340,0 @@ */ |
{ | ||
"name": "tlsclientwrapper", | ||
"version": "1.4.3", | ||
"version": "2.0.0", | ||
"main": "index.js", | ||
@@ -13,3 +13,3 @@ "scripts": { | ||
"dependencies": { | ||
"ffi-rs": "^1.0.74", | ||
"koffi": "^2.8.9", | ||
"node-fetch": "^3.3.2", | ||
@@ -16,0 +16,0 @@ "workerpool": "^9.1.0" |
# TlsClientWrapper | ||
A wrapper for `bogdanfinn/tls-client` based on ffi-rs for unparalleled performance and usability. Inspired by `@dryft/tlsclient`. | ||
A wrapper for `bogdanfinn/tls-client` based on koffi for unparalleled performance and usability. Inspired by `@dryft/tlsclient`. | ||
@@ -13,3 +13,3 @@ # Installation | ||
1. Advanced JSDocs for faster development. | ||
2. Use of the more updated ffi-rs. | ||
2. Use of the more updated koffi. | ||
3. Automatic conversations, session support, etc. | ||
@@ -77,3 +77,4 @@ 4. Default settings compatible with bogdafinn's client. | ||
> ⚠️ Warning ⚠️ | ||
> All the JSDocs are currently based on the TLSClient Version 1.7.2, if you're using a custom LibraryPath it will not update the JSDocs. | ||
> - All the JSDocs are currently based on the TLSClient Version 1.7.5, if you're using a custom LibraryPath it will not update the JSDocs. | ||
> - Koffi isn't might not be supported by your platform. Please check: https://github.com/Koromix/koffi and verify that your platform is officially supported. | ||
@@ -84,3 +85,3 @@ ### Constructor Options | ||
* @typedef {Object} TlsClientDefaultOptions | ||
* @property {ClientProfile} [tlsClientIdentifier='chrome_120'] - Identifier of the TLS client | ||
* @property {ClientProfile} [tlsClientIdentifier='chrome_124'] - Identifier of the TLS client | ||
* @property {boolean} [rotateSessions=false] - If true, sessions will be rotated on each request -> This will cause the cookies to be reset | ||
@@ -87,0 +88,0 @@ * @property {string|null} [customLibraryPath=null] - Path to the custom library file |
67
test.js
@@ -99,6 +99,6 @@ import TlsDependency from "./utils/path.js"; | ||
const response = await tlsClient.get("https://echo.zuplo.io/", { | ||
withDebug: false | ||
//withDebug: false | ||
}); | ||
const end = performance.now(); | ||
console.log(response) | ||
//console.log(response) | ||
console.log(`Total time: ${end - start} ms`); | ||
@@ -178,22 +178,25 @@ await tlsClient.terminate() | ||
(async () => { | ||
await oneRequest(); | ||
//await oneRequest(); | ||
//await axiosTest(); | ||
//await runRequests(); | ||
// let i = 0; | ||
// while (true) { | ||
// let promises = []; | ||
// for (let i = 0; i < 250; i++) { | ||
// promises.push(oneRequest()); | ||
// } | ||
// | ||
// await Promise.allSettled(promises); | ||
// i++; | ||
// console.log(i); | ||
// console.log(process.memoryUsage()); | ||
// | ||
// if(i >= 10) { | ||
// throw new Error("SIGINT received"); | ||
// break; | ||
// } | ||
// } | ||
let i = 0; | ||
while (true) { | ||
let promises = []; | ||
for (let i = 0; i < 250; i++) { | ||
promises.push(oneRequest()); | ||
} | ||
await Promise.allSettled(promises); | ||
i++; | ||
console.log(i); | ||
console.log(process.memoryUsage()); | ||
if (i >= 10) { | ||
await sleep(15000); | ||
throw new Error("SIGINT received"); | ||
break; | ||
} | ||
} | ||
//await oneAxiosRequest(); | ||
@@ -206,14 +209,14 @@ //await defineAndGo(); | ||
process.once('SIGINT', () => { | ||
throw new Error("SIGINT received"); | ||
}) | ||
// process.once('SIGINT', () => { | ||
// throw new Error("SIGINT received"); | ||
// }) | ||
// | ||
//on exit | ||
// process.once('uncaughtException', async () => { | ||
// console.log(process.memoryUsage()); | ||
// console.log("Exiting..."); | ||
// await sleep(5000); | ||
// v8.writeHeapSnapshot(path.join(process.cwd(), 'heapdump', Date.now() + 'heapdump.heapsnapshot')); | ||
// process.exit(0); | ||
// }); | ||
// on exit | ||
process.once('uncaughtException', async () => { | ||
console.log(process.memoryUsage()); | ||
console.log("Exiting..."); | ||
await sleep(5000); | ||
v8.writeHeapSnapshot(path.join(process.cwd(), 'heapdump', Date.now() + 'heapdump.heapsnapshot')); | ||
process.exit(0); | ||
}); | ||
/** | ||
* @typedef {"chrome_103"|"chrome_104"|"chrome_105"|"chrome_106"|"chrome_107"|"chrome_108"|"chrome_109"|"chrome_110"|"chrome_111"|"chrome_112"|"chrome_116_PSK"|"chrome_116_PSK_PQ"|"chrome_117"|"chrome_120"} ChromeProfile | ||
* @typedef {"chrome_103"|"chrome_104"|"chrome_105"|"chrome_106"|"chrome_107"|"chrome_108"|"chrome_109"|"chrome_110"|"chrome_111"|"chrome_112"|"chrome_116_PSK"|"chrome_116_PSK_PQ"|"chrome_117"|"chrome_120"|"chrome_124"} ChromeProfile | ||
*/ | ||
@@ -83,3 +83,3 @@ | ||
* @typedef {Object} TlsClientDefaultOptions | ||
* @property {ClientProfile} [tlsClientIdentifier='chrome_120'] - Identifier of the TLS client | ||
* @property {ClientProfile} [tlsClientIdentifier='chrome_124'] - Identifier of the TLS client | ||
* @property {boolean} [rotateSessions=false] - If true, sessions will be rotated on each request -> This will cause the cookies to be reset | ||
@@ -98,3 +98,3 @@ * @property {string|null} [customLibraryPath=null] - Path to the custom library file | ||
* @property {string[]} [headerOrder=["host", "user-agent", "accept", "accept-language", "accept-encoding", "connection", "upgrade-insecure-requests", "if-modified-since", "cache-control", "dnt", "content-length", "content-type", "range", "authorization", "x-real-ip", "x-forwarded-for", "x-requested-with", "x-csrf-token", "x-request-id", "sec-ch-ua", "sec-ch-ua-mobile", "sec-ch-ua-platform", "sec-fetch-dest", "sec-fetch-mode", "sec-fetch-site", "origin", "referer", "pragma", "max-forwards", "x-http-method-override", "if-unmodified-since", "if-none-match", "if-match", "if-range", "accept-datetime"]] - Order of headers | ||
* @property {Object|null} [defaultHeaders=Object] - default headers which will be used in every request - Default: UserAgent Chrome v120 | ||
* @property {Object|null} [defaultHeaders=Object] - default headers which will be used in every request - Default: UserAgent Chrome v124 | ||
* @property {boolean} [insecureSkipVerify=false] - If true, insecure verification will be skipped | ||
@@ -101,0 +101,0 @@ * @property {boolean} [isByteRequest=false] - If true, the request is a byte request |
@@ -1,2 +0,2 @@ | ||
import ffiRs from 'ffi-rs'; | ||
import koffi from 'koffi'; | ||
import workerpool from 'workerpool'; | ||
@@ -22,2 +22,4 @@ import TlsDependency from './path.js'; | ||
this.TLS_LIB_PATH = this.customPath ? options?.customLibraryPath : this.tlsDependencyPath?.TLS_LIB_PATH; | ||
this.lib = null; | ||
} | ||
@@ -61,64 +63,17 @@ | ||
ffiRs.open({ | ||
library: 'tls', | ||
path: this.TLS_LIB_PATH, | ||
}) | ||
this.lib = koffi.load(this.TLS_LIB_PATH); | ||
} | ||
createInstance() { | ||
if (!this.lib) { | ||
throw new Error('Library not loaded'); | ||
} | ||
return { | ||
request: (payload) => { | ||
return ffiRs.load({ | ||
library: 'tls', | ||
funcName: 'request', | ||
retType: 0, | ||
paramsType: [0], | ||
paramsValue: [payload] | ||
}) | ||
}, | ||
getCookiesFromSession: (payload) => { | ||
return ffiRs.load({ | ||
library: 'tls', | ||
funcName: 'getCookiesFromSession', | ||
retType: 0, | ||
paramsType: [0], | ||
paramsValue: [payload] | ||
}) | ||
}, | ||
addCookiesToSession: (payload) => { | ||
return ffiRs.load({ | ||
library: 'tls', | ||
funcName: 'addCookiesToSession', | ||
retType: 0, | ||
paramsType: [0], | ||
paramsValue: [payload] | ||
}) | ||
}, | ||
freeMemory: (payload) => { | ||
return ffiRs.load({ | ||
library: 'tls', | ||
funcName: 'freeMemory', | ||
retType: 2, | ||
paramsType: [0], | ||
paramsValue: [payload] | ||
}) | ||
}, | ||
destroyAll: () => { | ||
return ffiRs.load({ | ||
library: 'tls', | ||
funcName: 'destroyAll', | ||
retType: 0, | ||
paramsType: [], | ||
paramsValue: [] | ||
}) | ||
}, | ||
destroySession: (payload) => { | ||
return ffiRs.load({ | ||
library: 'tls', | ||
funcName: 'destroySession', | ||
retType: 0, | ||
paramsType: [0], | ||
paramsValue: [payload] | ||
}) | ||
}, | ||
request: this.lib.func('request', 'string', ['string']), | ||
getCookiesFromSession: this.lib.func('getCookiesFromSession', 'string', ['string']), | ||
addCookiesToSession: this.lib.func('addCookiesToSession', 'string', ['string']), | ||
freeMemory: this.lib.func('freeMemory', 'void', ['string']), | ||
destroyAll: this.lib.func('destroyAll', 'void', []), | ||
destroySession: this.lib.func('destroySession', 'string', ['string']), | ||
} | ||
@@ -130,10 +85,3 @@ } | ||
workerpool.worker({ | ||
request: instance.request, | ||
getCookiesFromSession: instance.getCookiesFromSession, | ||
addCookiesToSession: instance.addCookiesToSession, | ||
freeMemory: instance.freeMemory, | ||
destroyAll: instance.destroyAll, | ||
destroySession: instance.destroySession, | ||
}); | ||
workerpool.worker(instance); | ||
} | ||
@@ -152,3 +100,4 @@ | ||
const client = new Client(); | ||
await client.open(); | ||
client.startWorker(); | ||
} |
@@ -11,3 +11,3 @@ import fs from "node:fs"; | ||
this.platform = os.platform(); | ||
this.version = "1.7.4"; | ||
this.version = "1.7.5"; | ||
this.filename = "tls-client-xgo"; | ||
@@ -14,0 +14,0 @@ this.extension = ""; |
180
46514
806
+ Addedkoffi@^2.8.9
+ Addedkoffi@2.10.1(transitive)
- Removedffi-rs@^1.0.74
- Removed@yuuang/ffi-rs-darwin-arm64@1.2.5(transitive)
- Removed@yuuang/ffi-rs-darwin-x64@1.2.5(transitive)
- Removed@yuuang/ffi-rs-linux-arm-gnueabihf@1.2.5(transitive)
- Removed@yuuang/ffi-rs-linux-arm64-gnu@1.2.5(transitive)
- Removed@yuuang/ffi-rs-linux-arm64-musl@1.2.5(transitive)
- Removed@yuuang/ffi-rs-linux-x64-gnu@1.2.5(transitive)
- Removed@yuuang/ffi-rs-linux-x64-musl@1.2.5(transitive)
- Removed@yuuang/ffi-rs-win32-arm64-msvc@1.2.5(transitive)
- Removed@yuuang/ffi-rs-win32-ia32-msvc@1.2.5(transitive)
- Removed@yuuang/ffi-rs-win32-x64-msvc@1.2.5(transitive)
- Removedffi-rs@1.2.5(transitive)