UNPKG

@withkeystone/cli

Version:

Keystone CLI - Test automation for modern web apps

67 lines 2.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.findChrome = findChrome; exports.launchBrowser = launchBrowser; const puppeteer_core_1 = __importDefault(require("puppeteer-core")); const fs_1 = require("fs"); const child_process_1 = require("child_process"); const os_1 = __importDefault(require("os")); // Platform-specific Chrome paths const CHROME_PATHS = { darwin: [ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium', ], win32: [ 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', ], linux: [ '/usr/bin/google-chrome-stable', '/usr/bin/google-chrome', '/usr/bin/chromium-browser', '/usr/bin/chromium', ] }; async function findChrome() { const platform = os_1.default.platform(); const paths = CHROME_PATHS[platform] || CHROME_PATHS.linux; // Check common paths for (const path of paths) { if ((0, fs_1.existsSync)(path)) { console.log(`[Browser] Found Chrome at: ${path}`); return path; } } // Try 'which' command try { const path = (0, child_process_1.execSync)('which chromium || which google-chrome || which chrome', { encoding: 'utf8' }).trim(); if (path) { console.log(`[Browser] Found Chrome via which: ${path}`); return path; } } catch { } throw new Error('Chrome/Chromium not found. Please install Chrome or set CHROME_PATH environment variable.'); } async function launchBrowser(options) { return await puppeteer_core_1.default.launch({ headless: options.headless || false, executablePath: options.executablePath, defaultViewport: { width: 1440, height: 900 }, args: [ '--window-size=1440,900', // Ensure consistent window size '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-web-security', // Allow iframe embedding of localhost '--allow-insecure-localhost' ] }); } //# sourceMappingURL=browser.js.map