Lighthouse CI 为啥在 GitHub Actions 里跑不通?
我在本地用 Lighthouse CI 跑得好好的,但一推到 GitHub Actions 就报错说“Unable to connect to Chrome”。我明明用了官方推荐的 lighthouseci action,也加了 --collect.settings.chromeFlags='--no-sandbox',还是不行。
页面本身很简单,就一个带渐变背景的按钮,CSS 长这样:
.btn {
background: linear-gradient(45deg, #ff6b6b, #ffa5a5);
border: none;
padding: 12px 24px;
color: white;
border-radius: 8px;
cursor: pointer;
}
是不是 CI 环境里缺了啥依赖?还是 Chrome 启动参数没配对?真的搞不懂了……
在 lighthouseci 的配置里改成这样:
然后在 lighthouserc.js 里配置 Chrome 启动参数:
关键就是
--disable-dev-shm-usage这个参数,GitHub Actions 的容器默认 /dev/shm 只有 64MB,Chrome 跑不起来。加上这个参数让 Chrome 用磁盘临时文件代替共享内存,就搞定了。