首页 > 解决方案 > Puppeteer - UnhandledPromiseRejectionWarning

问题描述

我尝试使用木偶师,

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://10.1.40.117/print/d37a2017-4bc4-46fb-9a8a-7ddc31e65a33', {waitUntil: 'networkidle2'});
  await page.pdf({path: 'hn.pdf', format: 'A4'});

  await browser.close();
})();

收到以下错误,

(node:16064) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: net::ERR_CERT_AUTHORITY_INVALID at https://10.1.40.117/print/d37a2017-4bc4-46fb-9a8a-7ddc31e65a33
(node:16064) [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.

对此有什么帮助吗?

标签: node.jspdfnpmpuppeteer

解决方案


ignoreHTTPSErrors: true启动浏览器实例时尝试。当您在本地使用自签名证书时会发生这种情况。

解决方案:

const browser = await puppeteer.launch({ignoreHTTPSErrors: true});

推荐阅读