首页 > 解决方案 > 在 Docker 映像中包装 Playwright 时出错

问题描述

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

Dockerfile

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(我正在运行)上无效:(

标签: dockerfirefoxplaywright

解决方案


正如您已经说过的,这是一个错误(现在在功能请求中),因为 MS Devs 提供的 docker 文件对于 M1 Macs 失败。

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


推荐阅读