一、error while loading shared libraries: libatk-1.0.so.0
报错:/home/work/node_modules/puppeteer/.local-chromium/linux-856583/chrome-linux/chrome: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory
解决:yum install atk
二、error while loading shared libraries: libatk-bridge-2.0.so.0
报错:/home/work/node_modules/puppeteer/.local-chromium/linux-856583/chrome-linux/chrome: error while loading shared libraries: libatk-bridge-2.0.so.0: cannot open shared object file: No such file or directory
解决:yum install at-spi2-atk
三、error while loading shared libraries: libxkbcommon.so.0
报错:/home/work/node_modules/puppeteer/.local-chromium/linux-856583/chrome-linux/chrome: error while loading shared libraries: libxkbcommon.so.0: cannot open shared object file: No such file or directory
解决:yum install libxkbcommon-x11-devel
四、error while loading shared libraries: libXcomposite.so
报错:/home/work/node_modules/puppeteer/.local-chromium/linux-856583/chrome-linux/chrome: error while loading shared libraries: libXcomposite.so.1: cannot open shared object file: No such file or directory
解决:yum install libXcomposite
五、error while loading shared libraries: libgtk-3.so.0:
报错:/home/work/node_modules/puppeteer/.local-chromium/linux-856583/chrome-linux/chrome: error while loading shared libraries: libgtk-3.so.0: cannot open shared object file: No such file or directory
解决:yum install gtk3
六、Running as root without --no-sandbox is not supported
报错Running as root without --no-sandbox is not supported
解决:启动参数添加 "args": ["--no-sandbox"]
例如:
const browser = await puppeteer.launch({
args: ["--no-sandbox"],
headless: true,
});
七、Puppeteer中文显示方块乱码解决
解决:这并不是Puppeteer的问题,实际上是Linux字体库对中文支持不好的原因。
我们只需要给服务器的Linux系统安装支持的中文字体库即可。这里推荐文泉驿字体 :
文泉驿是一个以开发开源、免费中文电子资源--如汉字字体、词库等--为目标的公益性组织。她的创办宗旨是实现“任何人在任何地方都可以自由使用汉字和汉语进行交流”。
——摘自百度百科
这里以CentOS为例,其他Linux系统也都有自己的包管理器,只是换个包管理器操作,安装步骤基本是一样的:
安装文泉字体:
yum install wqy-microhei-fonts.noarch -y
yum install wqy-unibit-fonts.noarch -y
yum install wqy-zenhei-fonts.noarch -y
安装完成,再次执行 Puppeteer
的操作,一切都显示正常了。