Puppeteer 异常处理

栏目: Node.js · 发布时间: 7年前

内容简介:从一个生成 PDF 的需求中接触到了 Puppeteer ,随着使用场景的深入,异常问题也越发难以处理。索性纪录一下摸索过程,供新手参考学习。UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Chromium revision is not downloaded. Run “npm install” or “yarn install”遇到这个问题,说明你并没有成功下载

从一个生成 PDF 的需求中接触到了 Puppeteer ,随着使用场景的深入,异常问题也越发难以处理。索性纪录一下摸索过程,供新手参考学习。

一、Chromium revision is not downloaded

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Chromium revision is not downloaded. Run “npm install” or “yarn install”

遇到这个问题,说明你并没有成功下载 Chromium

二、Unhandled promise rejection

需要使用 catch 处理异常

三、spawn EACCES

没有权限,需要执行:

sudo chmod -R a+rwx chromium/Chromium.app

四、PrintToPDF is not implemented

https://github.com/GoogleChrome/puppeteer/issues/576

五、生成 PDF 乱码问题

小技巧:如果你发现无头打印异常,可以将设置改掉 headless: false ,,通过调试 工具 打开。

六、在 Docker 中使用

https://www.meiwen.com.cn/subject/xkwsbftx.html

七、更改默认视口

await page.setViewport({width: 1024, height: 880});

八、设置 cookie

const COOKS =[
  {
  'domain': 'jartto.wang',
  'name': 'user',
  'value': 'jartto',
  }
]

await page.setCookie(...COOKS);

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Art of Computer Programming, Volume 3

The Art of Computer Programming, Volume 3

Donald E. Knuth / Addison-Wesley Professional / 1998-05-04 / USD 74.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 3》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具