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);

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

查看所有标签

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

Introduction to the Design and Analysis of Algorithms

Introduction to the Design and Analysis of Algorithms

Anany Levitin / Addison Wesley / 2006-2-24 / USD 122.00

Based on a Based on a new classification of algorithm design techniques and a clear delineation of analysis methods, "Introduction to the Design and Analysis of Algorithms" presents the subject in a c......一起来看看 《Introduction to the Design and Analysis of Algorithms》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

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

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具