UNPKG

node-libcurl-ja3

Version:

Node.js native bindings for libcurl-impersonate. Impersonate Chrome, Edge, Firefox and Safari TLS fingerprints.

124 lines 5.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurlOptionsFromBrowserConfig = exports.getCurlOptionsFromBrowser = exports.BROWSER_CONFIGS = exports.Browser = exports.getSafariConfig = exports.getFirefoxConfig = exports.getEdgeConfig = exports.getChromeConfig = void 0; const CurlSslVersion_1 = require("../../enum/CurlSslVersion"); const chrome_1 = require("./chrome"); const edge_1 = require("./edge"); const firefox_1 = require("./firefox"); const safari_1 = require("./safari"); var chrome_2 = require("./chrome"); Object.defineProperty(exports, "getChromeConfig", { enumerable: true, get: function () { return chrome_2.getChromeConfig; } }); var edge_2 = require("./edge"); Object.defineProperty(exports, "getEdgeConfig", { enumerable: true, get: function () { return edge_2.getEdgeConfig; } }); var firefox_2 = require("./firefox"); Object.defineProperty(exports, "getFirefoxConfig", { enumerable: true, get: function () { return firefox_2.getFirefoxConfig; } }); var safari_2 = require("./safari"); Object.defineProperty(exports, "getSafariConfig", { enumerable: true, get: function () { return safari_2.getSafariConfig; } }); exports.Browser = { ...chrome_1.ChromeBrowser, ...edge_1.EdgeBrowser, ...firefox_1.FirefoxBrowser, ...safari_1.SafariBrowser, }; exports.BROWSER_CONFIGS = { ...chrome_1.CHROME_BROWSER_CONFIGS, ...edge_1.EDGE_BROWSER_CONFIGS, ...firefox_1.FIREFOX_BROWSER_CONFIGS, ...safari_1.SAFARI_BROWSER_CONFIGS, }; function getCurlOptionsFromBrowser(browser) { const config = exports.BROWSER_CONFIGS[browser]; if (!config) { throw new Error(`Unsupported browser: ${browser}`); } return getCurlOptionsFromBrowserConfig(config); } exports.getCurlOptionsFromBrowser = getCurlOptionsFromBrowser; function getCurlOptionsFromBrowserConfig(config) { var _a; const headersList = Object.entries(config.headers).map(([key, value]) => `${key}: ${value}`); const curlOptions = { HTTPHEADER: headersList, TLS_STATUS_REQUEST: 1, }; if (config.tlsVersion) { let tlsVersion = config.tlsVersion; // fixme setting tls as 1.3 causes an error if (tlsVersion === CurlSslVersion_1.CurlSslVersion.TlsV1_3) { tlsVersion = CurlSslVersion_1.CurlSslVersion.TlsV1_2; } curlOptions.SSLVERSION = tlsVersion; } if (config.ciphers) { curlOptions.SSL_CIPHER_LIST = config.ciphers; } if (config.curves) { curlOptions.SSL_EC_CURVES = config.curves; } if (config.signatureHashes) { curlOptions.SSL_SIG_HASH_ALGS = config.signatureHashes; } if (config.compressed) { const acceptEncoding = (_a = headersList .find((header) => header.toLowerCase().startsWith('accept-encoding:'))) === null || _a === void 0 ? void 0 : _a.split(':', 2)[1].trim(); curlOptions.ACCEPT_ENCODING = acceptEncoding || 'gzip, deflate, br, zstd'; } if (config.httpVersion) { curlOptions.HTTP_VERSION = config.httpVersion; } if (config.http2PseudoHeadersOrder) { curlOptions.HTTP2_PSEUDO_HEADERS_ORDER = config.http2PseudoHeadersOrder; } if (config.http2Settings) { curlOptions.HTTP2_SETTINGS = config.http2Settings; } if (typeof config.http2StreamExclusive === 'number') { curlOptions.STREAM_EXCLUSIVE = config.http2StreamExclusive; } // CURLOPT_STREAM_WEIGHT is not supported (issue in node bindings?) // if (typeof config.http2StreamWeight === 'number') { // curlyOptions.STREAM_WEIGHT = config.http2StreamWeight; // } if (typeof config.http2WindowUpdate === 'number') { curlOptions.HTTP2_WINDOW_UPDATE = config.http2WindowUpdate; } if (typeof config.alps === 'boolean') { curlOptions.SSL_ENABLE_ALPS = Number(config.alps); } if (config.ech) { curlOptions.ECH = config.ech; } if (config.sslCertCompression) { curlOptions.SSL_CERT_COMPRESSION = config.sslCertCompression; } if (config.tlsDelegatedCredentials) { curlOptions.TLS_DELEGATED_CREDENTIALS = config.tlsDelegatedCredentials; } if (config.tlsExtensionOrder) { curlOptions.TLS_EXTENSION_ORDER = config.tlsExtensionOrder; } if (typeof config.tlsGrease === 'boolean') { curlOptions.TLS_GREASE = Number(config.tlsGrease); } if (typeof config.tlsKeySharesLimit === 'number') { curlOptions.TLS_KEY_SHARES_LIMIT = config.tlsKeySharesLimit; } if (typeof config.tlsPermuteExtensions === 'boolean') { curlOptions.SSL_PERMUTE_EXTENSIONS = Number(config.tlsPermuteExtensions); } if (typeof config.tlsRecordSizeLimit === 'number') { curlOptions.TLS_RECORD_SIZE_LIMIT = config.tlsRecordSizeLimit; } if (typeof config.tlsSessionTicket === 'boolean') { curlOptions.SSL_ENABLE_TICKET = Number(config.tlsSessionTicket); } if (typeof config.tlsSignedCertTimestamps === 'boolean') { curlOptions.TLS_SIGNED_CERT_TIMESTAMPS = Number(config.tlsSignedCertTimestamps); } if (typeof config.tlsUseNewAlpsCodepoint === 'boolean') { curlOptions.TLS_USE_NEW_ALPS_CODEPOINT = Number(config.tlsUseNewAlpsCodepoint); } return curlOptions; } exports.getCurlOptionsFromBrowserConfig = getCurlOptionsFromBrowserConfig; //# sourceMappingURL=index.js.map