UNPKG

dev-lamp

Version:

Your friendly lighthouse performance companion - 100% local

119 lines 4.33 kB
"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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ChromeManager = void 0; const chromeLauncher = __importStar(require("chrome-launcher")); class ChromeManager { static instance; chromeInstance = null; useCount = 0; constructor() { } static getInstance() { if (!ChromeManager.instance) { ChromeManager.instance = new ChromeManager(); } return ChromeManager.instance; } async getChrome(options = {}) { if (!this.chromeInstance) { this.chromeInstance = await this.launchChrome(options); } this.useCount++; return this.chromeInstance; } async launchChrome(options) { const flags = [ '--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage', '--disable-setuid-sandbox', '--no-first-run', '--disable-default-apps', '--disable-extensions', '--disable-background-networking', '--disable-background-timer-throttling', '--disable-backgrounding-occluded-windows', '--disable-breakpad', '--disable-client-side-phishing-detection', '--disable-component-extensions-with-background-pages', '--disable-features=TranslateUI', '--disable-ipc-flooding-protection', '--disable-popup-blocking', '--disable-prompt-on-repost', '--disable-renderer-backgrounding', '--disable-sync', '--metrics-recording-only', '--no-default-browser-check', '--mute-audio', '--autoplay-policy=no-user-gesture-required', '--disable-blink-features=AutomationControlled' ]; if (options.headless !== false) { flags.push('--headless=new'); } try { return await chromeLauncher.launch({ chromeFlags: flags, chromePath: options.chromePath, port: options.port }); } catch (error) { if (error.code === 'ENOENT' || error.message?.includes('No Chrome installations found')) { const chromeNotFoundError = new Error('Chrome browser not found'); chromeNotFoundError.code = 'CHROME_NOT_FOUND'; throw chromeNotFoundError; } throw error; } } async cleanup() { this.useCount--; if (this.useCount <= 0 && this.chromeInstance) { await this.chromeInstance.kill(); this.chromeInstance = null; this.useCount = 0; } } async forceCleanup() { if (this.chromeInstance) { await this.chromeInstance.kill(); this.chromeInstance = null; this.useCount = 0; } } } exports.ChromeManager = ChromeManager; //# sourceMappingURL=chrome-manager.js.map