Playwright Error: Firefox revision is not downloaded. Run "npm install" or "yarn install"

Playwright Error: Firefox revision is not downloaded. Run "npm install" or "yarn install"

const playwright = require("playwright");

(async () => {
  const browsers = ["chromium", "firefox", "webkit"];

  for (const browserType of browsers) {
    const browser = await playwright[browserType].launch({args: ['--no-sandbox']});
    const context = await browser.newContext();
    const page = await context.newPage("http://whatsmyuseragent.org/");

    await page.screenshot({ path: `example-${browserType}.png` });
  }
})();

在 运行 这个脚本之后,我得到了 UnhandledPromiseRejectionWarning: E​​rror: Firefox revision is not downloaded。 运行 "npm install" 或 "yarn install" 在控制台中。如何解决?

使用 npm 代替 yarn 后问题得到解决。

您可以使用 Playwright CLI 安装浏览器:

npx playwright install

找不到修订的原因主要是由于node_modules时NPM的缓存配置不正确。缓存在某些 CI 环境中。由于 NPM 认为 Playwright 已安装,但实际浏览器存储在另一个位置。请参阅 here 以供参考。