@pricething/curl
Version:
A typescript wrapper around cURL-impersonate.
115 lines (114 loc) • 3.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveBrowser = exports.getDefaultPlatformBrowser = exports.getCompatibleBrowsers = exports.BROWSERS = exports.BINARY_PATH = void 0;
const node_path_1 = __importDefault(require("node:path"));
exports.BINARY_PATH = node_path_1.default.join(__dirname, "..", "bin", process.platform);
exports.BROWSERS = {
win32: [
{
name: "chrome",
arch: "x64",
binary: "chrome-x64.exe"
},
{
name: "safari",
arch: "x64",
binary: "chrome-x64.exe"
},
{
name: "firefox",
arch: "x64",
binary: "chrome-x64.exe"
}
],
darwin: [
{
name: "firefox",
arch: "x64",
binary: "chrome-x64"
},
{
name: "chrome",
arch: "x64",
binary: "chrome-x64"
},
{
name: "chrome",
arch: "arm64",
binary: "chrome-arm64"
},
{
name: "safari",
arch: "x64",
binary: "chrome-x64"
},
{
name: "safari",
arch: "arm64",
binary: "chrome-arm64"
}
],
linux: [
{
name: "firefox",
arch: "x64",
binary: "chrome-x64"
},
{
name: "chrome",
arch: "x64",
binary: "chrome-x64"
},
{
name: "firefox",
arch: "arm64",
binary: "chrome-arm64"
},
{
name: "chrome",
arch: "arm64",
binary: "chrome-arm64"
},
{
name: "safari",
arch: "x64",
binary: "chrome-x64"
},
{
name: "safari",
arch: "arm64",
binary: "chrome-arm64"
}
]
};
const getCompatibleBrowsers = () => {
const browsers = exports.BROWSERS[process.platform];
if (browsers === undefined) {
throw new Error(`No browsers defined for the platform ${process.platform}`);
}
const matchingArchs = browsers.filter((b) => b.arch === process.arch);
if (matchingArchs.length === 0) {
const availableArchs = browsers.map((b) => b.arch).join(", ");
throw new Error(`Unable to find browser binary that matches system architecture (system: ${process.arch}, available: ${availableArchs})`);
}
return matchingArchs;
};
exports.getCompatibleBrowsers = getCompatibleBrowsers;
const getDefaultPlatformBrowser = () => {
const browsers = (0, exports.getCompatibleBrowsers)();
return browsers[0];
};
exports.getDefaultPlatformBrowser = getDefaultPlatformBrowser;
const resolveBrowser = (browser) => {
const browsers = (0, exports.getCompatibleBrowsers)();
const foundBrowser = browsers.find((b) => b.name === browser);
if (foundBrowser === undefined) {
const availableNames = browsers.map((b) => b.name).join(", ");
throw new Error(`Unable to find browser with name '${browser}' (available: ${availableNames})`);
}
return foundBrowser;
};
exports.resolveBrowser = resolveBrowser;