I have a Node.js application that uses Puppeteer for web scraping and screenshot generation. Everything works great when I run it on my development machine, but after pushing it to Azure Web App, I’m getting browser not found errors.
The Problem:
When the app tries to launch Puppeteer on Azure, I get this error:
Unable to locate Chrome browser (version 131.0.6778.85). This error occurs when:
1. Browser installation was not completed before script execution (try running `npx puppeteer browsers install chrome`) or
2. Cache directory path is misconfigured (current path: /root/.cache/puppeteer).
Refer to configuration guide at https://pptr.dev/guides/configuration for troubleshooting.
My Current Setup:
- Local development: No issues at all
- Azure production: Browser detection fails
Code Implementation:
app.get("/api/capture", async (req, res) => {
try {
const websiteUrl = req.query.site || "https://google.com";
console.log("Initializing browser instance...");
const browserInstance = await puppeteer.launch({
headless: true,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--single-process",
"--no-zygote"
],
executablePath: process.env.CHROME_EXECUTABLE_PATH
});
console.log("Browser initialized successfully");
const newPage = await browserInstance.newPage();
console.log("Loading website:", websiteUrl);
await newPage.goto(websiteUrl, { waitUntil: "networkidle2" });
console.log("Website loaded, capturing screenshot");
const imageBuffer = await newPage.screenshot({ encoding: "base64" });
console.log("Screenshot captured, cleaning up");
await browserInstance.close();
res.send(`<img src="data:image/png;base64,${imageBuffer}" />`);
} catch (err) {
console.error("Screenshot API error:", err);
res.status(500).json({
error: "Screenshot generation failed",
details: err.message,
trace: err.stack,
chromePath: process.env.CHROME_EXECUTABLE_PATH || "Path not configured"
});
}
});
GitHub Actions Workflow:
name: deploy-web-app
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "22.x"
- name: Install packages
run: npm ci
- name: Configure Puppeteer
run: |
npm remove puppeteer-core
npm add puppeteer
npx puppeteer browsers install chrome
echo "CHROME_EXECUTABLE_PATH=$(node -e 'console.log(require("puppeteer").executablePath())')\