使用puppeteer 提示Error: Failed to launch the browser process解决办法
记一次在ubuntu18上使用puppeteer的经过
通过远程的code-server使用puppeteer实现在nodejs上也能给网页截图, 但是运行官网上的示例报错.如下:
const puppeteer = require('puppeteer');(async () => {const browser = await puppeteer.launch()const page = await browser.newPage()await page.goto('https://bilibili.com/')await page.screenshot({ path: 'example.png' })await browser.close()
})()
运行后提示error:
Error: Failed to launch the browser process!/var/app/current/node_modules/puppeteer/.local-chromium/linux-848005./chrome-linux/chrome: error while loading shared libraries: libxkbcommon.so.0: cannot open shared object file: No such file or directoryTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.mdat onClose (/var/app/current/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)at Interface.<anonymous> (/var/app/current/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)at Interface.emit (events.js:323:22)at Interface.close (readline.js:409:8)at Socket.onend (readline.js:187:10)at Socket.emit (events.js:323:22)at endReadableNT (_stream_readable.js:1204:12)at processTicksAndRejections (internal/process/task_queues.js:84:21)
于是在github上的puppeteer/issues查询, 网址:
https://github.com/puppeteer/puppeteer/issues/6922
实际上是系统缺少一些包, 而且puppeteer的文档中也写得很详细:在
https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
由于我的系统是ubuntu18, 所以需要安装他列举的所有依赖
sudo apt-get install ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils -y
之后运行时, 提示另外一个错误:
(node:5267) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
[0308/163337.932654:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
在文档中有提到,
https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
将代码改为:
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] })
就可以正常运行, 但是官方并不推荐我们这么做就是了, 在截图没截到的下方有其他推荐的做法.
使用puppeteer 提示Error: Failed to launch the browser process解决办法相关推荐
- 升级Android Studio 导致的 `Error:Failed to notify project evaluation listener.`解决办法
最近升级Android Studio和sdk后, gradle同步项目时忽然报错, Error:Failed to notify project evaluation listener.截图如下, 更 ...
- linux下解压大于4G文件提示error: Zip file too big错误的解决办法
error: Zip file too big (greater than 4294959102 bytes)错误解决办法.zip文件夹大于4GB,在centos下无法正常unzip,需要使用第三方工 ...
- idea中项目编译提示Error(1,1) java:非法字符的解决办法(亲测有效)
从eclipse中导入项目运行是提示非法字符 查找答案得出原因是编码问题 设置的idea默认使用的是UTF-8编码但是我之前eclispe中项目编码也是UTF-8 整个项目中只有以上几处提示Error ...
- Androidstudio下Generate signed apk提示Error: Expected resource of type id [ResourceType]解决办法...
只需要在报错位置所在的类上面添加: @SuppressWarnings("ResourceType") 即可实现Generate signed apk.
- error: failed to launch '/private/var/mobile/Applications/** busy解决办法
error: failed to launch '/private/var/mobile/Applications/** -busy 今天遇到了这个问题,搜索了一下看到好多是关于timeout的解决办 ...
- oracle ipc message,【案例】Oracle RAC IPC send timeout error导致RAC的节点挂起解决办法
天萃荷净 Oracle研究中心案例分析:运维DBA反映Oracle RAC环境数据库节点挂起,分享日志发现是由于IPC send timeout error导致RAC的节点挂起. 本站文章除注明转载外 ...
- Error loading native library: libnjni9.so.的解决办法
Error loading native library: libnjni9.so.的解决办法 $ netca Error loading native library: libnjni9.so. j ...
- Error: Cannot find module ‘webpack-cli/bin/config-yargs‘ 解决办法
在webpack配置自动打包功能的时候,执行打包命令npm run dev报错: Error: Cannot find module 'webpack-cli/bin/config-yargs' 解决 ...
- pycharm报错:Error configuring SDK: Accessing invalid virtual file: 解决办法
pycharm报错:Error configuring SDK: Accessing invalid virtual file: 解决办法: 针对linux系统, 删除home目录下pycharm配置 ...
最新文章
- 实现数组字符串翻转的两种方法
- 写 Python 代码不可不知的函数式编程技术
- juc java_深入理解JUC(java.util.concurrent)
- mysql order by 多字段排序
- java 字符串过长_idea java常量字符串过长解决办法
- 天气小工具新增风格-默认无背景,感谢欧阳兄制作
- 历届冬奥会举办地与举办时间
- .Net使用RabbitMQ详解
- python header头部请求_python3爬虫怎样构建请求header
- System V 共享内存区
- mysql 优化器 cost评估_MySQL优化器cost计算
- harmonyos 2.0开机动画壁纸,华为鸿蒙OS 2.0开机动画
- Windows系统查询硬盘序列号
- RT struct 文件 保存为nii文件及解析
- 电子数据取证基础知识5
- 金蝶盘点机PDA仓库条码管理:仓库如何盘点
- 快速获取网站媒体资源方法
- 在香港不能用GPRS上網(转)
- 使用 Wall 搭建个人照片墙和视频墙
- 利用wxid批量加好友