解决 Could not find expected browser (chrome) locally

8 min read

(node:72421) UnhandledPromiseRejectionWarning: Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (970485).
    at ChromeLauncher.launch (/Users/pan/crawl/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:101:23)
    at async getNewList (/Users/pan/crawl/index.js:10:19)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:72421) 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:72421) [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.

Mac 系统需要下载 chromium

下载地址

https://download-chromium.appspot.com/

然后添加puppeteer 的执行路径

const browser = await puppeteer.launch({
    headless: false,
    timeout: 0,
    devtools: false,
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
  });