如何使用puppeteer-core,puppeteer使用本地Chrome,puppeteer下载失败问题

puppeteer由于众所周知的原因会下载失败,我们可以使用puppeteer-core配合本地的Chrome或者Chrome Canary来使用:
首先安装puppeteer-core和Carlo(会用到Carlo的find_chrome模块,可以在node_modules/carlo/lib/目录下找到)
//安装对应chrome@71对应的puppeteer
npm install puppeteer-core@chrome-71
//安装Carlo
npm i carlo
//或 yarn add carlo
不同版本的浏览器可以使用对应版本的puppeteer-core,以减少不兼容问题。
具体的puppeteer对应的Chrome版本查看:https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md 中的Releases per Chromium Version部分
const puppeteer = require('puppeteer-core');
//find_chrome模块来源于GoogleChromeLabs的Carlo,可以查看本机安装Chrome目录,详细请查看底部博客,

const findChrome = require('./node_modules/carlo/lib/find_chrome');

(async () => {
  let findChromePath = await findChrome({});
  let executablePath = findChromePath.executablePath;
  console.log(executablePath)
  const browser = await puppeteer.launch({
    executablePath,
    headless: false
  });

  const page = await browser.newPage();
  await page.goto('http://www.woleigequ.net/');
  /*
  	dosomeThing
  */

  await browser.close();
})();
以上代码部分来自下面的博客:

Web技术试炼地

chaos-fe

posted @   一颗小行星-  阅读(2427)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示