feat: 拆分 macOS 架构安装包并内置浏览器运行时

将 macOS 安装包拆分为 arm64 与 amd64 两个独立产物,每个安装包只携带对应架构的服务、托盘程序、Playwright driver 和 Chromium。

调整桌面端 CI,在构建阶段预下载并组装 Playwright runtime;服务启动时按当前进程架构解析 runtime 根目录,避免安装后联网下载 Chromium。

移除 Windows/macOS 安装阶段的 browser-install 调用和托盘中的安装/修复 Chromium 菜单,保留 Linux 安装脚本的既有流程。

升级 Playwright Go 依赖到 v0.6100.0,并迁移导入路径;仅按本次授权修改 CAPTCHA 相关文件的 import 行,不改变 CAPTCHA 行为。

验证:go test ./...、go vet ./...、macOS 安装脚本语法、Workflow YAML 语法、Windows amd64 交叉编译及两个 macOS pkg 的本地组装。
This commit is contained in:
Christ committed 2026-08-12 01:09:59 +08:00
1 parent d4e9717570
commit 1ac6912c7b
24 files changed
+242 -93

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ import (
"sync/atomic"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
)
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"sync"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
)
+43 -2
View File
@@ -1,5 +1,5 @@
// Package browser 用 playwright-go 在进程内驱动 Chromium。
// 首次使用时自动下载 Chromium(playwright.Install),无需手动启动外部服务。
// 安装包提供预置 runtime;开发环境没有预置 runtime 时才自动下载。
package browser
import (
@@ -10,11 +10,13 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"golang.org/x/sync/singleflight"
"xianyu-go/internal/xianyu"
@@ -58,6 +60,42 @@ func skipPlaywrightBrowserDownload() bool {
}
}
func packagedPlaywrightRuntimeReady() bool {
driverDir := strings.TrimSpace(os.Getenv("PLAYWRIGHT_DRIVER_PATH"))
if driverDir == "" {
return false
}
nodeName := "node"
if runtime.GOOS == "windows" {
nodeName = "node.exe"
}
for _, path := range []string{
filepath.Join(driverDir, nodeName),
filepath.Join(driverDir, "package", "cli.js"),
} {
if _, err := os.Stat(path); err != nil {
return false
}
}
if strings.TrimSpace(os.Getenv("PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH")) != "" {
return true
}
browserDir := strings.TrimSpace(os.Getenv("PLAYWRIGHT_BROWSERS_PATH"))
if browserDir == "" {
return false
}
matches, err := filepath.Glob(filepath.Join(browserDir, "chromium-*"))
if err != nil {
return false
}
for _, match := range matches {
if info, statErr := os.Stat(match); statErr == nil && info.IsDir() {
return true
}
}
return false
}
// Manager 管理浏览器生命周期与按账号复用的上下文池。
type Manager struct {
pw *playwright.Playwright
@@ -108,6 +146,9 @@ func NewManager(logger *slog.Logger) *Manager {
renewLocks: make(map[string]*sync.Mutex),
renewSlots: make(chan struct{}, 3),
installFn: func() error {
if packagedPlaywrightRuntimeReady() {
return nil
}
opts := &playwright.RunOptions{
Browsers: []string{"chromium"},
Verbose: false,
+34 -1
View File
@@ -1,10 +1,13 @@
package browser
import (
"os"
"path/filepath"
"runtime"
"testing"
"time"
playwright "github.com/playwright-community/playwright-go"
playwright "github.com/mxschmitt/playwright-go"
)
// TestChromiumLaunchArgs 验证启动参数含关键安全/反检测项。
@@ -28,6 +31,36 @@ func TestChromiumLaunchArgs(t *testing.T) {
}
}
func TestPackagedPlaywrightRuntimeReady(t *testing.T) {
runtimeRoot := t.TempDir()
driverDir := filepath.Join(runtimeRoot, "driver")
browserDir := filepath.Join(runtimeRoot, "browsers")
if err := os.MkdirAll(filepath.Join(driverDir, "package"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Join(browserDir, "chromium-1228"), 0o755); err != nil {
t.Fatal(err)
}
nodeName := "node"
if runtime.GOOS == "windows" {
nodeName = "node.exe"
}
for _, path := range []string{
filepath.Join(driverDir, nodeName),
filepath.Join(driverDir, "package", "cli.js"),
} {
if err := os.WriteFile(path, []byte("runtime"), 0o755); err != nil {
t.Fatal(err)
}
}
t.Setenv("PLAYWRIGHT_DRIVER_PATH", driverDir)
t.Setenv("PLAYWRIGHT_BROWSERS_PATH", browserDir)
t.Setenv("PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH", "")
if !packagedPlaywrightRuntimeReady() {
t.Fatal("预置 Playwright runtime 应被识别")
}
}
// newTestManager 构造一个不触网的 Manager(pool 空,maxSize 小便于测试驱逐)。
func newTestManager(maxSize int) *Manager {
return &Manager{
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"sync"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
"xianyu-go/internal/xianyu/mtop"
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
// loginFormSelectors 登录表单选择器,主页面和 iframe 中都要找。
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/logsafe"
)
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
// sliderSelectors 按优先级排列的滑块相关选择器(移植自 xianyu_slider_stealth.py)。
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
const (
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
var fallbackTrackSelectors = []string{
@@ -11,7 +11,7 @@ import (
"testing"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
func TestReferencePlaywrightSliderBrowserIntegration(t *testing.T) {
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
type cookieReadResult struct {