chore: upgrade puppeteer usage to fit new version

This commit is contained in:
moonrailgun 2024-09-30 19:54:24 +08:00
parent c24e22d920
commit 9066792d74
2 changed files with 7 additions and 2 deletions

View File

@ -1,13 +1,18 @@
import puppeteer from 'puppeteer'; import puppeteer from 'puppeteer';
import lighthouse, { Result, generateReport } from 'lighthouse'; import lighthouse, { Result, generateReport } from 'lighthouse';
import { logger } from '../logger.js';
import { env } from '../env.js';
export async function generateLighthouse(url: string): Promise<Result> { export async function generateLighthouse(url: string): Promise<Result> {
logger.info('[Lighthouse] Generating Lighthouse report...', { url });
// Use Puppeteer to launch headless Chrome // Use Puppeteer to launch headless Chrome
// - Omit `--enable-automation` (See https://github.com/GoogleChrome/lighthouse/issues/12988) // - Omit `--enable-automation` (See https://github.com/GoogleChrome/lighthouse/issues/12988)
// - Don't use 800x600 default viewport // - Don't use 800x600 default viewport
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
// Set to false if you want to see the script in action. // Set to false if you want to see the script in action.
headless: 'new', executablePath: env.puppeteerExecutablePath,
headless: true,
args: ['--no-sandbox', '--single-process', '--disable-dev-shm-usage'], args: ['--no-sandbox', '--single-process', '--disable-dev-shm-usage'],
defaultViewport: null, defaultViewport: null,
ignoreDefaultArgs: ['--enable-automation'], ignoreDefaultArgs: ['--enable-automation'],

View File

@ -12,7 +12,7 @@ export async function screenshotWebsiteDetailImage(
) { ) {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
executablePath: env.puppeteerExecutablePath, executablePath: env.puppeteerExecutablePath,
headless: 'new', headless: true,
}); });
const page = await browser.newPage(); const page = await browser.newPage();
try { try {