From 00ff7ea83029eda7cb4b4decc1f9768eb7cd6e51 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Sat, 28 Feb 2026 15:35:36 +0000 Subject: [PATCH] feat: add MouseDown/MouseUp methods to InteractiveBrowser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enables drag operations (mousedown → mousemove → mouseup) needed for slider captchas and other drag-based interactions. Closes #79 Co-Authored-By: Claude Opus 4.6 --- interactive.go | 36 ++++++++++++++++++++++++++++++++++++ promote_test.go | 4 +++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/interactive.go b/interactive.go index aad8558..8929a8f 100644 --- a/interactive.go +++ b/interactive.go @@ -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) } diff --git a/promote_test.go b/promote_test.go index 88a8b9d..3e60725 100644 --- a/promote_test.go +++ b/promote_test.go @@ -13,7 +13,9 @@ 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) MouseMove(float64, float64) 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 } func (m mockInteractiveBrowser) KeyboardPress(string) error { return nil } -- 2.49.1