feat: modo de velocidad de sesión (browser_set_mode) + acciones más rápidas en auto
Añade un flag de velocidad por sesión para que el manejo del navegador sea muy rápido por defecto, conservando un modo sigiloso para cuando haya detección anti-bot fuerte. - Nueva tool browser_set_mode (tools_session.go): fija el modo de la sesión por puerto en el pool. 'auto' (default del MCP) = rápido; 'human' = sigiloso anti-detección; también admite 'fast'/'instant'. Cada tool de acción puede overridearlo con su arg mode. - pool.go: estado de modo por puerto (modes map + setMode/getMode), limpiado en drop y closeAll. - tools_dom.go: effectiveMode resuelve el modo (arg de la llamada > modo de sesión > 'auto'). settleForMode reemplaza el sleep ciego fijo de 400ms tras cada acción mutante: 60ms en auto/fast, aleatorio 250-650ms en human (ritmo no-máquina), 0 en instant. dom_type_ref gana arg mode y rutea a CdpTypeRefFast (insertText, un round-trip) en auto o CdpTypeRef (carácter a carácter) en human. Descripciones del arg mode actualizadas (el default ya no es human). - tools_lifecycle.go: browser_launch_profile reemplaza el sleep(1s) ciego por un poll del puerto CDP (waitCDPPort). - .gitignore: ignora registry.db/operations.db (no deben vivir en la app; regla db_locations). Doctrina invertida respecto a la anterior 'humanizado siempre': ahora rápido por defecto, sigiloso bajo demanda.
This commit is contained in:
+20
-7
@@ -324,16 +324,16 @@ func (d *deps) handleBrowserLaunchProfile(_ context.Context, _ mcp.CallToolReque
|
||||
pid := cmd.Process.Pid
|
||||
_ = cmd.Process.Release()
|
||||
|
||||
// Give Chromium a moment to come up. If it forwarded to an existing master the
|
||||
// child exits fast; the launched pid is still informative.
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// When cdp=true, opportunistically confirm the port responds (best-effort: a
|
||||
// forwarded launch may not bind the port if the master had no CDP).
|
||||
// Give Chromium a moment to come up. With CDP we poll the port instead of a
|
||||
// blind 1s sleep: we return as soon as it responds (best-effort: a forwarded
|
||||
// launch may not bind the port if the master had no CDP). Without CDP there's
|
||||
// no port to poll, so we give the window a short margin to appear / forward.
|
||||
if a.CDP && note == "" {
|
||||
if !cdpPortResponds(cdpPort) {
|
||||
if !waitCDPPort(cdpPort, 5*time.Second) {
|
||||
note = "cdp port not confirmed listening yet"
|
||||
}
|
||||
} else {
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
}
|
||||
|
||||
out := map[string]any{
|
||||
@@ -452,6 +452,19 @@ func processAlive(pid int) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// waitCDPPort polls the CDP port until it accepts a TCP connection or the timeout
|
||||
// elapses. Replaces a blind sleep: returns as soon as Chromium binds the port.
|
||||
func waitCDPPort(port int, timeout time.Duration) bool {
|
||||
deadline := time.Now().Add(timeout)
|
||||
for time.Now().Before(deadline) {
|
||||
if cdpPortResponds(port) {
|
||||
return true
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return cdpPortResponds(port)
|
||||
}
|
||||
|
||||
// cdpPortResponds reports whether something is listening on the CDP port on
|
||||
// 127.0.0.1. Single TCP dial with a short timeout; best-effort confirmation only.
|
||||
func cdpPortResponds(port int) bool {
|
||||
|
||||
Reference in New Issue
Block a user