How do you run Playwright in serverless functions?



  • I'm building a web app that generates PDF invoices for small businesses, and I use Playwright to open the invoice preview before exporting it. Everything works fine locally, but moving the process to AWS Lambda has been a pain. Chromium needs extra libraries, cold starts are slow, and packaging the whole browser into a function feels excessive for something that only runs when a customer creates an invoice. Is there a better way to handle this without keeping a dedicated browser server running all day?



  • That's a lot of machinery just to produce an invoice. Before spending more time on Chromium, see whether your PDF templates actually need a browser to render. For simple HTML invoices, server-side PDF generation might be enough. If Playwright is necessary, try a Lambda-compatible Chromium build with its dependencies in a layer or container image. Put the jobs in a queue and save completed PDFs to S3. Customers can get their files when they're ready without waiting through a cold start.



  • The browser itself is only half the trouble. You still have to deal with updates, missing libraries, and memory limits whenever something changes. Another option is to keep Playwright in your Lambda function but run Chromium remotely. Take a look at how a Playwright automation tool in the cloud works: https://gologin.com/blog/playwright-automation-tool-in-the-cloud/ . Test it with invoices containing long tables and custom fonts. Measure connection time, PDF generation speed, and session costs. Make sure remote browsers close after each job so unused sessions don't keep costing you money.


Login
 

Looks like your connection to FBX Forum was lost, please wait while we try to reconnect.