@@ -74,27 +74,16 @@ func (h *ElementHandle) boundingBox() (*Rect, error) {
74
74
return & Rect {X : x + position .X , Y : y + position .Y , Width : width , Height : height }, nil
75
75
}
76
76
77
+ // checkHitTargetAt checks if the element is hit by the pointer at the given point.
78
+ //
79
+ // It will recurse through frames and iframes to check if the point hits a target
80
+ // when an error:intercept occurs.
81
+ //
82
+ // It will eventually return error:intercept if the point doesn't hit any target. At
83
+ // this point the caller should retry the action after scrolling.
77
84
func (h * ElementHandle ) checkHitTargetAt (apiCtx context.Context , point Position ) (bool , error ) {
78
- frame , err := h .ownerFrame (apiCtx )
79
- if err != nil {
80
- return false , fmt .Errorf ("checking hit target at %v: %w" , point , err )
81
- }
82
- if frame != nil && frame .parentFrame != nil {
83
- el , err := frame .FrameElement ()
84
- if err != nil {
85
- return false , err
86
- }
87
- box , err := el .boundingBox ()
88
- if err != nil {
89
- return false , err
90
- }
91
- if box == nil {
92
- return false , errors .New ("missing bounding box of element" )
93
- }
94
- // Translate from viewport coordinates to frame coordinates.
95
- point .X -= box .X
96
- point .Y -= box .Y
97
- }
85
+ h .logger .Debugf ("ElementHandle:checkHitTargetAt" , "checking hit target at %v" , point )
86
+
98
87
fn := `
99
88
(node, injected, point) => {
100
89
return injected.checkHitTargetAt(node, point);
@@ -112,14 +101,28 @@ func (h *ElementHandle) checkHitTargetAt(apiCtx context.Context, point Position)
112
101
// Either we're done or an error happened (returned as "error:..." from JS)
113
102
const done = resultDone
114
103
if v , ok := result .(string ); ! ok {
115
- // We got a { hitTargetDescription: ... } result
116
- // Meaning: Another element is preventing pointer events.
117
- //
118
- // It's safe to count an object return as an interception.
119
- // We just don't interpret what is intercepting with the target element
120
- // because we don't need any more functionality from this JS function
121
- // right now.
122
- return false , errorFromDOMError ("error:intercept" )
104
+ frame , err := h .ownerFrame (apiCtx )
105
+ if err != nil {
106
+ return false , fmt .Errorf ("checking hit target at %v: %w" , point , err )
107
+ }
108
+
109
+ if frame == nil {
110
+ // We got a { hitTargetDescription: ... } result
111
+ // Meaning: Another element is preventing pointer events.
112
+ //
113
+ // It's safe to count an object return as an interception.
114
+ // We just don't interpret what is intercepting with the target element
115
+ // because we don't need any more functionality from this JS function
116
+ // right now.
117
+ return false , errorFromDOMError ("error:intercept" )
118
+ }
119
+
120
+ el , err := frame .FrameElement ()
121
+ if err != nil {
122
+ return false , err
123
+ }
124
+
125
+ return el .checkHitTargetAt (apiCtx , point )
123
126
} else if v != done {
124
127
return false , errorFromDOMError (v )
125
128
}
0 commit comments