Puppeteer启动Chrome失败提示缺失共享库libXcomposite.so.1如何解决
Puppeteer Chrome启动缺失libXcomposite.so.1修复方案
报错信息:
Error: Failed to launch chrome! /node_modules/puppeteer/.local-chromium/linux-662092/chrome-linux/chrome: error while loading shared libraries: libXcomposite.so.1: cannot open shared object file: No such file or directory
问题本质
Linux系统未安装Chromium运行依赖的X11相关系统库,其中libXcomposite.so.1属于libxcomposite1(Debian系)/libXcomposite(RHEL系)软件包。
修复步骤
步骤1:安装系统依赖
按你使用的操作系统发行版执行对应命令:
- Debian/Ubuntu 及衍生发行版
执行命令:sudo apt update && sudo apt install -y libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libasound2 libpangocairo-1.0-0 libatk1.0-0 libatk-bridge2.0-0 libgtk-3-0 - CentOS/RHEL 及衍生发行版
执行命令:sudo yum install -y libXcomposite libXcursor libXdamage libXi libXtst nss cups-libs libXScrnSaver libXrandr alsa-lib pango atk at-spi2-atk gtk3
步骤2:无GUI环境额外配置
如果运行环境是没有桌面的无头服务器,启动Puppeteer时添加以下参数规避额外报错:
const browser = await puppeteer.launch({ // 开启无头模式 headless: true, // 禁用沙箱(生产环境可根据安全需求调整配置) args: ['--no-sandbox', '--disable-setuid-sandbox'] });
步骤3:验证
重新运行Puppeteer相关脚本即可正常启动Chrome。
内容的提问来源于stack exchange,提问作者MemZ
相关产品推荐
相关产品推荐

