Files
navegator/cmd/screenshot.go
T
Developer 3253828fef
Tests / Lint (push) Has been cancelled
Tests / Unit Tests (push) Has been cancelled
Tests / E2E Tests (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
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>
2026-03-24 23:33:07 +01:00

79 lines
2.0 KiB
Go

package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"path/filepath"
"navegator/pkg/browser"
)
func main() {
// Parámetros
url := flag.String("url", "", "URL a capturar (requerido)")
output := flag.String("o", "screenshot.png", "Archivo de salida")
profile := flag.String("profile", "screenshot-bot", "Perfil de navegador a usar")
headless := flag.Bool("headless", true, "Modo headless")
fullPage := flag.Bool("full", false, "Captura página completa")
width := flag.Int("width", 1280, "Ancho de ventana")
height := flag.Int("height", 720, "Alto de ventana")
flag.Parse()
if *url == "" {
fmt.Println("Error: debes proporcionar una URL con -url")
fmt.Println("\nEjemplo:")
fmt.Println(" ./screenshot -url https://example.com -o captura.png")
fmt.Println("\nOpciones:")
flag.PrintDefaults()
os.Exit(1)
}
ctx := context.Background()
// Configurar navegador
currentDir, _ := os.Getwd()
profilesDir := filepath.Join(currentDir, "perfiles")
config := browser.DefaultConfig()
config.ProfilesBaseDir = profilesDir
config.ProfileName = *profile
config.StealthFlags.Headless = *headless
config.StealthFlags.WindowSize = [2]int{*width, *height}
log.Printf("📸 Capturando: %s", *url)
log.Printf("👤 Usando perfil: %s", *profile)
// Lanzar navegador
b, err := browser.Launch(ctx, config)
if err != nil {
log.Fatalf("❌ Error: %v", err)
}
defer b.Close()
// Navegar
opts := browser.DefaultNavigateOptions()
opts.Timeout = 15 * 1000000000 // 15 segundos
if err := b.Navigate(ctx, *url, opts); err != nil {
log.Printf("⚠️ Timeout en navegación, pero continuando...")
}
// Tomar screenshot
log.Println("📷 Capturando pantalla...")
screenshot, err := b.Screenshot(ctx, *fullPage)
if err != nil {
log.Fatalf("❌ Error al capturar: %v", err)
}
// Guardar
if err := os.WriteFile(*output, screenshot, 0644); err != nil {
log.Fatalf("❌ Error al guardar: %v", err)
}
log.Printf("✅ Screenshot guardado: %s (%d bytes)", *output, len(screenshot))
}