feat: add MouseDown/MouseUp to InteractiveBrowser #80

Merged
Claude merged 1 commits from feature/79-mouse-down-up into main 2026-02-28 15:35:56 +00:00
2 changed files with 39 additions and 1 deletions

View File

@@ -23,6 +23,10 @@ type InteractiveBrowser interface {
// MouseClick clicks at the given coordinates with the specified button ("left", "middle", "right").
MouseClick(x, y float64, button string) error
// MouseDown presses the mouse button at the given coordinates without releasing.
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
// MouseWheel scrolls by the given delta.
@@ -156,6 +160,38 @@ func (ib *interactiveBrowser) MouseClick(x, y float64, button string) error {
return ib.page.Mouse().Click(x, y, playwright.MouseClickOptions{Button: btn})
}
func (ib *interactiveBrowser) MouseDown(x, y float64, button string) error {
if err := ib.page.Mouse().Move(x, y); err != nil {
return err
}
var btn *playwright.MouseButton
switch button {
case "right":
btn = playwright.MouseButtonRight
case "middle":
btn = playwright.MouseButtonMiddle
default:
btn = playwright.MouseButtonLeft
}
return ib.page.Mouse().Down(playwright.MouseDownOptions{Button: btn})
}
func (ib *interactiveBrowser) MouseUp(x, y float64, button string) error {
if err := ib.page.Mouse().Move(x, y); err != nil {
return err
}
var btn *playwright.MouseButton
switch button {
case "right":
btn = playwright.MouseButtonRight
case "middle":
btn = playwright.MouseButtonMiddle
default:
btn = playwright.MouseButtonLeft
}
return ib.page.Mouse().Up(playwright.MouseUpOptions{Button: btn})
}
func (ib *interactiveBrowser) MouseMove(x, y float64) error {
return ib.page.Mouse().Move(x, y)
}

View File

@@ -13,6 +13,8 @@ func (m mockInteractiveBrowser) GoBack() (string, error) { return
func (m mockInteractiveBrowser) GoForward() (string, error) { return "", nil }
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) MouseWheel(float64, float64) error { return nil }
func (m mockInteractiveBrowser) KeyboardType(string) error { return nil }