简体   繁体   English

如何使 Puppeteer 或 Playwright 在 Azure Web App Service (Linux) 上工作

[英]How to make Puppeteer or Playwright to work on Azure Web App Service (Linux )

I am using Puppeteer to convert the web page into pdf when I run the code in my local it works fine completely but when I push the code to Azure Linux Web App service I am getting an error. I am using Puppeteer to convert the web page into pdf when I run the code in my local it works fine completely but when I push the code to Azure Linux Web App service I am getting an error.

Code used:使用的代码:

const puppeteer = require("puppeteer");
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
      `https://${env.domain}/authorize? 
       client_id=${env.clientId}&response_type=token&redirect_uri=${env.redirectUri}`,
      { waitUntil: "networkidle2" }
    );
await page.waitForSelector('input[name="email"]', {
      visible: true,
      timeout: 5000
    });
await page.type('input[name="email"]', env.email, {delay: 50});
await page.type('input[name="password"]', env.password, {delay: 50});
await page.click('button[type="submit"]');
await page.waitForNavigation({ waitUntil: "networkidle2" });
const clientUrl = await page.evaluate(() => window.location.href);
await page.pdf({path: 'sendgrid/html-page.pdf', format: 'A4'});
await browser.close();  

I have tried changing my code everything works fine in local but whenever I deploy it to webapp I getting below errors我尝试更改我的代码在本地一切正常,但是每当我将它部署到 webapp 时,我都会遇到错误

error 1:错误1:

Could not find browser revision 818858. Run "PUPPETEER_PRODUCT=firefox npm install" or "PUPPETEER_PRODUCT=firefox yarn
install" to download a supported Firefox browser binary.

error 2:错误2:

/node_modules/puppeteer/.local-chromium/linux-782078/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory

Is there any solution to fix this issue有什么解决方案可以解决这个问题

In case someone have the same issue I tested a simple working solution on Azure with Node12.如果有人遇到同样的问题,我用 Node12 在 Azure 上测试了一个简单的工作解决方案。 You just need to launch the ssh terminal in your Azure App Service>Developement tools>SSH and apt-get install the necessary packages.您只需在 Azure App Service>Development tools>SSH 和 apt-get 中启动 ssh 终端并安装必要的软件包。

Example for "libgobject-2.0.so.0" the second Google result point to this page https://packages.debian.org/cgi-bin/search_contents.pl?word=libgobject-2.0.so.0&searchmode=searchfiles&case=insensitive&version=unstable&arch=i386 where you see that the package to install is "libglib2.0-0" so run "apt-get install libglib2.0-0" and voilà. “libgobject-2.0.so.0”的示例,第二个 Google 结果指向此页面https://packages.debian.org/cgi-bin/search_contents.pl?word=libgobject-2.0.so.0&versionmode=searchfiles =unstable&arch=i386你看到要安装的 package 是“libglib2.0-0”,所以运行“apt-get install libglib2.0-0”,瞧。 You'll probably have other errors so repeat the process.您可能还会遇到其他错误,因此请重复该过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 wkhtmltopdf 或 puppeteer 在 Azure Linux Web 应用程序上的节点中 - wkhtmltopdf or puppeteer in Node on Azure Linux Web App 木偶无头Chrome是否可以在Azure App Service的Windows容器中工作? - Does puppeteer headless chrome work in a Windows container in Azure App Service? 使用Github的Azure'Linux Web App'应用服务连续部署被破坏 - Azure 'Web App on Linux' app service continuous deployment with Github is broken Linux 上的 Azure Web 应用程序 - 使 Conda 安装持久化 - Azure Web app on Linux - Make Conda Installation persistent 使用 Puppeteer/Playwright 滚动不适用于 SAPUI5 应用程序 - Scrolling with Puppeteer/Playwright not working for SAPUI5 app 如何在Azure Web Service上升级yarn和使yarn工作区正常工作 - How can I upgrade yarn on Azure Web Service and make yarn workspaces work 部署的 Nodejs 服务在 Azure Web 应用程序上不起作用 - Deployed Nodejs service does not work on Azure Web App Azure Node.js Web App-如何在更新服务时使其可用? - Azure Node.js Web App - how to make service available while it's being updated? 如何使用 Playwright 或 Puppeteer 登录 google 帐户? - How to log in to google account using Playwright or Puppeteer? 在 Azure 应用服务 (Linux) 上运行的 Node/Next/React 应用是否需要 web.config 文件? - Is the web.config file required for a Node/Next/React App running on Azure App Service (Linux)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM