TL;DR - 有谁知道在安装 Node.js 依赖项后以及在 Google Cloud Function 的生产环境中运行
npx playwright install chromium
的方法吗?
是否可以在已部署的 Google Cloud Function 中运行 Playwright?我有一个已部署的函数,在本地运行良好,但在部署时,始终失败并出现以下错误:
browserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium-1015/chrome-linux/chrome
有趣的是,在使用 Playwright 之前,我成功地使用 Puppeteer 成功部署了 Google Cloud Function。 Puppeteer 也使用 Chromium,并且在定位和/或安装 Chromium 可执行文件方面没有任何问题(而且我也仅将 Chromium 与 Playwright 一起使用)。
我很确定在
npx playwright install chromium
之后运行 npm install
可以解决问题,但我不确定如何在 Google Cloud Function 的环境中运行该命令。我尝试执行以下操作:
// package.json
...
"scripts": {
...
"postinstall": "npx playwright install chromium",
"postci": "npx playwright install chromium"
}
...
但这不起作用,因为我遇到了同样的错误(并且我不确定是否执行了后脚本)。不过运行
npx playwright install chromium
可以在本地运行。
有人在部署的 Google Cloud Function 中成功运行 Playwright 吗?
执行此方法适用于远程运行,但不适用于本地运行(通过模拟的 Google Cloud 功能)。这种方法的另一个问题是我们修复了特定版本的
playwright-core
和 chrome-aws-lambda
。
有没有人有更好的解决方案?