错误:无法启动浏览器进程! Whatsapp 网页 js | Azure 门户 Linux 木偶师

问题描述 投票:0回答:3

我正在尝试使用 Whatsapp web js,它在我的本地主机中工作正常,但是当我尝试推送到 Azure Linux 托管时,我收到此错误。

/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241
            reject(new Error([
                   ^

Error: Failed to launch the browser process!
/node_modules/whatsapp-web.js/node_modules/puppeteer/.local-chromium/linux-982053/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory

    at onClose (/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
    at Interface.<anonymous> (/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:231:68)
    at Interface.emit (node:events:402:35)
    at Interface.close (node:readline:586:8)
    at Socket.onend (node:readline:277:10)
    at Socket.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm info lifecycle [email protected]~start: Failed to exec start script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm timing npm Completed in 105615ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-07-15T12_45_52_651Z-debug.log

我的包json文件如下:

Node > 16.0 
NPM > 8.0
whatsapp-web.js": "^1.15.8"
"puppeteer": "^12.0.1"
node.js linux azure puppeteer whatsapp
3个回答
4
投票

根据非 GUI 环境的文档,例如LinuxUbuntu 等,您必须遵循一些步骤才能使 puppeteer 正常工作。 设置:

  1. 首先确保您的软件包是最新的。

    sudo apt-get update 

  2. 然后安装一些额外的软件包

$ sudo apt install -y gconf-service libgbm-dev libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 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 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

  1. 现在您需要指定一些参数来启动浏览器。在启动时添加此 agr
    --no-sandbox
    如果您没有 root 权限,还可以添加
    --disable-setuid-sandbox
    。你的代码应该看起来像 -

index.js

new Client({
    ...,
    puppeteer: {
        args: [
          '--no-sandbox',
          '--disable-setuid-sandbox'
        ],
        authStrategy: // what ever authStrategy you are using
    }
})
  1. 是的,你完成了!!

1
投票

错误:无法启动浏览器进程! /node_modules/whatsappweb.js/node_modules/puppeteer/.local-chromium/linux-982053/chrome-linux/chrome:加载共享库时出错:libgobject-2.0.so.0:无法打开共享对象文件:没有这样的文件或目录

Whatsapp-web.js 高度不稳定。请尝试从package.json 中卸载whatsapp-web.js 依赖项并重新安装。

  1. 安装更新

    sudo apt-get update -y then -> sudo apt install -y libatk-bridge2.0-0 && sudo apt install -y libxkbcommon-x11-0 && sudo apt-get install -y libxdamage-dev
    
  2. 安装 Chromium 浏览器。

      sudo apt-get install chromium-browser
    
  3. 安装ubuntu所需的其他依赖项

          sudo apt-get install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 li-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 li libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
    

随着whatsapp-web.js不断更新,到时候可能需要安装更多依赖项,并检查docker文件构建步骤,这是由@thedavidbarton所说的。

参考: node.js - 错误:无法启动浏览器进程 puppeteer - 堆栈内存溢出


-2
投票

使用windows初始化项目(创建自己的样板) 步骤:

mkdir whatapp_bot cd whatapp_bot npm init -y npm i whatsapp-web.js

如果出现铬问题:

node node_modules/puppeteer/install.js

如果一切成功,将whatapp_bot文件夹及其node_modules传输到linux ubuntu计算机

© www.soinside.com 2019 - 2024. All rights reserved.