d7f2c00d7b
- Migration 007: repo_url on apps table + analysis table with FTS5 - Analysis struct, parser, CRUD, validation, hash computation - Selective purge: remote-only apps/analysis preserved across fn index - CLI: fn app list/clone/pull, fn analysis list/clone/pull - search/show/list now include analysis results - Apps removed from git tracking (content lives in Gitea repos) - .gitkeep for apps/ and analysis/ dirs - Bash functions: jupyter analysis pipeline, shell utilities - Browser domain: CDP functions moved from infra to browser Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package browser
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// CdpEvaluate ejecuta una expresion JavaScript en la pagina actual via Runtime.evaluate.
|
|
// Retorna el resultado como string. Soporta expresiones simples y complejas.
|
|
// Para valores no-string, Chrome los serializa a JSON.
|
|
func CdpEvaluate(c *CDPConn, expression string) (string, error) {
|
|
if c == nil {
|
|
return "", fmt.Errorf("cdp evaluate: conexion nula")
|
|
}
|
|
|
|
params := map[string]any{
|
|
"expression": expression,
|
|
"returnByValue": true,
|
|
"awaitPromise": true,
|
|
"userGesture": true,
|
|
}
|
|
|
|
result, err := c.sendCDP("Runtime.evaluate", params)
|
|
if err != nil {
|
|
return "", fmt.Errorf("cdp evaluate: %w", err)
|
|
}
|
|
|
|
// Verificar excepcion JS
|
|
if exc, ok := result["exceptionDetails"]; ok && exc != nil {
|
|
excMap, _ := exc.(map[string]any)
|
|
text, _ := excMap["text"].(string)
|
|
return "", fmt.Errorf("cdp evaluate: excepcion JS: %s", text)
|
|
}
|
|
|
|
// Extraer valor del resultado
|
|
resVal, ok := result["result"].(map[string]any)
|
|
if !ok {
|
|
return "", fmt.Errorf("cdp evaluate: resultado inesperado: %v", result)
|
|
}
|
|
|
|
value, ok := resVal["value"]
|
|
if !ok {
|
|
// Puede ser undefined o un tipo no serializable
|
|
typ, _ := resVal["type"].(string)
|
|
return typ, nil
|
|
}
|
|
|
|
return fmt.Sprintf("%v", value), nil
|
|
}
|