docker - 在 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(我正在运行)上无效:(
解决方案
正如您已经说过的,这是一个错误(现在在功能请求中),因为 MS Devs 提供的 docker 文件对于 M1 Macs 失败。
这是功能请求的链接 - https://github.com/microsoft/playwright/issues/7723
推荐阅读
- python - pytest - 在执行期间更改 Jupyter 笔记本单元格中的变量值
- java - Java多线程在main中的两个类
- ruby-on-rails - 只有一个产品变体添加到购物车,它总是第一个添加到我的数据库
- flutter - 颤振:没有名为“溢出”的命名参数,溢出:溢出。可见,
- node.js - 一种每隔 X 秒将 localhost 中的 InfluxDB 数据在线复制到 InfluxDB 的方法?
- python - 从 joblib 文件加载的 TfidfVectorizer 模型仅在同一会话中训练时才有效
- javascript - React Native Elements Checkbox 一直选择所有项目,而不是选择的一项
- excel - 选择多个工作簿,将每个工作簿中的第一个选项卡合并到同一工作簿中的新选项卡,使用文件名重命名选项卡
- r - 在 R 中编译“gridtext”包时出现问题
- javascript - 如何将 jQuery ':not(:has(*)):not(a *):not(a)' 转换为 TreeWalker 的纯 js?