docker 中的 puppeteer v19.10.1 在 macOS 上失败 [0424/114437.819230:FATAL:zygote

编程入门 行业动态 更新时间:2024-10-05 09:23:08

<a href=https://www.elefans.com/category/jswz/34/1771431.html style=docker 中的 puppeteer v19.10.1 在 macOS 上失败 [0424/114437.819230:FATAL:zygote"/>

docker 中的 puppeteer v19.10.1 在 macOS 上失败 [0424/114437.819230:FATAL:zygote

错误预期

我正在 macOS 上的 docker 中试用 puppeteer 脚本

我跑

docker run -i --init --cap-add=SYS_ADMIN --rm ghcr.io/puppeteer/puppeteer:latest node -e "$(cat coremakepdf.js)"

或(没有

--cap-add=SYS_ADMIN

docker run -i --init --rm ghcr.io/puppeteer/puppeteer:latest node -e "$(cat coremakepdf.js)"

coremakepdf.js脚本内容:

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('/', {
        waitUntil: 'networkidle2',
    });
    await page.pdf({ path: 'developer.chrome.pdf', format: 'a4' });

    await browser.close();
})();

非 PDF 相关脚本失败并出现类似错误,因此实际脚本无关紧要,但在 docker 中运行

const puppeteer = require('puppeteer');
 
(async () => {

    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    // await page.goto('chrome://settings/help');
    // (node:24252) UnhandledPromiseRejectionWarning: Error: net::ERR_INVALID_URL at chrome://settings/help
    //await page.goto('/'); //OK
    //await page.goto('/'); //OK
    await page.goto('/', {
        waitUntil: 'networkidle2',
    }); //OK

    await page.screenshot({ path: 'about3.png' });

    await browser.close();
})();
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

  Puppeteer old Headless deprecation warning:
    In the near feature `headless: true` will default to the new Headless mode
    for Chrome instead of the old Headless implementation. For more
    information, please see /.
    Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
    If you encounter any bugs, please report them to .

/home/pptruser/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262
                reject(new Error([
                       ^

Error: Failed to launch the browser process!
[0424/114437.785256:ERROR:stack_trace_posix(811)] Failed to parse the contents of /proc/self/maps
[0424/114437.819230:FATAL:zygote_host_impl_linux(127)] No usable sandbox! Update your kernel or see /+/main/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
#0 0x004007d22f72 base::debug::CollectStackTrace()
#1 0x004007d0f4b3 base::debug::StackTrace::StackTrace()
#2 0x004007c61fbf logging::LogMessage::~LogMessage()
#3 0x00400647ec16 content::ZygoteHostImpl::Init()
#4 0x0040071b8b23 content::ContentMainRunnerImpl::Initialize()
#5 0x0040071b6427 content::RunContentProcess()
#6 0x0040071b6606 content::ContentMain()
#7 0x0040077a01fa headless::HeadlessShellMain()
#8 0x0040038d7255 ChromeMain
#9 0x004010fa5d0a __libc_start_main
#10 0x0040038d702a _start

qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped


TROUBLESHOOTING: /troubleshooting

    at Interface.onClose (/home/pptruser/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262:24)
    at Interface.emit (node:events:525:35)
    at Interface.close (node:internal/readline/interface:533:10)
    at Socket.onend (node:internal/readline/interface:259:10)
    at Socket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.16.0

错误行为

  • [ ] 片状
  • [ ] PDF

最小的、可重现的例子

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('/', {
        waitUntil: 'networkidle2',
    });
    await page.pdf({ path: 'developer.chrome.pdf', format: 'a4' });

    await browser.close();
})();

错误字符串

错误:启动浏览器进程失败! [0424/114437.785256:ERROR:stack_trace_posix(811)] 无法解析 /proc/self/maps 的内容 [0424/114437.819230:FATAL:zygote_host_impl_linux(127)] 没有可用的沙箱!更新您的内核或查看 /+/main/docs/linux/suid_sandbox_development.md 了解有关使用 SUID 沙箱进行开发的更多信息。如果您想过着危险的生活并需要立即解决方法,可以尝试使用 --no-sandbox。

人偶配置

const {join} = require('path');

/**
 * @type {import("puppeteer").Configuration}
 */
module.exports = {
    // Changes the cache location for Puppeteer.
    cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};

人偶版

19.10.1

节点版本

v18.16.0

包管理器

纱线

包管理器版本

1.22.19

操作系统

macOS

回答如下:

这是 docker 问题。通过

解决

在 Docker 设置中,在开发部分的功能中,启用 Rosetta。 并重启 Docker

https://levelup.gitconnected/docker-on-apple-silicon-mac-how-to-run-x86-containers-with-rosetta-2-4a679913a0d5

更多推荐

docker 中的 puppeteer v19.10.1 在 macOS 上失败 [0424/114437.819230:FATAL:zygote

本文发布于:2024-05-30 07:56:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:docker   puppeteer   macOS   FATAL   zygote

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!