当前位置: 首页 > Web前端 > JavaScript

centos7puppeteer报错:启动浏览器进程失败!

时间:2023-03-26 20:45:26 JavaScript

错误提示Error:Failedtolaunchthebrowserprocess!......查看githubpuppeteer/issues:https://github.com/puppeteer/。..原因是系统缺少一些包,在puppeteer文档中也有解释:https://github.com/puppeteer/...解决安装依赖包的问题,??根据文档:yuminstallpango。x86_64libXcomposite.x86_64libXcursor.x86_64libXdamage.x86_64libXext.x86_64libXi.x86_64libXtst.x86_64cups-libs.x86_64libXScrnSaver.x86_64libXrandr.x86_64GConf2.x86_64alsa-lib.x86_64atk.x86_64gtk3.x86_64-yrestartthenodeservice,还是报错process![0308/163337.932654:ERROR:zygote_host_impl_linux.cc(90)]不支持不带--no-sandbox的root运行。请参阅https://crbug.com/638180。文档中也提到:https://github.com/puppeteer/...原因是Chromium是在root权限下打开的,可以换角色运行节点服务。另一种解决方案是在打开Chromium时传入参数:constbrowser=awaitpuppeteer.launch({args:['--no-sandbox','--disable-setuid-sandbox']})puppeteer不推荐这样做,但是我是来测试的,没关系,生产环境不要这样做。重启node服务,截图成功但是中文乱码,原因是centos7缺少中文字体。解决字体丢失下载安装字体:安装字体管理工具安装fontconfig管理字体库yum-yinstallfontconfig安装fontconfig后可以在/usr/shared目录下看到fonts和fontconfig目录(之前没有)查看全部fonts:fc-list查看中文字体:fc-list:lang=zh创建字体目录并修改权限创建字体目录:mkdir/usr/share/fonts/chinese修改字体文件的权限,允许非root用户也可以使用:chmod-R755/usr/share/fonts/chinese将字体COPY到/usr/share/fonts/chinese在Windows的C:\Windows\Fonts目录下找到需要的字体,复制到/usr/share/fonts目录下,添加雅黑和新松:msyh.ttc、simsun.ttc建立字体索引信息,更新字体缓存cd/usr/share/fonts/chinesemkfontscale//如果提示mkfontscale:commandnotfound,需要自己安装#yuminstallmkfontscalemkfontdirfc-cache-fv//如果fc-cache:commandnotfound提示,需要安装#yuminstallfontconfig