puppeteer外掛啟動chrome失敗: Error: Failed to launch the browser process!
阿新 • • 發佈:2020-07-20
最近使用puppeteer外掛啟動chrome失敗,有的系統無法啟動喚起chrome
自己膝上型電腦安裝有360會提示被阻止,允許執行即可呼叫成功,公司電腦,沒有任何提示直接無法啟動(公司防毒軟體無法配置關閉)
控制檯報錯:
(node:2620) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md at onClose (E:\shimoxix2\node\node-pup\node_modules\[email protected]@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:193:20) at ChildProcess.<anonymous> (E:\shimoxix2\node\node-pup\node_modules\[email protected]@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:184:79) at ChildProcess.emit (events.js:201:15) at Process.ChildProcess._handle.onexit (internal/child_process.js:257:12) (node:2620) 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:2620) [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,可以勉強使用,如果不允許瀏覽器可視,我做的頁面抓取內容會失敗。。
const browser = await puppeteer.launch({ //如果無法啟動chrome,指定瀏覽器路徑:executablePath,headless設定為false:可以看到瀏覽器 executablePath:'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', headless:false, //可以看到開啟瀏覽器效果,預設值true puppeteerOptions: { ignoreHTTPSErrors: true, dumpio: false, } });