refactor: 改进浏览器实例管理,按需创建浏览器实例 (#12)

- 移除全局浏览器单例,改为按需创建浏览器实例
- 添加 configs/browser.go 用于管理无头模式配置
- 更新 service.go 中所有方法,每次调用时创建新的浏览器实例
- 更新测试文件,使用新的浏览器管理方式
- 确保每个浏览器实例使用后正确关闭,避免资源泄漏

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
zy
2025-08-17 15:30:16 +08:00
committed by GitHub
parent cfaee894f5
commit 0e4450b12c
7 changed files with 41 additions and 41 deletions

View File

@@ -3,9 +3,8 @@ package main
import (
"flag"
"github.com/xpzouying/xiaohongshu-mcp/browser"
"github.com/sirupsen/logrus"
"github.com/xpzouying/xiaohongshu-mcp/configs"
)
func main() {
@@ -16,10 +15,7 @@ func main() {
flag.BoolVar(&headless, "headless", true, "是否无头模式")
flag.Parse()
if err := browser.Init(headless); err != nil {
logrus.Fatalf("failed to init browser: %v", err)
}
defer browser.Close()
configs.InitHeadless(headless)
if err := startServer(); err != nil {
logrus.Fatalf("failed to run server: %v", err)