Azure / Azure/static-web-apps

Unable to deploy an Azure Function that uses Puppeteer

Open
#1,115 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
346
Forks
67
PR merge metrics
No merged PRs in 30d

Description

The problem I'm facing is the following:
1. I have a simple API function that uses Puppeteer to generate a PDF
2. The package.json of the API has one dependency:
"puppeteer": "^19.7.5"
3. I deploy the API using Azure DevOps and run npm install
4. I run the function calling
const browser = await puppeteer.launch({ headless: true });
and get the runtime error:
Could not find Chromium (rev. 1095492). This can occur if either 1. you did not perform an installation before running the script (e.g. `npm install`) or 2. your cache path is incorrectly configured (which is: /home/.cache/puppeteer).
5. If I include a Puppeteer config file, api\.puppeteerrc.js to specify:
cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
this will install the Chromium driver in the .cache folder of the function. This makes the deployment fail, because the whole package is over 400MB, well over the 100MB limit
6. If I don't include a Puppeteer config file, the Chromium driver is already installed under /root/.cache/puppeteer/chrome/linux-1095492. I know this because I've tried to run **node node_modules/puppeteer/install.js** post install. It would be great to use this driver but the runtime can't access it:
Failed to launch the browser process! spawn /root/.cache/puppeteer/chrome/linux-1095492/chrome EACCES TROUBLESHOOTING

So, is it safe to say that Azure Static Web Apps don't support Puppeteer? Or is this a bug? This article seemed to suggest it was possible to use Puppeteer: https://anthonychu.ca/post/azure-functions-headless-chromium-puppeteer-playwright/
Is there any other way of installing the Chromium driver without exceeding the 100MB limit of the function?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.