feat(browser): cdp_click_ref/cdp_hover_ref usan cdp_wait_actionable
Antes de calcular el centro y despachar el pointer, ambos esperan a que el elemento sea accionable (visible + stable + hit-test contra elementFromPoint), evitando clicks/hover tragados por overlays/banners o por elementos aún montándose o animándose. Si la comprobación no converge en 2s, se cae al cálculo de centro previo (sin regresión). Modo 'instant' sigue saltando al click JS directo. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,15 @@
|
|||||||
package browser
|
package browser
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// refActionableTimeout es cuánto espera CdpClickRef/CdpHoverRef a que el elemento
|
||||||
|
// sea accionable (visible+stable+hit-test) antes de caer al cálculo de centro
|
||||||
|
// previo. Lo bastante para tragar animaciones/overlays transitorios sin penalizar
|
||||||
|
// el caso común (que converge en ~1 frame).
|
||||||
|
const refActionableTimeout = 2 * time.Second
|
||||||
|
|
||||||
// refBoxCenter resuelve el centro (x,y) en coords de página de un nodo DOM por su
|
// refBoxCenter resuelve el centro (x,y) en coords de página de un nodo DOM por su
|
||||||
// backendDOMNodeId, vía DOM.getBoxModel. El content quad son 8 floats (4 esquinas).
|
// backendDOMNodeId, vía DOM.getBoxModel. El content quad son 8 floats (4 esquinas).
|
||||||
@@ -37,6 +46,13 @@ func CdpClickRef(c *CDPConn, backendNodeID int, opts MouseHumanOpts) error {
|
|||||||
if opts.Mode == "instant" {
|
if opts.Mode == "instant" {
|
||||||
return clickRefViaJS(c, backendNodeID)
|
return clickRefViaJS(c, backendNodeID)
|
||||||
}
|
}
|
||||||
|
// Preferir el punto validado por actionability (visible + stable + hit-test):
|
||||||
|
// evita clicks tragados por overlays/banners y elementos aún montándose o
|
||||||
|
// animándose. Si no converge dentro del timeout, se cae al cálculo de centro
|
||||||
|
// previo (sin regresión).
|
||||||
|
if x, y, err := CdpWaitActionable(c, backendNodeID, false, refActionableTimeout); err == nil {
|
||||||
|
return CdpClickXYHuman(c, x, y, opts)
|
||||||
|
}
|
||||||
// scroll al elemento si no está visible; ignorar error (no fatal)
|
// scroll al elemento si no está visible; ignorar error (no fatal)
|
||||||
_, _ = c.sendCDP("DOM.scrollIntoViewIfNeeded", map[string]any{"backendNodeId": backendNodeID})
|
_, _ = c.sendCDP("DOM.scrollIntoViewIfNeeded", map[string]any{"backendNodeId": backendNodeID})
|
||||||
cx, cy, err := refBoxCenter(c, backendNodeID)
|
cx, cy, err := refBoxCenter(c, backendNodeID)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ purity: impure
|
|||||||
signature: "func CdpClickRef(c *CDPConn, backendNodeID int, opts MouseHumanOpts) error"
|
signature: "func CdpClickRef(c *CDPConn, backendNodeID int, opts MouseHumanOpts) error"
|
||||||
description: "Click humanizado (Bézier + jitter) sobre el elemento identificado por su #ref del AX outline. El #ref es el backendDOMNodeId estable del nodo DOM. Hace scroll al elemento si no está en viewport antes de calcular las coordenadas vía DOM.getBoxModel."
|
description: "Click humanizado (Bézier + jitter) sobre el elemento identificado por su #ref del AX outline. El #ref es el backendDOMNodeId estable del nodo DOM. Hace scroll al elemento si no está en viewport antes de calcular las coordenadas vía DOM.getBoxModel."
|
||||||
tags: [cdp, browser, action, ref, humanized, navegator]
|
tags: [cdp, browser, action, ref, humanized, navegator]
|
||||||
uses_functions: [cdp_click_xy_human_go_browser]
|
uses_functions: [cdp_click_xy_human_go_browser, cdp_wait_actionable_go_browser]
|
||||||
uses_types: []
|
uses_types: []
|
||||||
returns: []
|
returns: []
|
||||||
returns_optional: false
|
returns_optional: false
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ func CdpHoverRef(c *CDPConn, backendNodeID int, opts MouseHumanOpts) error {
|
|||||||
if c == nil {
|
if c == nil {
|
||||||
return fmt.Errorf("cdp hover ref: conexión nil")
|
return fmt.Errorf("cdp hover ref: conexión nil")
|
||||||
}
|
}
|
||||||
|
// Preferir el punto validado por actionability; si no converge, caer al centro.
|
||||||
|
if x, y, err := CdpWaitActionable(c, backendNodeID, false, refActionableTimeout); err == nil {
|
||||||
|
return CdpMoveMouseHuman(c, x, y, opts)
|
||||||
|
}
|
||||||
// scroll al elemento si no está visible; ignorar error (no fatal)
|
// scroll al elemento si no está visible; ignorar error (no fatal)
|
||||||
_, _ = c.sendCDP("DOM.scrollIntoViewIfNeeded", map[string]any{"backendNodeId": backendNodeID})
|
_, _ = c.sendCDP("DOM.scrollIntoViewIfNeeded", map[string]any{"backendNodeId": backendNodeID})
|
||||||
cx, cy, err := refBoxCenter(c, backendNodeID)
|
cx, cy, err := refBoxCenter(c, backendNodeID)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ purity: impure
|
|||||||
signature: "func CdpHoverRef(c *CDPConn, backendNodeID int, opts MouseHumanOpts) error"
|
signature: "func CdpHoverRef(c *CDPConn, backendNodeID int, opts MouseHumanOpts) error"
|
||||||
description: "Mueve el ratón con trayectoria humanizada (Bézier) sobre el elemento identificado por su #ref del AX outline. Útil para activar menús desplegables, tooltips y cualquier interacción que dependa de hover. El #ref es el backendDOMNodeId estable del nodo DOM."
|
description: "Mueve el ratón con trayectoria humanizada (Bézier) sobre el elemento identificado por su #ref del AX outline. Útil para activar menús desplegables, tooltips y cualquier interacción que dependa de hover. El #ref es el backendDOMNodeId estable del nodo DOM."
|
||||||
tags: [cdp, browser, action, ref, humanized, navegator]
|
tags: [cdp, browser, action, ref, humanized, navegator]
|
||||||
uses_functions: [cdp_move_mouse_human_go_browser]
|
uses_functions: [cdp_move_mouse_human_go_browser, cdp_wait_actionable_go_browser]
|
||||||
uses_types: []
|
uses_types: []
|
||||||
returns: []
|
returns: []
|
||||||
returns_optional: false
|
returns_optional: false
|
||||||
|
|||||||
Reference in New Issue
Block a user