Initial commit: navegator - Chrome CDP automation for LLMs
Add complete navegator system for stealthy browser automation: - CDP client with WebSocket communication - Browser API with navigation, storage, network, runtime - Stealth flags and anti-detection scripts - Persistent profile support - Examples and comprehensive documentation Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"navegator/pkg/browser"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Obtener ruta absoluta de perfiles
|
||||
currentDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("Error al obtener directorio actual: %v", err)
|
||||
}
|
||||
|
||||
profilesDir := filepath.Join(currentDir, "perfiles")
|
||||
|
||||
// Configuración
|
||||
config := browser.DefaultConfig()
|
||||
config.ProfilesBaseDir = profilesDir
|
||||
config.ProfileName = "test-profile"
|
||||
|
||||
// Modo visible (cambiar a true para headless)
|
||||
config.StealthFlags.Headless = false
|
||||
|
||||
// Ventana más pequeña
|
||||
config.StealthFlags.WindowSize = [2]int{1280, 720}
|
||||
|
||||
log.Println("========================================")
|
||||
log.Println("Navegator - Control de Chrome via CDP")
|
||||
log.Println("========================================")
|
||||
log.Printf("Directorio de perfiles: %s\n", profilesDir)
|
||||
log.Printf("Perfil: %s\n", config.ProfileName)
|
||||
log.Println("Lanzando navegador...")
|
||||
|
||||
// Lanzar navegador
|
||||
b, err := browser.Launch(ctx, config)
|
||||
if err != nil {
|
||||
log.Fatalf("❌ Error al lanzar navegador: %v", err)
|
||||
}
|
||||
defer b.Close()
|
||||
|
||||
log.Println("✅ Navegador lanzado exitosamente!")
|
||||
log.Printf("📂 Perfil ubicado en: %s\n", b.ProfilePath())
|
||||
log.Printf("🔧 Debug URL: %s\n", b.DebugURL())
|
||||
|
||||
// Iniciar recording de acciones
|
||||
recordingFile := filepath.Join(currentDir, "session.log")
|
||||
if err := b.StartRecording(recordingFile); err != nil {
|
||||
log.Printf("⚠️ No se pudo iniciar recording: %v", err)
|
||||
} else {
|
||||
log.Printf("📝 Recording activado: %s\n", recordingFile)
|
||||
}
|
||||
|
||||
// Navegar a página de prueba
|
||||
b.AddComment("=== INICIO DE SESIÓN ===")
|
||||
log.Println("\n📍 Navegando a example.com...")
|
||||
if err := b.Navigate(ctx, "https://example.com", nil); err != nil {
|
||||
log.Printf("❌ Error al navegar: %v", err)
|
||||
} else {
|
||||
log.Println("✅ Navegación completada")
|
||||
}
|
||||
|
||||
b.AddComment("Página cargada correctamente")
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// Obtener información de la página
|
||||
log.Println("\n📊 Obteniendo información de la página...")
|
||||
|
||||
title, _ := b.Evaluate(ctx, "document.title")
|
||||
log.Printf(" Título: %v", title.Value)
|
||||
|
||||
url, _ := b.Evaluate(ctx, "window.location.href")
|
||||
log.Printf(" URL: %v", url.Value)
|
||||
|
||||
h1Text, _ := b.GetText(ctx, "h1")
|
||||
log.Printf(" H1: %s", h1Text)
|
||||
|
||||
// Verificar stealth
|
||||
log.Println("\n🕵️ Verificando stealth...")
|
||||
webdriver, _ := b.Evaluate(ctx, "navigator.webdriver")
|
||||
log.Printf(" navigator.webdriver: %v", webdriver.Value)
|
||||
|
||||
hasChrome, _ := b.Evaluate(ctx, "typeof window.chrome !== 'undefined'")
|
||||
log.Printf(" window.chrome existe: %v", hasChrome.Value)
|
||||
|
||||
// Mantener navegador abierto
|
||||
log.Println("\n✋ Navegador abierto. Presiona Ctrl+C para cerrar...")
|
||||
|
||||
// Esperar señal de interrupción
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||
<-sigChan
|
||||
|
||||
fmt.Println("\n👋 Cerrando navegador...")
|
||||
}
|
||||
Reference in New Issue
Block a user