Puppeteer:Could not find expected browser (chrome) locally?

// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('C:/Users/Administrator/node_modules/puppeteer-extra')

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('C:/Users/Administrator/node_modules/puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

// puppeteer usage as normal
puppeteer.launch({ headless: true }).then(async browser => {
    console.log('Running tests..')
    const page = await browser.newPage()
    await page.goto('https://cn.bing.com/?scope=web&FORM=ANNTH1')
    await page.waitForTimeout(5000)
    await page.screenshot({ path: 'd:/zhusc/testresult.png', fullPage: true })
    await browser.close()
    console.log(`All done, check the screenshot. ✨`)
})

报错:Error: Could not find expected browser (chrome) locally. Run npm install to download the correct Chromium revision (938248)
但是,我是有Chromium的

我也能运行这个浏览器的,以下代码运行成功

const puppeteer = require('D:/nodejs/node_global/node_modules/puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.addScriptTag({path:'D:/zhusc/stealth.min.js'})
await page.goto('https://cn.bing.com/?scope=web&FORM=ANNTH1');
await page.screenshot({path:'example.png'});
})();
阅读 7.6k
1 个回答

无头模式时要指定本地 chrome 的路径,不然就得下 puppeteer 里自带的。

见官方文档default-runtime-settings

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题