UNPKG

chrome-cookies-secure

Version:

Extract encrypted Google Chrome cookies for a url on a Mac, Linux or Windows

65 lines (54 loc) 2.05 kB
const puppeteer = require('puppeteer'); const path = require('path'); const fs = require('fs'); const assert = require('assert'); const chromeCookies = require('../index'); describe('Chrome Cookies Integration', function() { this.timeout(20000); // UI tests take time const testProfilePath = path.join(__dirname, 'test-profile'); before(async () => { // 1. Launch Puppeteer to create a real Chrome profile & cookie const browser = await puppeteer.launch({ headless: "new", userDataDir: testProfilePath, args: [ '--no-sandbox', '--disable-setuid-sandbox', '--password-store=basic' // Important: Keeps encryption simple for CI ] }); const page = await browser.newPage(); await page.goto('https://example.com'); // 2. Set a cookie programmatically await page.setCookie({ name: 'integration_test_cookie', value: 'secret_payload', domain: 'example.com' }); // 3. Close the browser to flush SQLite buffers to disk await browser.close(); }); it.only('should read the real cookie from the Puppeteer-generated DB', async () => { // Tell your lib to look at the newly created profile const cookiePath = path.join(testProfilePath, 'Default', 'Cookies'); const cookies = await chromeCookies.getCookiesPromised('https://example.com'); console.log(cookies); await joi.validate(cookies, joi.object().required()); // Adjust your library call to accept a custom path if it doesn't already // chromeCookies.getCookies('https://example.com', 'object', (err, cookies) => { // if (err) return done(err); // try { // assert.strictEqual(cookies.integration_test_cookie, 'secret_payload'); // done(); // } catch (e) { // done(e); // } // }, 'Default', testProfilePath); }); after(() => { // Clean up the temporary profile if (fs.existsSync(testProfilePath)) { fs.rmSync(testProfilePath, { recursive: true, force: true }); } }); });