Hey everyone, I’m stuck with a problem in my Azure Function. I’m trying to take screenshots of webpages and save them as images. Puppeteer didn’t work out, so I switched to Playwright. But now I’m getting this error:
Microsoft.Playwright.PlaywrightException: Driver not found: /home/.playwright/node/linux-x64/node
I’m using a Flex consumption plan and deploying through Azure DevOps. Here’s a snippet of my code:
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = true,
Args = new[] { "--no-sandbox", "--disable-gpu", "--disable-setuid-sandbox", "--disable-dev-shm-usage" }
});
I even tried adding a startup script to install the needed packages. Any ideas what I’m doing wrong or how to fix this? Thanks in advance!
hey mate, i had similar issues. try adding this to ur function.json:
“PLAYWRIGHT_BROWSERS_PATH”: “/home/site/wwwroot/.playwright”
also, make sure ur running on linux plan. consumption can be wonky w/ browser stuff. if that don’t work, hit me up and we’ll figure it out!
I’ve dealt with this exact problem in my Azure Function projects. The key is making sure Playwright has all its dependencies available in the Azure environment. What worked for me was including the Playwright CLI in my project and running the install command during the build process.
In your Azure DevOps pipeline, add a step to install Playwright browsers:
- script: npx playwright install chromium
displayName: 'Install Playwright browsers'
Also, make sure your function app’s settings include:
PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot/.playwright
This tells Playwright where to find the installed browsers.
Lastly, I found that using a Linux-based App Service plan, preferably Premium, gives better performance and fewer headaches with Playwright. The consumption plan can be finicky with browser automation.
If you’re still stuck after trying these, let me know and I can share more detailed steps from my setup.
I’ve encountered a similar issue when working with Playwright in Azure Functions. The problem stems from the fact that Azure Functions runtime doesn’t include the necessary Playwright drivers by default.
To resolve this, you need to ensure the Playwright browser binaries are available in your function app. Here’s what worked for me:
Add the Microsoft.Playwright.NUnit NuGet package to your project, run ‘playwright install’ in your function app’s root directory to download the required browsers, and include the playwright-dotnet.sh script in your project while setting it as a startup command in your function app settings.
Additionally, make sure your function app is running on a Linux-based App Service plan, as Playwright has better support for Linux environments in Azure.
If you’re still facing issues, double-check your deployment process to ensure all necessary files are being included in your function app package.