add09c2faa
10 funciones Go en infra/ para controlar Chrome via Chrome DevTools Protocol: chrome_launch, cdp_connect, cdp_navigate, cdp_evaluate, cdp_screenshot, cdp_click, cdp_type_text, cdp_wait_element, cdp_get_html, cdp_close. WebSocket RFC 6455 implementado sin dependencias externas. Incluye tests de integración con Chrome real. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
760 B
Go
31 lines
760 B
Go
package infra
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// CdpNavigate navega a la URL indicada usando Page.navigate.
|
|
// Espera a que la carga este confirmada via Page.loadEventFired antes de retornar.
|
|
// El timeout de la navegacion es gestionado por Chrome internamente.
|
|
func CdpNavigate(c *CDPConn, targetURL string) error {
|
|
if c == nil {
|
|
return fmt.Errorf("cdp navigate: conexion nula")
|
|
}
|
|
|
|
params := map[string]any{
|
|
"url": targetURL,
|
|
}
|
|
|
|
result, err := c.sendCDP("Page.navigate", params)
|
|
if err != nil {
|
|
return fmt.Errorf("cdp navigate: %w", err)
|
|
}
|
|
|
|
// Verificar que no hubo error de navegacion
|
|
if errText, ok := result["errorText"].(string); ok && errText != "" {
|
|
return fmt.Errorf("cdp navigate: error navegando a %q: %s", targetURL, errText)
|
|
}
|
|
|
|
return nil
|
|
}
|