Skip to content

fix: open HTML report in Windows browser when running in WSL#1148

Open
xuli500177 wants to merge 1 commit into
sansan0:masterfrom
xuli500177:fix/wsl-browser-open
Open

fix: open HTML report in Windows browser when running in WSL#1148
xuli500177 wants to merge 1 commit into
sansan0:masterfrom
xuli500177:fix/wsl-browser-open

Conversation

@xuli500177
Copy link
Copy Markdown

问题

WSL 环境下运行 TrendRadar 时,自动打开 HTML 报告会弹出错误弹窗。原因是 Python 的 webbrowser.open() 启动了 WSL 内的 Linux 浏览器,但 WSL 没有图形显示环境,导致打开失败。

方案

检测 WSL 环境,改用 powershell.exeStart-Process 在 Windows 默认浏览器中打开报告。

改动

  • _is_wsl():通过读取 /proc/version 检测 WSL 环境
  • _open_in_windows_browser():用 wslpath 转换路径 + powershell.exe 打开
  • 非 WSL 环境完全不受影响

测试

  • WSL2 + Windows 11:报告正确在 Windows Chrome 中打开
  • 无副作用,不影响 Linux/macOS/容器环境

WSL users currently see a broken popup when TrendRadar tries to open
the HTML report, because Python's webbrowser.open() launches a Linux
browser that has no display. This fix detects the WSL environment and
uses PowerShell's Start-Process to open the report in the user's
Windows default browser instead.

Changes:
- Add _is_wsl() to detect WSL via /proc/version
- Add _open_in_windows_browser() using wslpath + powershell.exe
- Non-WSL environments are unaffected
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