Set "PUPPETEER_SKIP_CHROMIUM_DOW

2019-04-22  本文已影响0人  mayufo

问题

最近学node, 之前用puppeteer写的抓包工具报错

UnhandledPromiseRejectionWarning: Error: Chromium revision is not downloaded. Run "npm install" or "yarn install"错误

但是如果你真的yarn一下就会报类似

Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD报错

解决

手动下载Chromium

下载地址:https://download-chromium.appspot.com/

把下载刚刚下载的文件解压到项目的chromium文件夹下,在chromium文件夹下你会看到chrome-mac文件

image.png

创建src/app.js

(async () => {
    const browser = await puppeteer.launch({
        executablePath: '../chromium/Chromium.app/Contents/MacOS/Chromium',
        headless: false
    });
    const page = await browser.newPage();
    await page.goto('https://www.baidu.com');

    // Get the "viewport" of the page, as reported by the page.
    const dimensions = await page.evaluate(() => {
        return {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight,
            deviceScaleFactor: window.devicePixelRatio
        };
    });

    console.log('Dimensions:', dimensions);

    await browser.close();
})();

以上解决!

上一篇下一篇

猜你喜欢

热点阅读