feat: add steps parameter to MouseMove for smooth drag gestures
All checks were successful
CI / test (pull_request) Successful in 47s
CI / vet (pull_request) Successful in 1m34s
CI / build (pull_request) Successful in 1m37s

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:
2026-02-28 16:23:32 +00:00
parent 035151d9fa
commit 1b95d12890
2 changed files with 10 additions and 5 deletions

View File

@@ -27,8 +27,9 @@ type InteractiveBrowser interface {
MouseDown(x, y float64, button string) error MouseDown(x, y float64, button string) error
// MouseUp releases the mouse button at the given coordinates. // MouseUp releases the mouse button at the given coordinates.
MouseUp(x, y float64, button string) error MouseUp(x, y float64, button string) error
// MouseMove moves the mouse to the given coordinates. // MouseMove moves the mouse to the given coordinates. An optional steps parameter
MouseMove(x, y float64) error // controls how many intermediate mousemove events are generated (default 1).
MouseMove(x, y float64, steps ...int) error
// MouseWheel scrolls by the given delta. // MouseWheel scrolls by the given delta.
MouseWheel(deltaX, deltaY float64) error 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}) return ib.page.Mouse().Up(playwright.MouseUpOptions{Button: btn})
} }
func (ib *interactiveBrowser) MouseMove(x, y float64) error { func (ib *interactiveBrowser) MouseMove(x, y float64, steps ...int) error {
return ib.page.Mouse().Move(x, y) 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 { func (ib *interactiveBrowser) MouseWheel(deltaX, deltaY float64) error {

View File

@@ -15,7 +15,7 @@ func (m mockInteractiveBrowser) URL() string { return
func (m mockInteractiveBrowser) MouseClick(float64, float64, string) error { return nil } func (m mockInteractiveBrowser) MouseClick(float64, float64, string) error { return nil }
func (m mockInteractiveBrowser) MouseDown(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) 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) MouseWheel(float64, float64) error { return nil }
func (m mockInteractiveBrowser) KeyboardType(string) error { return nil } func (m mockInteractiveBrowser) KeyboardType(string) error { return nil }
func (m mockInteractiveBrowser) KeyboardPress(string) error { return nil } func (m mockInteractiveBrowser) KeyboardPress(string) error { return nil }