feat: add local cdp startup and external association

This commit is contained in:
QiuSW
2026-07-25 15:53:31 +08:00
parent 972c637716
commit 4063b851eb
17 changed files with 845 additions and 158 deletions
+25 -12
View File
@@ -14,6 +14,10 @@ type BrowserKind string
const (
BrowserChrome BrowserKind = "chrome"
BrowserEdge BrowserKind = "edge"
DefaultRemoteDebugPort = 9666
MinRemoteDebugPort = 1024
MaxRemoteDebugPort = 65535
)
func (k BrowserKind) Valid() bool { return k == BrowserChrome || k == BrowserEdge }
@@ -35,6 +39,7 @@ type LaunchSpec struct {
Executable string
UserDataDir string
ProfileDirectory string
RemoteDebugPort int
TargetURL string
ProxyServer string
Headless bool
@@ -49,6 +54,9 @@ func (s LaunchSpec) Normalize() (LaunchSpec, error) {
if userDataDir == "" || !filepath.IsAbs(userDataDir) {
return LaunchSpec{}, fmt.Errorf("%w: user data dir must be absolute", ErrInvalidLaunchSpec)
}
if s.RemoteDebugPort != 0 && !ValidRemoteDebugPort(s.RemoteDebugPort) {
return LaunchSpec{}, fmt.Errorf("%w: remote debugging port must be between %d and %d", ErrInvalidLaunchSpec, MinRemoteDebugPort, MaxRemoteDebugPort)
}
target := strings.TrimSpace(s.TargetURL)
if target != "" {
parsed, err := url.Parse(target)
@@ -67,19 +75,24 @@ func (s LaunchSpec) Normalize() (LaunchSpec, error) {
return normalized, nil
}
func ValidRemoteDebugPort(port int) bool {
return port >= MinRemoteDebugPort && port <= MaxRemoteDebugPort
}
type InstanceView struct {
ID string
Kind BrowserKind
Executable string
PID int
UserDataDir string
Profile string
TargetURL string
Status InstanceStatus
ExitCode *int
StartedAt time.Time
ChangedAt time.Time
IdentityNote string
ID string
Kind BrowserKind
Executable string
PID int
RemoteDebugPort int
UserDataDir string
Profile string
TargetURL string
Status InstanceStatus
ExitCode *int
StartedAt time.Time
ChangedAt time.Time
IdentityNote string
}
type EventKind string