Docker M1 Mac上的Puppeteer无法打开新页面('Target.createTarget')

dbf7pr2w  于 2022-12-11  发布在  Docker
关注(0)|答案(2)|浏览(243)

我无法在M1 Mac上使用Docker中的Puppeteer启动新页面。

版本

Docker: version 20.10.11, build dea9396
Node: 16.13.1
MacOS: 12.0.1 (21A559)
Puppeteer: 13.5.1
M1 Chip

错误消息

ProtocolError: Protocol error (Target.createTarget): Target closed.
    at /home/node/app/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:75:24
    at new Promise (<anonymous>)
    at Connection.send (/home/node/app/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:71:16)
    at Browser._createPageInContext (/home/node/app/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:261:53)
    at BrowserContext.newPage (/home/node/app/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:520:30)
    at Browser.newPage (/home/node/app/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:254:37)
    at /home/node/app/src/test.js:17:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

脚本

const puppeteer = require('puppeteer');
(async function () {
  const browser = await puppeteer.launch({
    headless: true,
    args: [
      '--disable-gpu', // if i remove this, strangely the process exits unexpectedly
      '--disable-dev-shm-usage',
      '--no-sandbox',
      '--disable-setuid-sandbox',
    ],
  });
  await browser.newPage();
})();

停靠文件(相关信息)

第一个

olmpazwi

olmpazwi1#

节点:16.13.1-slim在linux/arm 64/v8中可用,只需修改行

FROM --platform=linux/amd64 node:16.13.1-slim

FROM --platform=linux/arm64/v8 node:16.13.1-slim

来测试一下。

dvtswwa3

dvtswwa32#

我知道我迟到了,但这个问题让我很生气。经过许多小时的试验和错误,我设法建立了一个适当的Dockerfile使用 Puppeteer 在我的苹果硅M2:https://github.com/juananpe/puppeteer-in-docker-in-m1希望能有所帮助。

相关问题