Mac 版 Puppeteer 和 Docker (Apple M1)

Jes*_*sse 7 docker puppeteer apple-m1

通过 puppeteer 导航打开 Chromium 时崩溃,并在我的 M1 上显示以下堆栈跟踪。我正在向社区寻求一些帮助,因为非基于 m1 的机器似乎对我们的 puppeteer 容器没有问题。

[0613/204124.018517:ERROR:stack_trace_posix.cc(707)] Failed to parse the contents of /proc/self/maps
[0613/204124.746267:ERROR:stack_trace_posix.cc(707)] Failed to parse the contents of /proc/self/maps
[0613/204124.751355:ERROR:stack_trace_posix.cc(707)] Failed to parse the contents of /proc/self/maps
[0613/204124.981155:FATAL:nacl_helper_linux.cc(440)] Check failed: nacl_sandbox->IsSingleThreaded().

qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[130:130:0613/204125.140482:FATAL:zygote_main_linux.cc(162)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded().
#0 0x0040072b9339 <unknown>
#1 0x00400722ff23 <unknown>
#2 0x00400722d070 <unknown>
#3 0x00400722dc6e <unknown>
#4 0x004006dae926 <unknown>
#5 0x004006da973e <unknown>
#6 0x004006daa369 <unknown>
#7 0x004006dab0cb <unknown>
#8 0x004006da838e <unknown>
#9 0x004006da8d4e <unknown>
#10 0x0040036e1227 <unknown>
#11 0x00400faba0b3 <unknown>
#12 0x0040036e102a <unknown>
Crash keys:
  "switch-7" = "--enable-crashpad"
  "switch-6" = "--change-stack-guard-on-fork=enable"
  "switch-5" = "--user-data-dir=/tmp/puppeteer_dev_chrome_profile-5BphEe"
  "switch-4" = "--enable-crash-reporter=,"
  "switch-3" = "--crashpad-handler-pid=117"
  "switch-2" = "--enable-crashpad"
  "switch-1" = "--no-sandbox"
  "num-switches" = "8"

qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[112:138:0613/204125.830241:ERROR:file_path_watcher_inotify.cc(329)] inotify_init() failed: Function not implemented (38)
[0613/204125.946536:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
Assertion failed: p_rcu_reader->depth != 0 (/qemu/include/qemu/rcu.h: rcu_read_unlock: 101)


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

Error scraping url: <my - url>: 
Error: Unable to launch chrome
Run Code Online (Sandbox Code Playgroud)

我正在使用以下选项启动 puppeteer:

  const args = [
    '--no-first-run',
    '--no-sandbox',
    '--disable-setuid-sandbox',
    '--single-process',
    '--disable-dev-shm-usage',
    '--ignore-certificate-errors',
    '--ignore-urlfetcher-cert-requests',
    '--disable-blink-features=AutomationControlled'
  ];
Run Code Online (Sandbox Code Playgroud)

我通过以下方式将 chromium 安装到基于 ubuntu 的容器中:

# Install Chrome for Ubuntu
RUN apt-get update \
 && apt-get install -y chromium-browser

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium
Run Code Online (Sandbox Code Playgroud)

小智 2

花了一整天的时间试图修复它。最后用colima运行 docker解决了这个问题。问题是,有些东西根本不适用于手臂,因此没有必要与之抗争。Colima 允许您通过 Rosetta 运行所有内容,从而全程模拟 x86。

  1. 首先安装 colima brew install colima
  2. 如果 docker 桌面正在运行,请关闭它。
  3. 启动 colima colima start --arch aarch64 --vm-type=vz(查看自述文件以获取更多信息)
  4. 现在您已经通过 Rossetta 完全运行了 docker。运行镜像时,使用“--platform linux/amd64”。