mirror of
https://github.com/black-ant/Ant-Browser.git
synced 2026-07-14 18:48:55 +08:00
publish: 1.1.0 snapshot (ff46de5)
channel: master version: 1.1.0 source-ref: master published-at-utc: 2026-03-20T14:14:07Z
This commit is contained in:
@@ -8,15 +8,13 @@ import (
|
||||
)
|
||||
|
||||
const browserStartReadyTimeout = 10 * time.Second
|
||||
const browserStartStableWindow = 1200 * time.Millisecond
|
||||
|
||||
func waitBrowserDebugPortReady(debugPort int, timeout time.Duration) error {
|
||||
address := fmt.Sprintf("127.0.0.1:%d", debugPort)
|
||||
deadline := time.Now().Add(timeout)
|
||||
|
||||
for time.Now().Before(deadline) {
|
||||
conn, err := net.DialTimeout("tcp", address, 250*time.Millisecond)
|
||||
if err == nil {
|
||||
_ = conn.Close()
|
||||
if canConnectDebugPort(debugPort, 250*time.Millisecond) {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
@@ -25,6 +23,38 @@ func waitBrowserDebugPortReady(debugPort int, timeout time.Duration) error {
|
||||
return fmt.Errorf("浏览器进程未在 %s 内完成启动,调试端口 %d 未就绪", timeout.Round(time.Second), debugPort)
|
||||
}
|
||||
|
||||
func waitBrowserDebugPortStable(debugPort int, timeout time.Duration, stableFor time.Duration) error {
|
||||
if err := waitBrowserDebugPortReady(debugPort, timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
if stableFor <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
deadline := time.Now().Add(stableFor)
|
||||
for time.Now().Before(deadline) {
|
||||
if !canConnectDebugPort(debugPort, 250*time.Millisecond) {
|
||||
return fmt.Errorf("浏览器调试端口 %d 短暂就绪后又失效", debugPort)
|
||||
}
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func canConnectDebugPort(debugPort int, dialTimeout time.Duration) bool {
|
||||
if debugPort <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
address := fmt.Sprintf("127.0.0.1:%d", debugPort)
|
||||
conn, err := net.DialTimeout("tcp", address, dialTimeout)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
_ = conn.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
func describeChromeProcessStartError(chromeBinaryPath string, err error) string {
|
||||
raw := strings.TrimSpace(err.Error())
|
||||
lower := strings.ToLower(raw)
|
||||
@@ -37,8 +67,10 @@ func describeChromeProcessStartError(chromeBinaryPath string, err error) string
|
||||
case strings.Contains(lower, "not a valid win32 application"),
|
||||
strings.Contains(raw, "不是有效的 win32 应用程序"),
|
||||
strings.Contains(raw, "不是有效的 Win32 应用程序"),
|
||||
strings.Contains(raw, "bad exe format"):
|
||||
return fmt.Sprintf("实例启动失败:当前浏览器内核与系统架构不兼容。可执行文件:%s。请更换为可用的 Windows 64 位 Chrome 内核。", chromeBinaryPath)
|
||||
strings.Contains(raw, "bad exe format"),
|
||||
strings.Contains(lower, "exec format error"),
|
||||
strings.Contains(lower, "cannot execute binary file"):
|
||||
return fmt.Sprintf("实例启动失败:当前浏览器内核与系统/架构不兼容。可执行文件:%s。请确认 Linux 环境使用的是对应架构的 Chrome 内核,而不是 Windows 可执行文件。", chromeBinaryPath)
|
||||
case strings.Contains(raw, "系统找不到指定的文件"),
|
||||
strings.Contains(lower, "file not found"),
|
||||
strings.Contains(lower, "no such file"),
|
||||
|
||||
Reference in New Issue
Block a user