Hey everyone! I’m trying to get Playwright working in Azure Functions using the consumption plan (not flex). I know there’s a 500MB limit, so I’ve tried storing the package in a blob container. I’m using a Windows image, but the browser won’t work. It’s fine locally, and I’ve set the environment variable and included the browsers with the binaries.
I keep getting ‘spawn’ or ‘failed to launch’ errors. The error message says it can’t find the exe, but I can see it’s there in Kudu. I’ve set PLAYWRIGHT_BROWSERS_PATH correctly.
If I download the zip file from the blob, extract it, and point my local build to that folder, it works fine. So the browser files seem okay.
I’ve tried both headless and non-headless modes, but no luck.
Has anyone managed to get this working? I’m not looking for a full solution, just wondering if it’s possible and what kind of setup you used. I really want to stick with the consumption plan for cost reasons.
Any tips or experiences would be super helpful! Thanks!
I’ve tackled this issue before, and it’s certainly challenging. One approach that worked for me was using a custom runtime bundle. Instead of relying on the full Playwright package, I created a stripped-down version with only the essential components for my specific use case.
To achieve this, I used webpack to bundle Playwright and its dependencies, excluding unnecessary modules. This significantly reduced the package size. I then uploaded this bundle to Azure Functions alongside my code.
For browser binaries, I opted for a lightweight browser like Firefox Nightly, which has a smaller footprint. I stored these in Azure File Storage and mounted them to the function app.
The key was meticulous optimization at every step. It required some trial and error, but I eventually got it working within the consumption plan limits.
Remember to set your PLAYWRIGHT_BROWSERS_PATH correctly and ensure your function has the necessary permissions to access the mounted storage.
This setup isn’t ideal for complex scenarios, but it’s a viable solution for simpler Playwright tasks while staying cost-effective.
I’ve actually faced a similar challenge with Playwright in Azure Functions on the consumption plan. It’s definitely tricky, but not impossible. Here’s what worked for me:
Instead of storing the browser package in a blob, I ended up using a custom Docker image. This allowed me to pre-install Playwright and its dependencies directly in the image. I then deployed this custom image to Azure Functions.
The key was to keep the image size under 500MB, which required some careful optimization. I stripped out unnecessary components and used a minimal base image.
For the PLAYWRIGHT_BROWSERS_PATH, I set it to a path within the container where I pre-installed the browser binaries.
One gotcha: make sure your function app’s platform is set to ‘Linux’ in the Azure portal, even though you’re using a Windows image.
It took some trial and error, but this approach eventually worked for me. The performance isn’t blazing fast, but it’s functional and stays within the consumption plan limits.
Hope this gives you some ideas to try! Let me know if you want more details on any part of the setup.
hey, i tried azure functions consumption plan with playwright using a custom linux container.
i used an alpine image, minimal deps and set PLAYWRIGHT_BROWSERS_PATH right. performance is meh but it works. lemme know if u need more deets!