转载:https://wwwblogs/zhidong123/p/13345990.html

最近使用puppeteer插件启动chrome失败,有的系统无法启动唤起chrome

自己笔记本电脑安装有360会提示被阻止,允许执行即可调用成功,公司电脑,没有任何提示直接无法启动(公司杀毒软件无法配置关闭)

控制台报错:

D:\MyCode\node\09puppetter> node .\index.js       
(node:21488) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! spawn D:\MyCode\node\09puppetter\node_modules\_puppeteer@5.2.1@puppeteer\.local-chromium\win64-782078\chrome-win\chrome.exe ENOENT


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (D:\MyCode\node\09puppetter\node_modules\_puppeteer@5.2.1@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:193:20)        
    at ChildProcess.<anonymous> (D:\MyCode\node\09puppetter\node_modules\_puppeteer@5.2.1@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:185:85)
    at ChildProcess.emit (events.js:315:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
    at onErrorNT (internal/child_process.js:468:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21488) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rePS D:\MyCode\node\09puppetter> node .\index.js       
(node:21488) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! spawn D:\MyCode\node\09puppetter\node_modules\_puppeteer@5.2.1@puppeteer\.local-chromium\win64-782078\chrome-win\chrome.exe ENOENT


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (D:\MyCode\node\09puppetter\node_modules\_puppeteer@5.2.1@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:193:20)        
    at ChildProcess.<anonymous> (D:\MyCode\node\09puppetter\node_modules\_puppeteer@5.2.1@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:185:85)
    at ChildProcess.emit (events.js:315:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
    at onErrorNT (internal/child_process.js:468:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21488) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:21488) [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.

后来经过尝试发现

强制配置chrome路径executablePath,并指定可以打开看到浏览器效果headless,可以勉强使用,如果不允许浏览器可视,我做的页面抓取内容会失败。

    let browser = await puppeteer.launch({ 
        executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', 
        headless: false })

更多推荐

puppeteer插件启动chrome失败: Error: Failed to launch the browser process!