[英]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.