UNPKG

webcapt

Version:

A simple cli to screen capture web pages and save them to disk as images or pdfs.

26 lines (25 loc) 778 B
import puppeteer from 'puppeteer'; import { nodeFs } from './fs.js'; export let chromeBrowser = null; export async function getChromeBrowser() { chromeBrowser ??= await puppeteer.launch({ executablePath: findChrome(), }); return chromeBrowser; } export async function closeBrowser() { await chromeBrowser?.close(); chromeBrowser = null; } export function findChrome(fs = nodeFs) { const paths = [ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/usr/bin/google-chrome', 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', ]; for (const path of paths) { if (fs.exists(path)) return path; } throw new Error('Chrome not found. Please install Google Chrome.'); }