feat: add steps parameter to MouseMove for smooth drag gestures
Makes MouseMove accept an optional steps variadic parameter that maps to Playwright's MouseMoveOptions.Steps, generating intermediate mousemove events for human-like drag behavior. Closes #81 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,8 +27,9 @@ type InteractiveBrowser interface {
|
||||
MouseDown(x, y float64, button string) error
|
||||
// MouseUp releases the mouse button at the given coordinates.
|
||||
MouseUp(x, y float64, button string) error
|
||||
// MouseMove moves the mouse to the given coordinates.
|
||||
MouseMove(x, y float64) error
|
||||
// MouseMove moves the mouse to the given coordinates. An optional steps parameter
|
||||
// controls how many intermediate mousemove events are generated (default 1).
|
||||
MouseMove(x, y float64, steps ...int) error
|
||||
// MouseWheel scrolls by the given delta.
|
||||
MouseWheel(deltaX, deltaY float64) error
|
||||
|
||||
@@ -192,8 +193,12 @@ func (ib *interactiveBrowser) MouseUp(x, y float64, button string) error {
|
||||
return ib.page.Mouse().Up(playwright.MouseUpOptions{Button: btn})
|
||||
}
|
||||
|
||||
func (ib *interactiveBrowser) MouseMove(x, y float64) error {
|
||||
return ib.page.Mouse().Move(x, y)
|
||||
func (ib *interactiveBrowser) MouseMove(x, y float64, steps ...int) error {
|
||||
var opts playwright.MouseMoveOptions
|
||||
if len(steps) > 0 && steps[0] > 1 {
|
||||
opts.Steps = playwright.Int(steps[0])
|
||||
}
|
||||
return ib.page.Mouse().Move(x, y, opts)
|
||||
}
|
||||
|
||||
func (ib *interactiveBrowser) MouseWheel(deltaX, deltaY float64) error {
|
||||
|
||||
@@ -15,7 +15,7 @@ func (m mockInteractiveBrowser) URL() string { return
|
||||
func (m mockInteractiveBrowser) MouseClick(float64, float64, string) error { return nil }
|
||||
func (m mockInteractiveBrowser) MouseDown(float64, float64, string) error { return nil }
|
||||
func (m mockInteractiveBrowser) MouseUp(float64, float64, string) error { return nil }
|
||||
func (m mockInteractiveBrowser) MouseMove(float64, float64) error { return nil }
|
||||
func (m mockInteractiveBrowser) MouseMove(float64, float64, ...int) error { return nil }
|
||||
func (m mockInteractiveBrowser) MouseWheel(float64, float64) error { return nil }
|
||||
func (m mockInteractiveBrowser) KeyboardType(string) error { return nil }
|
||||
func (m mockInteractiveBrowser) KeyboardPress(string) error { return nil }
|
||||
|
||||
Reference in New Issue
Block a user