在 Docker 图像中获取 Playwright 包装错误

Getting an error wrapping Playwright in a Docker image

我将我的 Playwright 项目包装在 Docker 图像中后出现一些错误。我在 Playwright 中使用 Firefox。

Docker文件

FROM mcr.microsoft.com/playwright:next

WORKDIR /app

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

RUN npx playwright install

CMD ["node","index.js"]

Package.json 依赖关系

"@extra/humanize": "^4.2.2-next.616",
"playwright": "^1.15.0",
"playwright-extra": "^4.2.1-next.616"

index.js

const { firefox } = require('playwright');

(async () => {
  const browser = await firefox.launch();
  const page = await browser.newPage();
  await page.goto('http://whatsmyuseragent.org/');
  await page.screenshot({ path: `example.png` });
  await browser.close();
})();

它构建良好,但是当我 运行 它时,我收到此错误:

browserType.launch: Protocol error (Browser.enable): Browser closed.

==================== Browser output: ====================

<launching> /ms-playwright/firefox-1225/firefox/firefox -no-remote -headless -profile /tmp/playwright_firefoxdev_profile-q4UuZi -juggler-pipe -silent

<launched> pid=965

[err] *** You are running in headless mode.

[err] [Parent 965, Main Thread] WARNING: failed to seal memfd: Invalid argument: file /mnt/actions-runner/_work/playwright-internal/playwright-internal/browser_patches/firefox/checkout/ipc/chromium/src/base/shared_memory_posix.cc:461

[err] [Parent 965, Main Thread] WARNING: freezeable shared memory was never frozen: file /mnt/actions-runner/_work/playwright-internal/playwright-internal/browser_patches/firefox/checkout/ipc/chromium/src/base/shared_memory_posix.cc:543

更新:

如果有人遇到同样的问题,我很遗憾地发现 Docker 图像在 MacBook M1(我是 运行)上无效:(

如您所述,这是一个错误(现在在功能请求中),因为 MS Devs 提供的 docker 文件无法用于 M1 Mac。

这是功能请求的 link - https://github.com/microsoft/playwright/issues/7723