You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Github Actions的ubuntu-latest(23)环境下使用Puppeteer出现“No usable sandbox”错误

Fixing ChromeHeadless Sandbox Error in Github Actions with Karma & Puppeteer

Let's break down why you're hitting this sandbox error even after setting --no-sandbox—and fix it step by step.

The Core Issue

Your Karma config defines a custom ChromeHeadlessCustom launcher with the --no-sandbox flag, but your test command is using the default ChromeHeadless launcher (which doesn't include that flag). That's why the sandbox restriction is still kicking in.

Step 1: Use Your Custom Launcher in the Test Command

Update your test:ci script to target the custom launcher you created:

"test:ci": "ng test ngx-float-ui --browsers=ChromeHeadlessCustom --watch=false"

Step 2: (Optional) Clean Up Your Browsers List

You have ChromeHeadlessNoSandbox listed in your browsers array, but you never defined that launcher. If you prefer that name, adjust your config like this:

customLaunchers: {
  ChromeHeadlessNoSandbox: { // Rename to match your browsers list
    base: "ChromeHeadless",
    flags: [
      "--no-sandbox",
      "--disable-gpu",
      "--remote-debugging-port=9333"
    ]
  }
}

Then update your test command to use this name instead:

"test:ci": "ng test ngx-float-ui --browsers=ChromeHeadlessNoSandbox --watch=false"

Step 3: Add Missing Chrome Dependencies to Github Actions

Github Actions' Ubuntu runners often lack some system libraries required by ChromeHeadless. Add this step to your workflow file before running tests:

- name: Install Chrome system dependencies
  run: |
    sudo apt-get update
    sudo apt-get install -y libnss3 libx11-xcb1 libxcb-dri3-0 libdrm2 libgbm1 libasound2

This ensures all required libraries are present for Chrome to launch successfully.

Step 4: Verify Puppeteer & Chrome Compatibility

Occasionally, version mismatches between Puppeteer and the Chrome binary it downloads can cause issues. If the above steps don't work, try:

  • Locking your Puppeteer version to a stable release (check the Puppeteer docs for compatible Chrome versions)
  • Using puppeteer-core instead of puppeteer to use the system-installed Chrome from your Github Actions runner

内容的提问来源于stack exchange,提问作者OtaconKiko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 12:29:06