e33b306225
Normaliza lang: typescript → ts en funciones frontend y corrige file_path de functions/infra/ → functions/browser/ en funciones CDP. Actualiza referencias cn_typescript_core → cn_ts_core. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
38 lines
1.3 KiB
Markdown
38 lines
1.3 KiB
Markdown
---
|
|
name: cdp_wait_element
|
|
kind: function
|
|
lang: go
|
|
domain: browser
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func CdpWaitElement(c *CDPConn, selector string, timeout time.Duration) error"
|
|
description: "Espera hasta que un selector CSS exista en el DOM. Hace polling con Runtime.evaluate cada 200ms. Retorna nil cuando el elemento aparece o error si se agota el timeout. Util despues de navegacion o acciones que producen cambios dinamicos."
|
|
tags: [chrome, cdp, browser, automation, dom, wait, polling, devtools]
|
|
uses_functions: [cdp_connect_go_browser, cdp_evaluate_go_browser]
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [fmt, time]
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "functions/browser/cdp_wait_element.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
conn, _ := CdpConnect(9222)
|
|
CdpNavigate(conn, "https://example.com")
|
|
|
|
// Esperar hasta 10 segundos a que aparezca el contenido
|
|
if err := CdpWaitElement(conn, ".main-content", 10*time.Second); err != nil {
|
|
log.Fatal("Timeout esperando elemento:", err)
|
|
}
|
|
```
|
|
|
|
## Notas
|
|
|
|
Usa `document.querySelector(selector) !== null` como condicion. Si `timeout <= 0` usa 10s por defecto. Los errores de `CdpEvaluate` durante el polling (pagina cargando) se ignoran y se reintenta en el siguiente ciclo.
|