Files
egutierrez 5b10b419a2 feat(browser): auto-commit con 44 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-06 12:49:54 +02:00

65 lines
1.8 KiB
Go

package browser
import (
"fmt"
)
// CdpNavForward avanza una entrada en el historial de navegacion de la pestana activa.
// Obtiene el historial via Page.getNavigationHistory, calcula el indice siguiente y
// navega a esa entrada via Page.navigateToHistoryEntry.
// Retorna error si ya estamos al final del historial (no hay entradas adelante).
func CdpNavForward(c *CDPConn) error {
if c == nil {
return fmt.Errorf("cdp nav forward: conexion nula")
}
result, err := c.sendCDP("Page.getNavigationHistory", nil)
if err != nil {
return fmt.Errorf("cdp nav forward: obtener historial: %w", err)
}
currentIndexRaw, ok := result["currentIndex"]
if !ok {
return fmt.Errorf("cdp nav forward: respuesta sin currentIndex")
}
currentIndex, ok := currentIndexRaw.(float64)
if !ok {
return fmt.Errorf("cdp nav forward: currentIndex tipo inesperado: %T", currentIndexRaw)
}
entriesRaw, ok := result["entries"]
if !ok {
return fmt.Errorf("cdp nav forward: respuesta sin entries")
}
entries, ok := entriesRaw.([]any)
if !ok {
return fmt.Errorf("cdp nav forward: entries tipo inesperado: %T", entriesRaw)
}
idx := int(currentIndex) + 1
if idx >= len(entries) {
return fmt.Errorf("cdp nav forward: ya en el final del historial")
}
entry, ok := entries[idx].(map[string]any)
if !ok {
return fmt.Errorf("cdp nav forward: entrada[%d] tipo inesperado: %T", idx, entries[idx])
}
entryIDRaw, ok := entry["id"]
if !ok {
return fmt.Errorf("cdp nav forward: entrada sin campo id")
}
entryIDFloat, ok := entryIDRaw.(float64)
if !ok {
return fmt.Errorf("cdp nav forward: entry id tipo inesperado: %T", entryIDRaw)
}
entryID := int(entryIDFloat)
_, err = c.sendCDP("Page.navigateToHistoryEntry", map[string]any{"entryId": entryID})
if err != nil {
return fmt.Errorf("cdp nav forward: navegar a entrada %d: %w", entryID, err)
}
return nil
}