puppeteer 不在 vps 上工作,但在本地工作 运行
puppeteer not working on vps but running locally
我写了一个小木偶程序,让我登录 Twitter 并检查一些东西。在 mac OS Catalina 上,它在本地工作,但在 VPS ubuntu 18.04 上不起作用。并在开始时向我显示日志:
/root/retwiter/node_modules/puppeteer/.local-chromium/linux-800071/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
我有 2 个 运行 浏览器配置:
本地:
{
headless: false,
defaultViewport: null,
args: [
'--window-size=1920,1080'
]
}
vps:
{
headless: true,
defaultViewport: null,
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
]
}
我认为您缺少 libnss3 库,请尝试使用
安装它
sudo apt-get install libnss3-dev
如果这还不够,请安装 puppeteer 的所有部门
sudo apt-get install -y gconf-service 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 libgbm-dev
您可以将 AWS Elastic Beanstalk 配置文件 (.ebextensions
) 添加到 Web 应用程序的源代码中,以配置您的环境并自定义其中包含的 AWS 资源。
在我们的例子中,如果我们不启用 EPEL 并且如果我们继续安装 Chromium 作为 npm install 的一部分,Puppeteer 将无法启动 Chromium,因为 libatk-1.0.so.0
.
修补程序
将以下内容添加到您的应用根目录:
- 创建一个
.npmrc
文件。
- 将以下内容添加到您的
.npmrc
文件中:
unsafe-perm=true
.npmrc
文件定义了 npm 在 运行ning 命令时的行为方式。将 unsafe-perm
设置为 true
会在 运行 宁包脚本时抑制 UID/GID 切换。将 unsafe-perm 标志设置为 运行 具有 root 权限的脚本。
- 来源@unsafe-perm
- 创建一个
.ebextensions
文件夹。
- 在
.ebextensions
文件夹中,创建一个 01_enableEPEL.config
文件并添加以下内容。
commands:
01_enableEPEL:
command: sudo amazon-linux-extras install epel -y
- 在
.ebextensions
文件夹中,创建一个 02_installEPELPackages.config
文件并添加以下内容
packages:
yum:
chromium: []
您可以在我的 GitHub @ https://github.com/amarinediary/Marionette
上查看相同的指南
我写了一个小木偶程序,让我登录 Twitter 并检查一些东西。在 mac OS Catalina 上,它在本地工作,但在 VPS ubuntu 18.04 上不起作用。并在开始时向我显示日志:
/root/retwiter/node_modules/puppeteer/.local-chromium/linux-800071/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
我有 2 个 运行 浏览器配置: 本地:
{
headless: false,
defaultViewport: null,
args: [
'--window-size=1920,1080'
]
}
vps:
{
headless: true,
defaultViewport: null,
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
]
}
我认为您缺少 libnss3 库,请尝试使用
安装它sudo apt-get install libnss3-dev
如果这还不够,请安装 puppeteer 的所有部门
sudo apt-get install -y gconf-service 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 libgbm-dev
您可以将 AWS Elastic Beanstalk 配置文件 (.ebextensions
) 添加到 Web 应用程序的源代码中,以配置您的环境并自定义其中包含的 AWS 资源。
在我们的例子中,如果我们不启用 EPEL 并且如果我们继续安装 Chromium 作为 npm install 的一部分,Puppeteer 将无法启动 Chromium,因为 libatk-1.0.so.0
.
修补程序
将以下内容添加到您的应用根目录:
- 创建一个
.npmrc
文件。 - 将以下内容添加到您的
.npmrc
文件中:
unsafe-perm=true
.npmrc
文件定义了 npm 在 运行ning 命令时的行为方式。将 unsafe-perm
设置为 true
会在 运行 宁包脚本时抑制 UID/GID 切换。将 unsafe-perm 标志设置为 运行 具有 root 权限的脚本。
- 来源@unsafe-perm
- 创建一个
.ebextensions
文件夹。 - 在
.ebextensions
文件夹中,创建一个01_enableEPEL.config
文件并添加以下内容。
commands:
01_enableEPEL:
command: sudo amazon-linux-extras install epel -y
- 在
.ebextensions
文件夹中,创建一个02_installEPELPackages.config
文件并添加以下内容
packages:
yum:
chromium: []
您可以在我的 GitHub @ https://github.com/amarinediary/Marionette
上查看相同的指南