UNPKG

chrome-cookie-extractor

Version:

Extract and decrypt Chrome cookies with curl integration - includes auth-curl command for authenticated requests

140 lines 6.29 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const extractor_1 = require("./extractor"); const os = __importStar(require("os")); const program = new commander_1.Command(); program .name('chrome-cookies') .description('Extract Chrome cookies and convert to curl-compatible format') .version('1.0.0'); program .option('-d, --domain <domain>', 'Extract cookies for specific domain only') .option('-o, --output <file>', 'Output file path', 'cookies.txt') .option('-p, --profile <profile>', 'Chrome profile name (Default, Profile 1, etc.)') .option('--curl', 'Output in curl header format') .option('--json', 'Output in JSON format') .option('--list-profiles', 'List available Chrome profiles') .option('--verbose', 'Verbose output'); program.action(async (options) => { try { const extractor = new extractor_1.ChromeCookieExtractor(); const profiles = extractor.getProfiles(); if (options.listProfiles) { console.log(chalk_1.default.blue('Available Chrome/Brave profiles:')); if (profiles.length === 0) { console.log(chalk_1.default.yellow('No profiles found')); console.log(chalk_1.default.gray('Make sure Chrome or Brave is installed and has been run at least once.')); return; } profiles.forEach((profile, index) => { console.log(`${index + 1}. ${chalk_1.default.green(profile.name)} - ${chalk_1.default.gray(profile.path)}`); }); return; } if (profiles.length === 0) { console.error(chalk_1.default.red('❌ No Chrome/Brave profiles found')); console.error(chalk_1.default.gray('Make sure Chrome or Brave is installed and has been run at least once.')); process.exit(1); } if (options.verbose) { console.log(chalk_1.default.blue(`Found ${profiles.length} profile(s)`)); profiles.forEach(profile => { console.log(chalk_1.default.gray(` - ${profile.name}: ${profile.cookiesPath}`)); }); } const extractorOptions = {}; if (options.domain) { extractorOptions.domain = options.domain; } if (options.profile) { extractorOptions.profiles = [options.profile]; } if (options.verbose) { console.log(chalk_1.default.blue('Extracting cookies...')); if (os.platform() === 'darwin') { console.log(chalk_1.default.yellow('Note: On macOS, encrypted cookies will be decrypted if possible.')); } } const cookies = await extractor.extractCookies(extractorOptions); if (cookies.length === 0) { console.error(chalk_1.default.yellow('⚠️ No cookies found')); if (options.domain) { console.error(chalk_1.default.gray(`Try without domain filter or check if '${options.domain}' is correct`)); } process.exit(1); } const encryptedCount = cookies.filter(c => c.value === '[ENCRYPTED]').length; const validCount = cookies.length - encryptedCount; if (options.verbose) { console.log(chalk_1.default.green(`✅ Extracted ${cookies.length} cookie(s)`)); if (encryptedCount > 0) { console.log(chalk_1.default.yellow(`⚠️ ${encryptedCount} cookie(s) are encrypted and could not be decrypted`)); } console.log(chalk_1.default.green(`📊 ${validCount} usable cookie(s)`)); } if (options.json) { console.log(extractor.formatAsJson(cookies)); } else if (options.curl) { const curlFormat = extractor.formatAsCurl(cookies); if (curlFormat) { console.log(curlFormat); } else { console.error(chalk_1.default.red('❌ No usable cookies found (all encrypted)')); process.exit(1); } } else { // Save as Netscape format await extractor.saveCookiesFile(cookies, options.output); console.log(chalk_1.default.green(`✅ Cookies saved to ${options.output}`)); if (options.verbose) { console.log(chalk_1.default.blue('\nUsage examples:')); console.log(chalk_1.default.gray(` curl -b ${options.output} https://example.com`)); console.log(chalk_1.default.gray(` wget --load-cookies ${options.output} https://example.com`)); } } } catch (error) { console.error(chalk_1.default.red('❌ Error:'), error.message); if (options.verbose && error.stack) { console.error(chalk_1.default.gray(error.stack)); } process.exit(1); } }); if (require.main === module) { program.parse(); } exports.default = program; //# sourceMappingURL=cli.js.map