I’m having trouble with my Node.js app on Azure. It uses Puppeteer and works fine locally, but not after deployment. The error says it can’t find Chrome. I’ve tried installing Puppeteer with Chromium and set up the API, but no luck.
Here’s a simplified version of what I’m trying:
const puppeteer = require('puppeteer');
async function takeScreenshot(url) {
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.goto(url);
const screenshot = await page.screenshot();
await browser.close();
return screenshot;
}
I’m using GitHub Actions for deployment. My YAML file includes steps to install Puppeteer and Chrome. Any ideas on how to get this working on Azure? Thanks!
I’ve been down this road before, and it can be frustrating. One approach that worked wonders for me was leveraging Azure Functions with Puppeteer. It’s a serverless option that eliminates many of the headaches associated with traditional deployments.
Here’s the kicker: Azure Functions has a Chromium package pre-installed, so you don’t need to worry about browser compatibility issues. You’ll need to tweak your code slightly to use the local Chromium instance:
const chromium = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-core');
const browser = await chromium.puppeteer.launch({
executablePath: await chromium.executablePath,
args: chromium.args,
defaultViewport: chromium.defaultViewport,
headless: chromium.headless
});
This approach has been rock-solid for me in production. It’s worth giving a shot if you’re still hitting walls with your current setup.
I encountered a similar issue when deploying a Puppeteer-based application to Azure. The solution that worked for me was to use a custom Docker container. This approach allows you to pre-install Chrome and all necessary dependencies.
First, create a Dockerfile that installs Chrome and your Node.js application. Then, configure your Azure App Service to use this custom Docker image. This method ensures that Chrome is available in the deployment environment.
Additionally, consider using the --no-sandbox flag when launching Puppeteer, as Azure’s default configuration may not support sandboxing. However, be aware of the security implications of disabling the sandbox in a production environment.
hey there! i’ve had similar issues. Have u tried using the puppeteer-core package instead? It lets u specify a custom chrome path. Also, make sure ur azure app service plan supports running chrome (like premium v3). good luck!