puppeteer Failed to launch chrome!

尝试过网上说的以下配置,均无效:
// args: ['--no-sandbox'],
// args: ['--no-sandbox', '--disable-setuid-sandbox'],
// ignoreDefaultArgs: ['--disable-extensions'],

报错信息如下:

f:\demo\autoDevtool\2019-9-17>node demo1.js

(node:18336) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome! spawn "C:Program Files (x86)GoogleChromeApplicationchrome.exe" ENOENT
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
    at onClose (f:\demo\autoDevtool\node_modules\puppeteer\lib\Launcher.js:348:14)
    at ChildProcess.helper.addEventListener.error (f:\demo\autoDevtool\node_modules\puppeteer\lib\Launcher.js:339:64)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)
    at onErrorNT (internal/child_process.js:407:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:18336) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18336) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled
will terminate the Node.js process with a non-zero exit code.

代码如下:

const puppeteer = require('puppeteer');

(async () => {

    const browser = await puppeteer.launch({
        // args: ['--no-sandbox'],
        // args: ['--no-sandbox', '--disable-setuid-sandbox'],
        //  ignoreDefaultArgs: ['--disable-extensions'],
        //粗心大意!!!下面的写法是错误的
        executablePath: '"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"',
        //正确写法如下:
        executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
        headless: false

    })

    const page = await browser.newPage()

    await page.goto('http://www.baidu.com')

    await page.screenshot({
        //将会在当前目录下保存一张baidu.png
        path: './baidu.png'

    })

})()
阅读 5.9k
1 个回答

路径改成\试试

单个反斜杠会被解释成转移符

'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题