Ubuntu服务器安装puppeteer

安装puppeteer-core

npm i puppeteer-core

安装chromium-browser

npm install chromium-browser

初始化puppeteer对象时需要指定chromium-browser位置

whereis chromium-browser

chromium-browser: /usr/bin/chromium-browser

配置位置

/**
 * 浏览器对象
 */
const puppeteer = require('puppeteer');
/**
 * 浏览器对象
 */
let browser = null;
/**
 * 启动浏览器,并打开一个Page
 */
exports.getPage = async function getPage() {
    if (null == browser) {
        //启动浏览器
        browser = await puppeteer.launch({
            ignoreDefaultArgs: ['--enable-automation'],
            args: [
                '--no-sandbox',
                '--disable-setuid-sandbox'
            ],
            executablePath: '/usr/bin/chromium-browser'
        });
    }
    //打开一个page
    return await browser.newPage();
}

你可能感兴趣的:(Ubuntu服务器安装puppeteer)