TL;DR - Does anyone know of a way to run npx playwright install chromium after installing Node.js dependencies, and in the Google Cloud Function's production environment?
Is it possible to run Playwright within a deployed Google Cloud Function? I have a deployed function that works fine locally, but when deployed, consistently fails with this error:
browserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium-1015/chrome-linux/chrome
Fun fact, before using Playwright, I successfully used Puppeteer to successfully deploy the Google Cloud Function. Puppeteer also uses Chromium and had no problems locating and/or installing the Chromium executable (and I am also using only Chromium with Playwright).
I'm pretty sure that running npx playwright install chromium after npm install would fix the problem, but I'm not sure how to run that command in the Google Cloud Function's environment. I tried doing the following:
// package.json
...
"scripts": {
...
"postinstall": "npx playwright install chromium",
"postci": "npx playwright install chromium"
}
...
But that didn't work since I'm getting the same error (and I'm not sure if either post script was executed). Running npx playwright install chromium works locally though.
Has anyone successfully ran Playwright in a deployed Google Cloud Function?
Update
Doing this approach works when running remotely, but not locally (via an emulated Google Cloud Function). Another problem with that approach is that we're fixed on specific versions of playwright-core and chrome-aws-lambda.
Does anyone have a better solution?
Executable doesn't existerror. What I found during debugging is that there was a version mismatch. browserType.launch was looking for ...\ms-playwright\webkit-1683\Playwright.exe executable while the installed version was located in ...\ms-playwright\webkit-1630.executablePathto point to the installed version? playwright.dev/docs/api/class-browsertype#browser-type-launchdownloadevent made that much easier than the manual polling method I was using with puppeteer. My script went from 120 lines to 60 for the same functionality.