WSL搭配X-Server运行Cypress时出现空白窗口及连接超时问题
WSL2 Ubuntu运行Cypress问题的解决办法
针对cypress open无内容+DBus/GPU错误
- 检查VcXsrv启动参数:必须勾选Disable access control,或直接用带参数的快捷方式启动,目标设为:
"C:\Program Files\VcXsrv\vcxsrv.exe" :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl - 在WSL的
~/.bashrc(或~/.zshrc)中添加环境变量并生效:echo 'export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '\''{print $2}'\''):0' >> ~/.bashrc echo 'export LIBGL_ALWAYS_INDIRECT=1' >> ~/.bashrc source ~/.bashrc - 运行时添加
--no-sandbox参数跳过沙箱限制:cypress open --no-sandbox
针对cypress run无头模式超时
- 先重启WSL:在Windows终端执行
wsl --shutdown,再重新打开Ubuntu - 项目根目录创建
cypress.json(Cypress 9.x版本适用),配置禁用沙箱:{ "chromeWebPreferences": { "args": ["--no-sandbox", "--disable-dev-shm-usage"] } } - 安装Ubuntu必要依赖包:
sudo apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb - 也可通过XVFB运行无头模式:
xvfb-run -a cypress run
针对cypress run --headed空白窗口+超时
- 确保VcXsrv正在运行,且DISPLAY环境变量配置正确(参考第一个问题的步骤)
- 添加
--no-sandbox参数运行:cypress run --headed --no-sandbox - 暂时关闭Windows Defender防火墙测试,确认未拦截WSL与VcXsrv的连接
内容的提问来源于stack exchange,提问作者van_folmert
相关产品推荐
相关产品推荐

