Skip to content

Fix: pass --no-sandbox flags to Lighthouse Chrome launcher#109

Open
tsira wants to merge 3 commits into
Shopify:mainfrom
tsira:fix/chrome-no-sandbox-for-lighthouse-audit
Open

Fix: pass --no-sandbox flags to Lighthouse Chrome launcher#109
tsira wants to merge 3 commits into
Shopify:mainfrom
tsira:fix/chrome-no-sandbox-for-lighthouse-audit

Conversation

@tsira
Copy link
Copy Markdown

@tsira tsira commented Apr 27, 2026

Problem

The generated `lighthouserc.yml` already passes `--no-sandbox` and related flags via `puppeteerLaunchOptions`, but those only apply to the Puppeteer browser used to set preview cookies. The actual Lighthouse audit runs a separate Chrome process via `LH:ChromeLauncher`, which does not inherit those flags.

When the action runs in a Docker container as root (the default on GitHub-hosted runners), Chrome 147+ exits immediately with:

```
LH:ChromeLauncher:error [167:167:...] Running as root without --no-sandbox is not supported.
See https://crbug.com/638180.
```

This causes `lhci collect` to fail with `Run #1...failed!` and `Error: Lighthouse failed with exit code 1`. The failure is environment-dependent — runners with a more permissive seccomp profile will pass, making the failure appear flaky.

Root cause

`chromeFlags` in `lighthouserc.yml` (whether under `collect` or `collect.settings`) is not reliably picked up by chrome-launcher. The reliable path is the `CHROME_PATH` environment variable, which chrome-launcher uses to locate and launch Chrome.

Fix

Create a wrapper script that unconditionally prepends `--no-sandbox` to every Chrome launch, then point both `PUPPETEER_EXECUTABLE_PATH` and `CHROME_PATH` at it:

```bash
cat > /usr/local/bin/chrome-no-sandbox <<'WRAPPER'
#!/bin/sh
exec /usr/bin/google-chrome-stable --no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage --disable-gpu "$@"
WRAPPER
chmod +x /usr/local/bin/chrome-no-sandbox

export PUPPETEER_EXECUTABLE_PATH='/usr/local/bin/chrome-no-sandbox'
export CHROME_PATH='/usr/local/bin/chrome-no-sandbox'
```

Also set `collect.chromePath` in `lighthouserc.yml` as a belt-and-suspenders fallback for any LHCI code path that reads config instead of env.

This means every Chrome launch in the action — Puppeteer cookie setup and Lighthouse audits — goes through the same wrapper and always has `--no-sandbox`.

Testing

  • Confirmed the original error reproduced 7 consecutive times on `yrf8g3-i4.myshopify.com` (Shopify Atelier theme) with `shopify/lighthouse-ci-action@v1.4.0` and Chrome `147.0.7727.116-1` on `ubuntu-24.04` runner image `20260413.86.1`.
  • Confirmed this fix passes end-to-end (Theme Check → Lint → Secret Scan → Deploy Staging → Lighthouse CI ✅ → Deploy Production ✅) on the same store using `tsira/lighthouse-ci-action@fix/chrome-no-sandbox-for-lighthouse-audit`: https://github.com/tsira/kwd/actions/runs/24977466455

🤖 Generated with Claude Code

The generated lighthouserc.yml already passes --no-sandbox and related
flags via puppeteerLaunchOptions, but those only apply to the Puppeteer
browser used for cookie setup. The Lighthouse audit runs a separate
Chrome process via LH:ChromeLauncher, which does not inherit those flags.

When running in Docker as root (the default on GitHub-hosted runners),
Chrome 147+ exits immediately with:

  Running as root without --no-sandbox is not supported.

Add a settings.chromeFlags field to the collect block so both Chrome
processes receive the same flags.
tsira and others added 2 commits April 26, 2026 21:54
settings maps to Lighthouse config options; chromeFlags is a top-level
ci.collect option in LHCI that gets passed as --chrome-flags to the
Chrome launcher. Placing it under settings silently has no effect.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chromeFlags in lighthouserc.yml is not picked up by chrome-launcher.
Instead, create a wrapper at /usr/local/bin/chrome-no-sandbox that
always prepends --no-sandbox, and point both PUPPETEER_EXECUTABLE_PATH
and CHROME_PATH (used by chrome-launcher / lhci) at the wrapper.
Also set collect.chromePath so lhci's own Chrome launch uses it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant