Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: complete canonical mouse actions and drag flow

Luigi Agosti1225f78602a0
diff --git a/cmd/pinchtab/cmd_cli_browser_actions.go b/cmd/pinchtab/cmd_cli_browser_actions.go
index dfb77f95..d8bc7ad5 100644
--- a/cmd/pinchtab/cmd_cli_browser_actions.go
+++ b/cmd/pinchtab/cmd_cli_browser_actions.go
@@ -1,6 +1,7 @@
package main
import (
+ "github.com/pinchtab/pinchtab/internal/bridge"
browseractions "github.com/pinchtab/pinchtab/internal/cli/actions"
"github.com/spf13/cobra"
)
@@ -44,6 +45,19 @@ func newRequiredRefActionCmd(use, short, action string) *cobra.Command {
}
}
+func newMouseActionCmd(use, short, action string, argsValidator cobra.PositionalArgs) *cobra.Command {
+ return &cobra.Command{
+ Use: use,
+ Short: short,
+ Args: argsValidator,
+ Run: func(cmd *cobra.Command, args []string) {
+ runCLI(func(rt cliRuntime) {
+ browseractions.MouseAction(rt.client, rt.base, rt.token, action, args, cmd)
+ })
+ },
+ }
+}
+
var clickCmd = newOptionalRefActionCmd("click <ref>", "Click element", "click")
var dblclickCmd = newOptionalRefActionCmd("dblclick <ref>", "Double-click element", "dblclick")
@@ -61,13 +75,24 @@ var mouseCmd = &cobra.Command{
Short: "Low-level mouse actions (move, down, up, wheel)",
}
-var mouseMoveCmd = newOptionalRefActionCmd("move [ref|selector]", "Move mouse to coordinates or element center", "mousemove")
+var mouseMoveCmd = newMouseActionCmd("move [x y|ref|selector]", "Move mouse to coordinates or element center", bridge.ActionMouseMove, cobra.RangeArgs(0, 2))
-var mouseDownCmd = newOptionalRefActionCmd("down [ref|selector]", "Press mouse button", "mousedown")
+var mouseDownCmd = newMouseActionCmd("down [ref|selector]", "Press mouse button", bridge.ActionMouseDown, cobra.MaximumNArgs(1))
-var mouseUpCmd = newOptionalRefActionCmd("up [ref|selector]", "Release mouse button", "mouseup")
+var mouseUpCmd = newMouseActionCmd("up [ref|selector]", "Release mouse button", bridge.ActionMouseUp, cobra.MaximumNArgs(1))
-var mouseWheelCmd = newOptionalRefActionCmd("wheel [ref|selector]", "Dispatch mouse wheel deltas", "mousewheel")
+var mouseWheelCmd = newMouseActionCmd("wheel [dy|ref|selector]", "Dispatch mouse wheel deltas", bridge.ActionMouseWheel, cobra.MaximumNArgs(1))
+
+var dragCmd = &cobra.Command{
+ Use: "drag <from> <to>",
+ Short: "Drag from one target to another",
+ Args: cobra.ExactArgs(2),
+ Run: func(cmd *cobra.Command, args []string) {
+ runCLI(func(rt cliRuntime) {
+ browseractions.Drag(rt.client, rt.base, rt.token, args, cmd)
+ })
+ },
+}
var focusCmd = newOptionalRefActionCmd("focus <ref>", "Focus element", "focus")
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index ee77e417..f5f18a3b 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -1,6 +1,9 @@
package main
-import "github.com/spf13/cobra"
+import (
+ "github.com/pinchtab/pinchtab/internal/bridge"
+ "github.com/spf13/cobra"
+)
func init() {
registerBrowserCommands()
@@ -17,6 +20,7 @@ func registerBrowserCommands() {
snapCmd,
clickCmd,
dblclickCmd,
+ dragCmd,
typeCmd,
screenshotCmd,
tabsCmd,
@@ -67,6 +71,7 @@ func registerBrowserCommands() {
snapCmd,
clickCmd,
dblclickCmd,
+ dragCmd,
typeCmd,
screenshotCmd,
tabsCmd,
@@ -127,20 +132,22 @@ func configureBrowserFlags() {
addPointFlags(hoverCmd, "hover")
mouseMoveCmd.Flags().String("css", "", "CSS selector instead of ref")
- addPointFlags(mouseMoveCmd, "mousemove")
+ addPointFlags(mouseMoveCmd, bridge.ActionMouseMove)
mouseDownCmd.Flags().String("css", "", "CSS selector instead of ref")
- addPointFlags(mouseDownCmd, "mousedown")
+ addPointFlags(mouseDownCmd, bridge.ActionMouseDown)
mouseDownCmd.Flags().String("button", "left", "Mouse button: left, right, middle")
mouseUpCmd.Flags().String("css", "", "CSS selector instead of ref")
- addPointFlags(mouseUpCmd, "mouseup")
+ addPointFlags(mouseUpCmd, bridge.ActionMouseUp)
mouseUpCmd.Flags().String("button", "left", "Mouse button: left, right, middle")
mouseWheelCmd.Flags().String("css", "", "CSS selector instead of ref")
- addPointFlags(mouseWheelCmd, "mousewheel")
- mouseWheelCmd.Flags().Int("wheel-delta-x", 0, "Wheel delta X")
- mouseWheelCmd.Flags().Int("wheel-delta-y", 0, "Wheel delta Y")
+ addPointFlags(mouseWheelCmd, bridge.ActionMouseWheel)
+ mouseWheelCmd.Flags().Int("dx", 0, "Wheel delta X")
+ mouseWheelCmd.Flags().Int("dy", 0, "Wheel delta Y")
+
+ dragCmd.Flags().String("button", "left", "Mouse button: left, right, middle")
focusCmd.Flags().String("css", "", "CSS selector instead of ref")
@@ -201,6 +208,7 @@ func configureBrowserFlags() {
mouseDownCmd,
mouseUpCmd,
mouseWheelCmd,
+ dragCmd,
focusCmd,
typeCmd,
pressCmd,
diff --git a/cmd/pinchtab/cmd_cli_test.go b/cmd/pinchtab/cmd_cli_test.go
index 9b9775e7..b0655d31 100644
--- a/cmd/pinchtab/cmd_cli_test.go
+++ b/cmd/pinchtab/cmd_cli_test.go
@@ -58,3 +58,9 @@ func TestMouseSubCommandsRegistered(t *testing.T) {
}
}
}
+
+func TestDragCommandRegistered(t *testing.T) {
+ if findCommand(rootCmd, "drag") == nil {
+ t.Fatal("expected drag command to be registered")
+ }
+}
diff --git a/docs/commands.md b/docs/commands.md
index 3201e51b..d570415a 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -73,10 +73,12 @@ pinchtab type <selector> <text> # Type via key events
pinchtab fill <selector> <text> # Fill directly
pinchtab press <key> # Press a key
pinchtab hover [selector] # Hover an element
-pinchtab mouse move [selector] # Move the mouse to an element or coordinates
+pinchtab mouse move <x> <y> # Move the mouse to coordinates
+pinchtab mouse move [selector] # Or move to an element center
pinchtab mouse down [selector] # Press a mouse button
pinchtab mouse up [selector] # Release a mouse button
-pinchtab mouse wheel [selector] # Dispatch wheel deltas
+pinchtab mouse wheel [dy|selector] # Dispatch wheel deltas
+pinchtab drag <from> <to> # Drag between targets (selector/ref or x,y)
pinchtab focus [selector] # Focus an element
pinchtab scroll <selector|pixels> # Scroll an element or the page
pinchtab select <selector> <value> # Select a <select> option
@@ -89,10 +91,11 @@ Low-level mouse commands are useful for drag handles, canvas-like UIs, and flows
```bash
pinchtab mouse move e5
-pinchtab mouse down e5 --button left
-pinchtab mouse up e5 --button left
-pinchtab mouse wheel e5 --wheel-delta-y 240
+pinchtab mouse down --button left
+pinchtab mouse up --button left
+pinchtab mouse wheel 240 --dx 40
pinchtab mouse move --x 400 --y 320
+pinchtab drag e5 400,320
```
## Page Analysis
diff --git a/docs/endpoints.md b/docs/endpoints.md
index 533980fd..b59f5eae 100644
--- a/docs/endpoints.md
+++ b/docs/endpoints.md
@@ -148,10 +148,10 @@ Action kinds currently include:
- `fill`
- `press`
- `hover`
-- `mousemove`
-- `mousedown`
-- `mouseup`
-- `mousewheel`
+- `mouse-move`
+- `mouse-down`
+- `mouse-up`
+- `mouse-wheel`
- `focus`
- `select`
- `scroll`
@@ -171,7 +171,7 @@ Action targeting fields:
- `nodeId`
- `x` and `y`
- `button`
-- `wheelDeltaX` and `wheelDeltaY`
+- `deltaX` and `deltaY`
- `waitNav`
- `dialogAction` and `dialogText`
diff --git a/docs/reference/cli.md b/docs/reference/cli.md
index 5568529f..6ff738fd 100644
--- a/docs/reference/cli.md
+++ b/docs/reference/cli.md
@@ -92,10 +92,11 @@ Common commands:
| `pinchtab quick <url>` | Navigate and snapshot |
| `pinchtab snap` | Accessibility snapshot |
| `pinchtab click <selector>` | Click an element |
-| `pinchtab mouse move <selector>` | Move the pointer to an element or coordinates |
-| `pinchtab mouse down <selector>` | Press a mouse button |
-| `pinchtab mouse up <selector>` | Release a mouse button |
-| `pinchtab mouse wheel <selector>` | Dispatch wheel deltas at an element or coordinates |
+| `pinchtab mouse move <x> <y>` | Move the pointer to coordinates |
+| `pinchtab mouse down [selector]` | Press a mouse button at the current pointer or a fresh target |
+| `pinchtab mouse up [selector]` | Release a mouse button at the current pointer or a fresh target |
+| `pinchtab mouse wheel [dy\|selector]` | Dispatch wheel deltas at the current pointer or a fresh target |
+| `pinchtab drag <from> <to>` | Drag from one target to another |
| `pinchtab type <selector> <text>` | Type via key events |
| `pinchtab fill <selector> <text>` | Fill directly |
| `pinchtab text` | Extract page text |
diff --git a/docs/reference/mouse.md b/docs/reference/mouse.md
index f5622123..c11daf36 100644
--- a/docs/reference/mouse.md
+++ b/docs/reference/mouse.md
@@ -1,40 +1,135 @@
# Mouse
-Low-level pointer controls for cases where DOM-native click or hover behavior is not enough.
+Low-level pointer controls for drag handles, canvas-like UIs, hover-driven menus, and flows where DOM-native `click` or `hover` are not enough.
+
+## CLI
```bash
+pinchtab mouse move <x> <y>
+pinchtab mouse move <selector>
+
+pinchtab mouse down [selector] --button left
+pinchtab mouse up [selector] --button left
+
+pinchtab mouse wheel <dy> [--dx <n>]
+pinchtab mouse wheel [selector]
+
+pinchtab drag <from> <to>
+```
+
+Examples:
+
+```bash
+# Move to an element, then use current-pointer semantics
+pinchtab mouse move e5
+pinchtab mouse down --button left
+pinchtab mouse move 400 320
+pinchtab mouse up --button left
+
+# Explicitly target down/up at an element
+pinchtab mouse down e5 --button left
+pinchtab mouse up e5 --button left
+
+# Wheel at current pointer
+pinchtab mouse wheel 240 --dx 40
+
+# Wheel at a fresh target
+pinchtab mouse wheel e5
+
+# Drag from an element to coordinates
+pinchtab drag e5 400,320
+```
+
+Notes:
+
+- `mouse move` accepts either coordinates or a unified selector.
+- `mouse down` and `mouse up` accept an optional selector. Without one, they use the current pointer position.
+- `mouse wheel` accepts either a delta form (`<dy> [--dx <n>]`) or an optional selector. Without a selector, it uses the current pointer position.
+- `drag <from> <to>` accepts selector/ref targets or `x,y` coordinate pairs.
+- `button` supports `left`, `right`, and `middle`.
+
+## HTTP API
+
+Canonical action kinds:
+
+- `mouse-move`
+- `mouse-down`
+- `mouse-up`
+- `mouse-wheel`
+- `drag`
+
+Targeting fields:
+
+- `ref`
+- `selector`
+- `nodeId`
+- `x` and `y`
+
+Wheel fields:
+
+- `deltaX`
+- `deltaY`
+
+Examples:
+
+```bash
+# Move to an element
curl -X POST http://localhost:9867/action \
-H "Content-Type: application/json" \
- -d '{"kind":"mousemove","ref":"e5"}'
+ -d '{"kind":"mouse-move","ref":"e5"}'
+# Move to coordinates
curl -X POST http://localhost:9867/action \
-H "Content-Type: application/json" \
- -d '{"kind":"mousedown","ref":"e5","button":"left"}'
+ -d '{"kind":"mouse-move","x":120,"y":220}'
+# Press/release at current pointer
curl -X POST http://localhost:9867/action \
-H "Content-Type: application/json" \
- -d '{"kind":"mouseup","ref":"e5","button":"left"}'
+ -d '{"kind":"mouse-down","button":"left"}'
curl -X POST http://localhost:9867/action \
-H "Content-Type: application/json" \
- -d '{"kind":"mousewheel","x":400,"y":320,"wheelDeltaY":240}'
+ -d '{"kind":"mouse-up","button":"left"}'
-# CLI Alternatives
-pinchtab mouse move e5
-pinchtab mouse down e5 --button left
-pinchtab mouse up e5 --button left
-pinchtab mouse wheel --x 400 --y 320 --wheel-delta-y 240
+# Press/release at an explicit target
+curl -X POST http://localhost:9867/action \
+ -H "Content-Type: application/json" \
+ -d '{"kind":"mouse-down","ref":"e5","button":"left"}'
+
+curl -X POST http://localhost:9867/action \
+ -H "Content-Type: application/json" \
+ -d '{"kind":"mouse-up","ref":"e5","button":"left"}'
+
+# Wheel at current pointer
+curl -X POST http://localhost:9867/action \
+ -H "Content-Type: application/json" \
+ -d '{"kind":"mouse-wheel","deltaY":240,"deltaX":40}'
+
+# Wheel at explicit coordinates
+curl -X POST http://localhost:9867/action \
+ -H "Content-Type: application/json" \
+ -d '{"kind":"mouse-wheel","x":400,"y":320,"deltaY":240}'
```
-Notes:
+Tab-scoped example:
+
+```bash
+curl -X POST http://localhost:9867/tabs/<tabId>/action \
+ -H "Content-Type: application/json" \
+ -d '{"kind":"mouse-move","ref":"e5"}'
+```
+
+## Behavior
-- mouse actions accept the same targeting modes as other action commands: `ref`, `selector`, `nodeId`, or `x`/`y`
-- `mousedown` and `mouseup` accept `button=left|right|middle`
-- `mousewheel` accepts `wheelDeltaX` and `wheelDeltaY`
-- use these for drag handles, canvas controls, precise hover choreography, or sites that require exact pointer sequencing
+- POST coordinate bodies work with plain `x` and `y`; no extra `hasXY` flag is required.
+- `mouse-down`, `mouse-up`, and `mouse-wheel` use per-tab current-pointer state when you omit a fresh target.
+- If no current pointer position is known yet, `mouse-down`, `mouse-up`, and `mouse-wheel` fail with a clear error. Use `mouse-move` first or pass an explicit target.
+- `mouse-wheel` defaults to vertical scrolling when only `deltaY` is provided.
## Related Pages
- [Click](./click.md)
- [Hover](./hover.md)
- [Scroll](./scroll.md)
+- [CLI](./cli.md)
diff --git a/docs/reference/tabs.md b/docs/reference/tabs.md
index e0519ccf..bae65a53 100644
--- a/docs/reference/tabs.md
+++ b/docs/reference/tabs.md
@@ -168,20 +168,20 @@ Low-level pointer control uses the same action surface:
```bash
curl -X POST http://localhost:9867/tabs/<tabId>/action \
-H "Content-Type: application/json" \
- -d '{"kind":"mousemove","ref":"e5"}'
+ -d '{"kind":"mouse-move","ref":"e5"}'
curl -X POST http://localhost:9867/tabs/<tabId>/action \
-H "Content-Type: application/json" \
- -d '{"kind":"mousedown","ref":"e5","button":"left"}'
+ -d '{"kind":"mouse-down","button":"left"}'
curl -X POST http://localhost:9867/tabs/<tabId>/action \
-H "Content-Type: application/json" \
- -d '{"kind":"mousewheel","x":400,"y":320,"wheelDeltaY":240}'
+ -d '{"kind":"mouse-wheel","x":400,"y":320,"deltaY":240}'
# CLI Alternatives
pinchtab mouse move --tab <tabId> e5
-pinchtab mouse down --tab <tabId> e5 --button left
-pinchtab mouse wheel --tab <tabId> --x 400 --y 320 --wheel-delta-y 240
+pinchtab mouse down --tab <tabId> --button left
+pinchtab mouse wheel --tab <tabId> 240 --dx 40
```
### Handoff State
diff --git a/internal/bridge/action_pointer.go b/internal/bridge/action_pointer.go
index 540b3058..04d7b1be 100644
--- a/internal/bridge/action_pointer.go
+++ b/internal/bridge/action_pointer.go
@@ -4,12 +4,23 @@ import (
"context"
"fmt"
"log/slog"
+ "strings"
"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/chromedp"
)
var scrollByCoordinateAction = ScrollByCoordinate
+var mouseMoveByCoordinateAction = MouseMoveByCoordinate
+var mouseDownByCoordinateAction = MouseDownByCoordinate
+var mouseUpByCoordinateAction = MouseUpByCoordinate
+
+type pointerState struct {
+ X float64
+ Y float64
+ Known bool
+}
+
var scrollViewportCenter = func(ctx context.Context) (float64, float64, error) {
var viewport struct {
X float64 `json:"x"`
@@ -149,7 +160,36 @@ func (b *Bridge) actionHover(ctx context.Context, req ActionRequest) (map[string
return nil, fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
}
-func pointerCoordinatesFromRequest(ctx context.Context, req ActionRequest) (float64, float64, error) {
+func (b *Bridge) rememberPointerPosition(tabID string, x, y float64) {
+ if b == nil || tabID == "" {
+ return
+ }
+ b.pointerMu.Lock()
+ b.pointerByTab[tabID] = pointerState{X: x, Y: y, Known: true}
+ b.pointerMu.Unlock()
+}
+
+func (b *Bridge) currentPointerPosition(tabID string) (float64, float64, bool) {
+ if b == nil || tabID == "" {
+ return 0, 0, false
+ }
+ b.pointerMu.RLock()
+ defer b.pointerMu.RUnlock()
+ state, ok := b.pointerByTab[tabID]
+ if !ok || !state.Known {
+ return 0, 0, false
+ }
+ return state.X, state.Y, true
+}
+
+func pointerTargetRequiredError(req ActionRequest, allowCurrent bool) error {
+ if allowCurrent && strings.TrimSpace(req.TabID) != "" {
+ return fmt.Errorf("no pointer position known for tab %s; move pointer first or provide selector, ref, nodeId, or x/y coordinates", req.TabID)
+ }
+ return fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
+}
+
+func (b *Bridge) pointerCoordinatesFromRequest(ctx context.Context, req ActionRequest, allowCurrent bool) (float64, float64, error) {
if req.HasXY {
return req.X, req.Y, nil
}
@@ -163,22 +203,28 @@ func pointerCoordinatesFromRequest(ctx context.Context, req ActionRequest) (floa
}
return PointerPointForNode(ctx, int64(node.BackendNodeID), false)
}
- return 0, 0, fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
+ if allowCurrent {
+ if x, y, ok := b.currentPointerPosition(req.TabID); ok {
+ return x, y, nil
+ }
+ }
+ return 0, 0, pointerTargetRequiredError(req, allowCurrent)
}
func (b *Bridge) actionMouseMove(ctx context.Context, req ActionRequest) (map[string]any, error) {
- x, y, err := pointerCoordinatesFromRequest(ctx, req)
+ x, y, err := b.pointerCoordinatesFromRequest(ctx, req, false)
if err != nil {
return nil, err
}
- if err := MouseMoveByCoordinate(ctx, x, y); err != nil {
+ if err := mouseMoveByCoordinateAction(ctx, x, y); err != nil {
return nil, err
}
+ b.rememberPointerPosition(req.TabID, x, y)
return map[string]any{"moved": true, "x": x, "y": y}, nil
}
func (b *Bridge) actionMouseDown(ctx context.Context, req ActionRequest) (map[string]any, error) {
- x, y, err := pointerCoordinatesFromRequest(ctx, req)
+ x, y, err := b.pointerCoordinatesFromRequest(ctx, req, true)
if err != nil {
return nil, err
}
@@ -186,14 +232,15 @@ func (b *Bridge) actionMouseDown(ctx context.Context, req ActionRequest) (map[st
if button == "" {
button = "left"
}
- if err := MouseDownByCoordinate(ctx, x, y, button); err != nil {
+ if err := mouseDownByCoordinateAction(ctx, x, y, button); err != nil {
return nil, err
}
+ b.rememberPointerPosition(req.TabID, x, y)
return map[string]any{"down": true, "x": x, "y": y, "button": button}, nil
}
func (b *Bridge) actionMouseUp(ctx context.Context, req ActionRequest) (map[string]any, error) {
- x, y, err := pointerCoordinatesFromRequest(ctx, req)
+ x, y, err := b.pointerCoordinatesFromRequest(ctx, req, true)
if err != nil {
return nil, err
}
@@ -201,19 +248,20 @@ func (b *Bridge) actionMouseUp(ctx context.Context, req ActionRequest) (map[stri
if button == "" {
button = "left"
}
- if err := MouseUpByCoordinate(ctx, x, y, button); err != nil {
+ if err := mouseUpByCoordinateAction(ctx, x, y, button); err != nil {
return nil, err
}
+ b.rememberPointerPosition(req.TabID, x, y)
return map[string]any{"up": true, "x": x, "y": y, "button": button}, nil
}
func (b *Bridge) actionMouseWheel(ctx context.Context, req ActionRequest) (map[string]any, error) {
- x, y, err := pointerCoordinatesFromRequest(ctx, req)
+ x, y, err := b.pointerCoordinatesFromRequest(ctx, req, true)
if err != nil {
return nil, err
}
- deltaX := req.WheelDeltaX
- deltaY := req.WheelDeltaY
+ deltaX := req.DeltaX
+ deltaY := req.DeltaY
if deltaX == 0 && deltaY == 0 {
deltaX = req.ScrollX
deltaY = req.ScrollY
@@ -224,6 +272,7 @@ func (b *Bridge) actionMouseWheel(ctx context.Context, req ActionRequest) (map[s
if err := scrollByCoordinateAction(ctx, x, y, deltaX, deltaY); err != nil {
return nil, err
}
+ b.rememberPointerPosition(req.TabID, x, y)
return map[string]any{"wheel": true, "x": x, "y": y, "deltaX": deltaX, "deltaY": deltaY}, nil
}
diff --git a/internal/bridge/action_registry.go b/internal/bridge/action_registry.go
index bae656c1..ed4d48b3 100644
--- a/internal/bridge/action_registry.go
+++ b/internal/bridge/action_registry.go
@@ -10,10 +10,10 @@ const (
ActionHover = "hover"
ActionSelect = "select"
ActionScroll = "scroll"
- ActionMouseMove = "mousemove"
- ActionMouseDown = "mousedown"
- ActionMouseUp = "mouseup"
- ActionMouseWheel = "mousewheel"
+ ActionMouseMove = "mouse-move"
+ ActionMouseDown = "mouse-down"
+ ActionMouseUp = "mouse-up"
+ ActionMouseWheel = "mouse-wheel"
ActionDrag = "drag"
ActionHumanClick = "humanClick"
ActionHumanType = "humanType"
diff --git a/internal/bridge/actions_test.go b/internal/bridge/actions_test.go
index e606b9e8..5a67b230 100644
--- a/internal/bridge/actions_test.go
+++ b/internal/bridge/actions_test.go
@@ -2,6 +2,7 @@ package bridge
import (
"context"
+ "encoding/json"
"strings"
"testing"
@@ -138,11 +139,11 @@ func TestMouseWheelAction_UsesExplicitWheelDeltas(t *testing.T) {
}
res, err := b.Actions[ActionMouseWheel](context.Background(), ActionRequest{
- HasXY: true,
- X: 50,
- Y: 75,
- WheelDeltaX: 123,
- WheelDeltaY: -456,
+ HasXY: true,
+ X: 50,
+ Y: 75,
+ DeltaX: 123,
+ DeltaY: -456,
})
if err != nil {
t.Fatalf("mouse wheel returned error: %v", err)
@@ -155,6 +156,107 @@ func TestMouseWheelAction_UsesExplicitWheelDeltas(t *testing.T) {
}
}
+func TestMouseActions_TrackCurrentPointerPosition(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+
+ origMove := mouseMoveByCoordinateAction
+ origUp := mouseUpByCoordinateAction
+ t.Cleanup(func() {
+ mouseMoveByCoordinateAction = origMove
+ mouseUpByCoordinateAction = origUp
+ })
+
+ moveCalled := false
+ upCalled := false
+ mouseMoveByCoordinateAction = func(ctx context.Context, x, y float64) error {
+ moveCalled = true
+ if x != 15 || y != 25 {
+ t.Fatalf("move coordinates = (%v, %v), want (15, 25)", x, y)
+ }
+ return nil
+ }
+ mouseUpByCoordinateAction = func(ctx context.Context, x, y float64, button string) error {
+ upCalled = true
+ if x != 15 || y != 25 {
+ t.Fatalf("up coordinates = (%v, %v), want (15, 25)", x, y)
+ }
+ if button != "left" {
+ t.Fatalf("button = %q, want left", button)
+ }
+ return nil
+ }
+
+ if _, err := b.Actions[ActionMouseMove](context.Background(), ActionRequest{
+ TabID: "tab1",
+ HasXY: true,
+ X: 15,
+ Y: 25,
+ }); err != nil {
+ t.Fatalf("mouse move returned error: %v", err)
+ }
+ if _, err := b.Actions[ActionMouseUp](context.Background(), ActionRequest{TabID: "tab1"}); err != nil {
+ t.Fatalf("mouse up returned error: %v", err)
+ }
+ if !moveCalled || !upCalled {
+ t.Fatalf("expected move and up actions to be called, got move=%v up=%v", moveCalled, upCalled)
+ }
+}
+
+func TestMouseDownAction_UsesTrackedPointerWhenTargetMissing(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+ b.rememberPointerPosition("tab-current", 33, 44)
+
+ origDown := mouseDownByCoordinateAction
+ t.Cleanup(func() {
+ mouseDownByCoordinateAction = origDown
+ })
+
+ mouseDownByCoordinateAction = func(ctx context.Context, x, y float64, button string) error {
+ if x != 33 || y != 44 {
+ t.Fatalf("down coordinates = (%v, %v), want (33, 44)", x, y)
+ }
+ if button != "right" {
+ t.Fatalf("button = %q, want right", button)
+ }
+ return nil
+ }
+
+ if _, err := b.Actions[ActionMouseDown](context.Background(), ActionRequest{
+ TabID: "tab-current",
+ Button: "right",
+ }); err != nil {
+ t.Fatalf("mouse down returned error: %v", err)
+ }
+}
+
+func TestMouseWheelAction_RequiresKnownPointerWhenTargetMissing(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+
+ _, err := b.Actions[ActionMouseWheel](context.Background(), ActionRequest{TabID: "tab-missing"})
+ if err == nil {
+ t.Fatal("expected missing pointer error")
+ }
+ if !strings.Contains(err.Error(), "move pointer first") {
+ t.Fatalf("unexpected error: %v", err)
+ }
+}
+
+func TestActionRequestUnmarshal_UsesCanonicalMouseFields(t *testing.T) {
+ var req ActionRequest
+ if err := json.Unmarshal([]byte(`{"kind":"mouse-wheel","x":0,"y":0,"deltaX":12,"deltaY":-34}`), &req); err != nil {
+ t.Fatalf("unmarshal action request: %v", err)
+ }
+ if req.Kind != ActionMouseWheel {
+ t.Fatalf("kind = %q, want %q", req.Kind, ActionMouseWheel)
+ }
+ if !req.HasXY {
+ t.Fatal("expected HasXY=true when x/y keys are present")
+ }
+ if req.DeltaX != 12 || req.DeltaY != -34 {
+ t.Fatalf("wheel deltas = (%d, %d), want (12, -34)", req.DeltaX, req.DeltaY)
+ }
+}
+
func TestScrollAction_UsesCoordinateWheelPath(t *testing.T) {
b := New(context.TODO(), nil, &config.RuntimeConfig{})
diff --git a/internal/bridge/bridge.go b/internal/bridge/bridge.go
index 3f03a1b9..b39106e3 100644
--- a/internal/bridge/bridge.go
+++ b/internal/bridge/bridge.go
@@ -3,6 +3,7 @@ package bridge
import (
"context"
"crypto/rand"
+ "encoding/json"
"fmt"
"log/slog"
"math/big"
@@ -57,6 +58,8 @@ type Bridge struct {
workerStealthTargets sync.Map
handoffMu sync.RWMutex
handoffs map[string]TabHandoffState
+ pointerMu sync.RWMutex
+ pointerByTab map[string]pointerState
// Lazy initialization / restart coordination
initMu sync.Mutex
@@ -86,6 +89,7 @@ func New(allocCtx, browserCtx context.Context, cfg *config.RuntimeConfig) *Bridg
netMonitor: NewNetworkMonitor(netBufSize),
fingerprintOverlays: make(map[string]bool),
handoffs: make(map[string]TabHandoffState),
+ pointerByTab: make(map[string]pointerState),
LogStore: logStore,
stealthLaunchMode: stealth.LaunchModeUninitialized,
}
@@ -529,6 +533,8 @@ func (b *Bridge) BrowserContext() context.Context {
}
func (b *Bridge) ExecuteAction(ctx context.Context, kind string, req ActionRequest) (map[string]any, error) {
+ kind = CanonicalActionKind(kind)
+ req.Kind = CanonicalActionKind(req.Kind)
fn, ok := b.Actions[kind]
if !ok {
return nil, fmt.Errorf("unknown action: %s", kind)
@@ -626,12 +632,12 @@ type ActionRequest struct {
ScrollX int `json:"scrollX"`
ScrollY int `json:"scrollY"`
- // WheelDeltaX/WheelDeltaY are explicit mouse-wheel deltas for low-level
- // mousewheel actions. ScrollX/ScrollY remain for backward compatibility.
- WheelDeltaX int `json:"wheelDeltaX,omitempty"`
- WheelDeltaY int `json:"wheelDeltaY,omitempty"`
- DragX int `json:"dragX"`
- DragY int `json:"dragY"`
+ // DeltaX/DeltaY are explicit mouse-wheel deltas for low-level
+ // mouse-wheel actions. ScrollX/ScrollY remain for backward compatibility.
+ DeltaX int `json:"deltaX,omitempty"`
+ DeltaY int `json:"deltaY,omitempty"`
+ DragX int `json:"dragX"`
+ DragY int `json:"dragY"`
WaitNav bool `json:"waitNav"`
Fast bool `json:"fast"`
@@ -647,6 +653,34 @@ type ActionRequest struct {
DialogText string `json:"dialogText,omitempty"`
}
+type actionRequestAlias ActionRequest
+
+func (r *ActionRequest) UnmarshalJSON(data []byte) error {
+ var alias actionRequestAlias
+ if err := json.Unmarshal(data, &alias); err != nil {
+ return err
+ }
+ raw := map[string]json.RawMessage{}
+ if err := json.Unmarshal(data, &raw); err != nil {
+ return err
+ }
+
+ *r = ActionRequest(alias)
+ r.Kind = CanonicalActionKind(r.Kind)
+ r.HasXY = r.HasXY || hasJSONKey(raw, "x") || hasJSONKey(raw, "y")
+ if hasJSONKey(raw, "deltaX") {
+ if err := json.Unmarshal(raw["deltaX"], &r.DeltaX); err != nil {
+ return err
+ }
+ }
+ if hasJSONKey(raw, "deltaY") {
+ if err := json.Unmarshal(raw["deltaY"], &r.DeltaY); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
// NormalizeSelector merges legacy Ref and Selector (CSS) fields into the
// unified Selector field. After calling this, only Selector needs to be
// inspected for element targeting. The method is idempotent.
@@ -661,6 +695,15 @@ func (r *ActionRequest) NormalizeSelector() {
// leave it as-is — Parse() will auto-detect the kind.
}
+func CanonicalActionKind(kind string) string {
+ return kind
+}
+
+func hasJSONKey(raw map[string]json.RawMessage, key string) bool {
+ _, ok := raw[key]
+ return ok
+}
+
func cryptoRandSeed() int64 {
n, err := rand.Int(rand.Reader, big.NewInt(1000000000))
if err != nil {
diff --git a/internal/cli/actions/actions_element.go b/internal/cli/actions/actions_element.go
index 87f5c190..d93bdbd0 100644
--- a/internal/cli/actions/actions_element.go
+++ b/internal/cli/actions/actions_element.go
@@ -2,13 +2,15 @@ package actions
import (
"fmt"
+ "net/http"
+ "strconv"
+ "strings"
+
+ "github.com/pinchtab/pinchtab/internal/bridge"
"github.com/pinchtab/pinchtab/internal/cli"
"github.com/pinchtab/pinchtab/internal/cli/apiclient"
"github.com/pinchtab/pinchtab/internal/selector"
"github.com/spf13/cobra"
- "net/http"
- "strconv"
- "strings"
)
func Action(client *http.Client, base, token, kind, selectorArg string, cmd *cobra.Command) {
@@ -23,23 +25,11 @@ func Action(client *http.Client, base, token, kind, selectorArg string, cmd *cob
if hasXY {
body["x"] = x
body["y"] = y
- body["hasXY"] = true
}
if button, _ := cmd.Flags().GetString("button"); button != "" {
body["button"] = button
}
- if cmd.Flags().Changed("wheel-delta-x") {
- if deltaX, err := cmd.Flags().GetInt("wheel-delta-x"); err == nil {
- body["wheelDeltaX"] = deltaX
- }
- }
- if cmd.Flags().Changed("wheel-delta-y") {
- if deltaY, err := cmd.Flags().GetInt("wheel-delta-y"); err == nil {
- body["wheelDeltaY"] = deltaY
- }
- }
-
if css != "" {
// Explicit --css flag: send as plain CSS selector
body["selector"] = css
@@ -56,12 +46,7 @@ func Action(client *http.Client, base, token, kind, selectorArg string, cmd *cob
}
}
- tabID, _ := cmd.Flags().GetString("tab")
- path := "/action"
- if tabID != "" {
- path = fmt.Sprintf("/tabs/%s/action", tabID)
- }
- apiclient.DoPost(client, base, token, path, body)
+ postAction(client, base, token, cmd, body)
}
// setSelectorBody parses a unified selector string and sets the appropriate
@@ -77,6 +62,184 @@ func setSelectorBody(body map[string]any, s string) {
}
}
+func postAction(client *http.Client, base, token string, cmd *cobra.Command, body map[string]any) {
+ postActionWithHeaders(client, base, token, cmd, body, nil)
+}
+
+func postActionWithHeaders(client *http.Client, base, token string, cmd *cobra.Command, body map[string]any, headers map[string]string) {
+ tabID, _ := cmd.Flags().GetString("tab")
+ path := "/action"
+ if tabID != "" {
+ path = fmt.Sprintf("/tabs/%s/action", tabID)
+ }
+ apiclient.DoPostWithHeaders(client, base, token, path, body, headers)
+}
+
+func setPointBody(body map[string]any, x, y float64) {
+ body["x"] = x
+ body["y"] = y
+}
+
+func readWheelDelta(cmd *cobra.Command, primary string) (int, bool) {
+ if cmd.Flags().Changed(primary) {
+ if value, err := cmd.Flags().GetInt(primary); err == nil {
+ return value, true
+ }
+ }
+ return 0, false
+}
+
+func parseCoordinateArgs(xArg, yArg string) (float64, float64, error) {
+ x, err := strconv.ParseFloat(xArg, 64)
+ if err != nil {
+ return 0, 0, err
+ }
+ y, err := strconv.ParseFloat(yArg, 64)
+ if err != nil {
+ return 0, 0, err
+ }
+ return x, y, nil
+}
+
+func applyMouseTarget(body map[string]any, selectorArg string, cmd *cobra.Command) bool {
+ css, _ := cmd.Flags().GetString("css")
+ hasX := cmd.Flags().Changed("x")
+ hasY := cmd.Flags().Changed("y")
+ if hasX || hasY {
+ x, _ := cmd.Flags().GetFloat64("x")
+ y, _ := cmd.Flags().GetFloat64("y")
+ setPointBody(body, x, y)
+ return true
+ }
+ if css != "" {
+ body["selector"] = css
+ return true
+ }
+ if selectorArg != "" {
+ setSelectorBody(body, selectorArg)
+ return true
+ }
+ return false
+}
+
+func MouseAction(client *http.Client, base, token, kind string, args []string, cmd *cobra.Command) {
+ body := map[string]any{"kind": kind}
+
+ if button, _ := cmd.Flags().GetString("button"); button != "" {
+ body["button"] = button
+ }
+
+ switch kind {
+ case bridge.ActionMouseMove:
+ if len(args) == 2 {
+ if cmd.Flags().Changed("x") || cmd.Flags().Changed("y") || cmd.Flags().Changed("css") {
+ cli.Fatal("Usage: pinchtab mouse move <x> <y> or pinchtab mouse move <selector> or pinchtab mouse move --x <num> --y <num>")
+ }
+ x, y, err := parseCoordinateArgs(args[0], args[1])
+ if err != nil {
+ cli.Fatal("Usage: pinchtab mouse move <x> <y>")
+ }
+ setPointBody(body, x, y)
+ } else if len(args) == 1 {
+ if cmd.Flags().Changed("x") || cmd.Flags().Changed("y") || cmd.Flags().Changed("css") {
+ cli.Fatal("Usage: pinchtab mouse move <x> <y> or pinchtab mouse move <selector> or pinchtab mouse move --x <num> --y <num>")
+ }
+ setSelectorBody(body, args[0])
+ } else if !applyMouseTarget(body, "", cmd) {
+ cli.Fatal("Usage: pinchtab mouse move <x> <y> or pinchtab mouse move <selector> or pinchtab mouse move --x <num> --y <num>")
+ }
+ case bridge.ActionMouseDown, bridge.ActionMouseUp:
+ if len(args) > 1 {
+ cli.Fatal("Usage: pinchtab mouse %s [selector]", strings.TrimPrefix(kind, "mouse-"))
+ }
+ _ = applyMouseTarget(body, optionalMouseArg(args), cmd)
+ case bridge.ActionMouseWheel:
+ if len(args) > 1 {
+ cli.Fatal("Usage: pinchtab mouse wheel <dy> [--dx <n>] or pinchtab mouse wheel [selector]")
+ }
+ if len(args) == 1 {
+ if dy, err := strconv.Atoi(args[0]); err == nil {
+ body["deltaY"] = dy
+ } else {
+ setSelectorBody(body, args[0])
+ }
+ }
+ if deltaX, ok := readWheelDelta(cmd, "dx"); ok {
+ body["deltaX"] = deltaX
+ }
+ if deltaY, ok := readWheelDelta(cmd, "dy"); ok {
+ if _, fromArg := body["deltaY"]; fromArg {
+ cli.Fatal("Usage: pinchtab mouse wheel <dy> [--dx <n>] or pinchtab mouse wheel [selector]")
+ }
+ body["deltaY"] = deltaY
+ }
+ if _, hasTarget := body["selector"]; !hasTarget {
+ if _, hasRef := body["ref"]; !hasRef {
+ _ = applyMouseTarget(body, "", cmd)
+ }
+ } else if cmd.Flags().Changed("x") || cmd.Flags().Changed("y") || cmd.Flags().Changed("css") {
+ cli.Fatal("Usage: pinchtab mouse wheel <dy> [--dx <n>] or pinchtab mouse wheel [selector]")
+ }
+ default:
+ cli.Fatal("unsupported mouse action: %s", kind)
+ }
+
+ postAction(client, base, token, cmd, body)
+}
+
+type dragTarget struct {
+ selector string
+ x float64
+ y float64
+ hasXY bool
+}
+
+func optionalMouseArg(args []string) string {
+ if len(args) == 0 {
+ return ""
+ }
+ return args[0]
+}
+
+func parseDragTarget(raw string) dragTarget {
+ parts := strings.Split(raw, ",")
+ if len(parts) == 2 {
+ x, errX := strconv.ParseFloat(strings.TrimSpace(parts[0]), 64)
+ y, errY := strconv.ParseFloat(strings.TrimSpace(parts[1]), 64)
+ if errX == nil && errY == nil {
+ return dragTarget{x: x, y: y, hasXY: true}
+ }
+ }
+ return dragTarget{selector: raw}
+}
+
+func actionBodyForTarget(kind string, target dragTarget) map[string]any {
+ body := map[string]any{"kind": kind}
+ if target.hasXY {
+ setPointBody(body, target.x, target.y)
+ return body
+ }
+ setSelectorBody(body, target.selector)
+ return body
+}
+
+func Drag(client *http.Client, base, token string, args []string, cmd *cobra.Command) {
+ from := parseDragTarget(args[0])
+ to := parseDragTarget(args[1])
+
+ mouseDown := map[string]any{"kind": bridge.ActionMouseDown}
+ mouseUp := map[string]any{"kind": bridge.ActionMouseUp}
+ if button, _ := cmd.Flags().GetString("button"); button != "" {
+ mouseDown["button"] = button
+ mouseUp["button"] = button
+ }
+
+ postAction(client, base, token, cmd, actionBodyForTarget(bridge.ActionMouseMove, from))
+ postAction(client, base, token, cmd, mouseDown)
+ postAction(client, base, token, cmd, actionBodyForTarget(bridge.ActionMouseMove, to))
+ postAction(client, base, token, cmd, mouseUp)
+}
+
func ActionSimple(client *http.Client, base, token, kind string, args []string, cmd *cobra.Command) {
body := map[string]any{"kind": kind}
@@ -124,10 +287,5 @@ func ActionSimple(client *http.Client, base, token, kind string, args []string,
body["key"] = args[0]
}
- tabID, _ := cmd.Flags().GetString("tab")
- path := "/action"
- if tabID != "" {
- path = fmt.Sprintf("/tabs/%s/action", tabID)
- }
- apiclient.DoPost(client, base, token, path, body)
+ postAction(client, base, token, cmd, body)
}
diff --git a/internal/cli/actions/actions_element_test.go b/internal/cli/actions/actions_element_test.go
index 87b0d2bc..1e8a8e3a 100644
--- a/internal/cli/actions/actions_element_test.go
+++ b/internal/cli/actions/actions_element_test.go
@@ -15,8 +15,8 @@ func newActionCmd() *cobra.Command {
cmd.Flags().Float64("x", 0, "")
cmd.Flags().Float64("y", 0, "")
cmd.Flags().String("button", "", "")
- cmd.Flags().Int("wheel-delta-x", 0, "")
- cmd.Flags().Int("wheel-delta-y", 0, "")
+ cmd.Flags().Int("dx", 0, "")
+ cmd.Flags().Int("dy", 0, "")
return cmd
}
@@ -142,18 +142,18 @@ func TestMouseDownIncludesButton(t *testing.T) {
_ = cmd.Flags().Set("x", "25")
_ = cmd.Flags().Set("y", "40")
- Action(client, m.base(), "", "mousedown", "", cmd)
+ MouseAction(client, m.base(), "", "mouse-down", nil, cmd)
var body map[string]any
_ = json.Unmarshal([]byte(m.lastBody), &body)
- if body["kind"] != "mousedown" {
- t.Errorf("expected kind=mousedown, got %v", body["kind"])
+ if body["kind"] != "mouse-down" {
+ t.Errorf("expected kind=mouse-down, got %v", body["kind"])
}
if body["button"] != "right" {
t.Errorf("expected button=right, got %v", body["button"])
}
- if body["hasXY"] != true {
- t.Errorf("expected hasXY=true, got %v", body["hasXY"])
+ if body["x"] != float64(25) || body["y"] != float64(40) {
+ t.Errorf("expected x/y coordinates, got %v", body)
}
}
@@ -163,23 +163,92 @@ func TestMouseWheelIncludesExplicitDeltas(t *testing.T) {
client := m.server.Client()
cmd := newActionCmd()
- _ = cmd.Flags().Set("wheel-delta-x", "120")
- _ = cmd.Flags().Set("wheel-delta-y", "-300")
+ _ = cmd.Flags().Set("dx", "120")
+ _ = cmd.Flags().Set("dy", "-300")
_ = cmd.Flags().Set("x", "10")
_ = cmd.Flags().Set("y", "20")
- Action(client, m.base(), "", "mousewheel", "", cmd)
+ MouseAction(client, m.base(), "", "mouse-wheel", nil, cmd)
var body map[string]any
_ = json.Unmarshal([]byte(m.lastBody), &body)
- if body["kind"] != "mousewheel" {
- t.Errorf("expected kind=mousewheel, got %v", body["kind"])
+ if body["kind"] != "mouse-wheel" {
+ t.Errorf("expected kind=mouse-wheel, got %v", body["kind"])
}
- if body["wheelDeltaX"] != float64(120) {
- t.Errorf("expected wheelDeltaX=120, got %v", body["wheelDeltaX"])
+ if body["deltaX"] != float64(120) {
+ t.Errorf("expected deltaX=120, got %v", body["deltaX"])
}
- if body["wheelDeltaY"] != float64(-300) {
- t.Errorf("expected wheelDeltaY=-300, got %v", body["wheelDeltaY"])
+ if body["deltaY"] != float64(-300) {
+ t.Errorf("expected deltaY=-300, got %v", body["deltaY"])
+ }
+}
+
+func TestMouseMoveSupportsPositionalCoordinates(t *testing.T) {
+ m := newMockServer()
+ defer m.close()
+ client := m.server.Client()
+
+ cmd := newActionCmd()
+ MouseAction(client, m.base(), "", "mouse-move", []string{"100", "200"}, cmd)
+
+ var body map[string]any
+ _ = json.Unmarshal([]byte(m.lastBody), &body)
+ if body["kind"] != "mouse-move" {
+ t.Fatalf("expected kind=mouse-move, got %v", body["kind"])
+ }
+ if body["x"] != float64(100) || body["y"] != float64(200) {
+ t.Fatalf("expected positional coordinates, got %v", body)
+ }
+}
+
+func TestMouseWheelSupportsPositionalDeltaY(t *testing.T) {
+ m := newMockServer()
+ defer m.close()
+ client := m.server.Client()
+
+ cmd := newActionCmd()
+ _ = cmd.Flags().Set("dx", "20")
+ MouseAction(client, m.base(), "", "mouse-wheel", []string{"-120"}, cmd)
+
+ var body map[string]any
+ _ = json.Unmarshal([]byte(m.lastBody), &body)
+ if body["deltaX"] != float64(20) {
+ t.Fatalf("expected deltaX=20, got %v", body["deltaX"])
+ }
+ if body["deltaY"] != float64(-120) {
+ t.Fatalf("expected deltaY=-120, got %v", body["deltaY"])
+ }
+}
+
+func TestDragPostsMouseSequence(t *testing.T) {
+ m := newMockServer()
+ defer m.close()
+ client := m.server.Client()
+
+ cmd := newActionCmd()
+ Drag(client, m.base(), "", []string{"e5", "400,320"}, cmd)
+
+ if len(m.requests) != 4 {
+ t.Fatalf("expected 4 requests, got %d", len(m.requests))
+ }
+
+ var bodies []map[string]any
+ for _, req := range m.requests {
+ var body map[string]any
+ _ = json.Unmarshal([]byte(req.Body), &body)
+ bodies = append(bodies, body)
+ }
+ if bodies[0]["kind"] != "mouse-move" || bodies[0]["ref"] != "e5" {
+ t.Fatalf("unexpected first request: %+v", bodies[0])
+ }
+ if bodies[1]["kind"] != "mouse-down" {
+ t.Fatalf("unexpected second request: %+v", bodies[1])
+ }
+ if bodies[2]["kind"] != "mouse-move" || bodies[2]["x"] != float64(400) || bodies[2]["y"] != float64(320) {
+ t.Fatalf("unexpected third request: %+v", bodies[2])
+ }
+ if bodies[3]["kind"] != "mouse-up" {
+ t.Fatalf("unexpected fourth request: %+v", bodies[3])
}
}
diff --git a/internal/cli/actions/mock_server_test.go b/internal/cli/actions/mock_server_test.go
index 18aa1de0..8d152b68 100644
--- a/internal/cli/actions/mock_server_test.go
+++ b/internal/cli/actions/mock_server_test.go
@@ -7,6 +7,14 @@ import (
"net/http/httptest"
)
+type capturedRequest struct {
+ Method string
+ Path string
+ Query string
+ Body string
+ Headers http.Header
+}
+
type mockServer struct {
server *httptest.Server
lastMethod string
@@ -14,6 +22,7 @@ type mockServer struct {
lastQuery string
lastBody string
lastHeaders http.Header
+ requests []capturedRequest
response string
statusCode int
}
@@ -29,6 +38,13 @@ func newMockServer() *mockServer {
body, _ := io.ReadAll(r.Body)
m.lastBody = string(body)
}
+ m.requests = append(m.requests, capturedRequest{
+ Method: m.lastMethod,
+ Path: m.lastPath,
+ Query: m.lastQuery,
+ Body: m.lastBody,
+ Headers: m.lastHeaders.Clone(),
+ })
w.WriteHeader(m.statusCode)
_, _ = w.Write([]byte(m.response))
})
diff --git a/internal/cli/apiclient/client.go b/internal/cli/apiclient/client.go
index 1d44c9cd..5a0d40ad 100644
--- a/internal/cli/apiclient/client.go
+++ b/internal/cli/apiclient/client.go
@@ -70,10 +70,17 @@ func DoGetRaw(client *http.Client, base, token, path string, params url.Values)
}
func DoPost(client *http.Client, base, token, path string, body map[string]any) map[string]any {
+ return DoPostWithHeaders(client, base, token, path, body, nil)
+}
+
+func DoPostWithHeaders(client *http.Client, base, token, path string, body map[string]any, headers map[string]string) map[string]any {
data, _ := json.Marshal(body)
req, _ := http.NewRequest("POST", base+path, bytes.NewReader(data))
req.Header.Set("Content-Type", "application/json")
setClientHeaders(req, token)
+ for key, value := range headers {
+ req.Header.Set(key, value)
+ }
resp, err := client.Do(req)
if err != nil {
fatal("Request failed: %v", err)
diff --git a/internal/handlers/actions.go b/internal/handlers/actions.go
index 331da533..2a54570a 100644
--- a/internal/handlers/actions.go
+++ b/internal/handlers/actions.go
@@ -53,7 +53,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
var req bridge.ActionRequest
if r.Method == http.MethodGet {
q := r.URL.Query()
- req.Kind = q.Get("kind")
+ req.Kind = bridge.CanonicalActionKind(q.Get("kind"))
req.TabID = q.Get("tabId")
req.Owner = q.Get("owner")
req.Ref = q.Get("ref")
@@ -80,18 +80,18 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
}
if v := q.Get("hasXY"); v != "" {
if b, err := strconv.ParseBool(v); err == nil {
- req.HasXY = b
+ req.HasXY = req.HasXY || b
}
}
req.Button = q.Get("button")
- if v := q.Get("wheelDeltaX"); v != "" {
- if n, err := strconv.Atoi(v); err == nil {
- req.WheelDeltaX = n
+ if vals, ok := q["deltaX"]; ok && len(vals) > 0 {
+ if n, err := strconv.Atoi(vals[0]); err == nil {
+ req.DeltaX = n
}
}
- if v := q.Get("wheelDeltaY"); v != "" {
- if n, err := strconv.Atoi(v); err == nil {
- req.WheelDeltaY = n
+ if vals, ok := q["deltaY"]; ok && len(vals) > 0 {
+ if n, err := strconv.Atoi(vals[0]); err == nil {
+ req.DeltaY = n
}
}
} else {
@@ -99,6 +99,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
httpx.Error(w, 400, fmt.Errorf("decode: %w", err))
return
}
+ req.Kind = bridge.CanonicalActionKind(req.Kind)
}
// Validate kind — single endpoint returns 400 for bad input (unlike batch which returns 200 with errors)
@@ -1043,6 +1044,7 @@ func (h *Handlers) cacheActionIntent(tabID string, req bridge.ActionRequest) {
}
func (h *Handlers) executeAction(ctx context.Context, req bridge.ActionRequest) (map[string]any, string, error) {
+ req.Kind = bridge.CanonicalActionKind(req.Kind)
if h.shouldUseLiteAction(req.Kind) {
return h.executeLiteAction(ctx, req)
}
@@ -1055,6 +1057,7 @@ func (h *Handlers) executeAction(ctx context.Context, req bridge.ActionRequest)
}
func (h *Handlers) shouldUseLiteAction(kind string) bool {
+ kind = bridge.CanonicalActionKind(kind)
capability, ok := actionCapability(kind)
if !ok {
return h.Router != nil && h.Router.Mode() == engine.ModeLite
@@ -1066,7 +1069,7 @@ func (h *Handlers) executeLiteAction(ctx context.Context, req bridge.ActionReque
if h.Router == nil || h.Router.Lite() == nil {
return nil, "", fmt.Errorf("lite engine unavailable")
}
- switch strings.ToLower(strings.TrimSpace(req.Kind)) {
+ switch bridge.CanonicalActionKind(req.Kind) {
case bridge.ActionClick:
if req.Ref == "" {
return nil, "lite", fmt.Errorf("lite mode actions require ref from /snapshot")
@@ -1096,7 +1099,7 @@ func (h *Handlers) executeLiteAction(ctx context.Context, req bridge.ActionReque
}
func actionCapability(kind string) (engine.Capability, bool) {
- switch strings.ToLower(strings.TrimSpace(kind)) {
+ switch bridge.CanonicalActionKind(kind) {
case bridge.ActionClick:
return engine.CapClick, true
case bridge.ActionType, bridge.ActionFill:
diff --git a/internal/handlers/actions_test.go b/internal/handlers/actions_test.go
index b5e2b74b..99b65ad4 100644
--- a/internal/handlers/actions_test.go
+++ b/internal/handlers/actions_test.go
@@ -24,6 +24,12 @@ type liteActionBridge struct {
ensureChromeCalled bool
}
+type recordingActionBridge struct {
+ mockBridge
+ lastKind string
+ lastReq bridge.ActionRequest
+}
+
func (m *liteActionBridge) AvailableActions() []string {
return []string{bridge.ActionClick, bridge.ActionType, bridge.ActionPress}
}
@@ -37,6 +43,21 @@ func (m *liteActionBridge) RestartBrowser(cfg *config.RuntimeConfig) error {
return nil
}
+func (m *recordingActionBridge) AvailableActions() []string {
+ return []string{
+ bridge.ActionMouseMove,
+ bridge.ActionMouseDown,
+ bridge.ActionMouseUp,
+ bridge.ActionMouseWheel,
+ }
+}
+
+func (m *recordingActionBridge) ExecuteAction(ctx context.Context, kind string, req bridge.ActionRequest) (map[string]any, error) {
+ m.lastKind = kind
+ m.lastReq = req
+ return map[string]any{"ok": true}, nil
+}
+
type fakeLiteEngine struct {
clickRefs []string
typeCalls []struct {
@@ -406,6 +427,65 @@ func TestHandleAction_InvalidJSON(t *testing.T) {
}
}
+func TestHandleAction_PostCanonicalMouseFieldsAreAccepted(t *testing.T) {
+ b := &recordingActionBridge{}
+ h := New(b, &config.RuntimeConfig{}, nil, nil, nil)
+
+ req := httptest.NewRequest("POST", "/action", bytes.NewReader([]byte(`{"kind":"mouse-wheel","x":0,"y":0,"deltaY":240}`)))
+ req.Header.Set("Content-Type", "application/json")
+ w := httptest.NewRecorder()
+
+ h.HandleAction(w, req)
+
+ if w.Code != 200 {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ if b.lastKind != bridge.ActionMouseWheel {
+ t.Fatalf("kind = %q, want %q", b.lastKind, bridge.ActionMouseWheel)
+ }
+ if !b.lastReq.HasXY || b.lastReq.X != 0 || b.lastReq.Y != 0 {
+ t.Fatalf("expected zero coordinates with HasXY=true, got %+v", b.lastReq)
+ }
+ if b.lastReq.DeltaY != 240 {
+ t.Fatalf("deltaY = %d, want 240", b.lastReq.DeltaY)
+ }
+}
+
+func TestHandleAction_GetCanonicalMouseQueryIsAccepted(t *testing.T) {
+ b := &recordingActionBridge{}
+ h := New(b, &config.RuntimeConfig{}, nil, nil, nil)
+
+ req := httptest.NewRequest("GET", "/action?kind=mouse-move&x=0&y=0", nil)
+ w := httptest.NewRecorder()
+
+ h.HandleAction(w, req)
+
+ if w.Code != 200 {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ if b.lastKind != bridge.ActionMouseMove {
+ t.Fatalf("kind = %q, want %q", b.lastKind, bridge.ActionMouseMove)
+ }
+ if !b.lastReq.HasXY || b.lastReq.X != 0 || b.lastReq.Y != 0 {
+ t.Fatalf("expected zero coordinates with HasXY=true, got %+v", b.lastReq)
+ }
+}
+
+func TestHandleAction_LegacyMouseKindIsRejected(t *testing.T) {
+ b := &recordingActionBridge{}
+ h := New(b, &config.RuntimeConfig{}, nil, nil, nil)
+
+ req := httptest.NewRequest("POST", "/action", bytes.NewReader([]byte(`{"kind":"mousewheel","x":0,"y":0,"deltaY":240}`)))
+ req.Header.Set("Content-Type", "application/json")
+ w := httptest.NewRecorder()
+
+ h.HandleAction(w, req)
+
+ if w.Code != 400 {
+ t.Fatalf("expected 400, got %d: %s", w.Code, w.Body.String())
+ }
+}
+
func TestHandleMacro_Disabled(t *testing.T) {
h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
req := httptest.NewRequest("POST", "/macro", bytes.NewReader([]byte(`{"steps":[{"kind":"click","ref":"e0"}]}`)))
diff --git a/plugin/README.md b/plugin/README.md
index c8a94142..54cace7d 100644
--- a/plugin/README.md
+++ b/plugin/README.md
@@ -56,7 +56,7 @@ One tool definition, many actions — keeps context lean:
| `navigate` | Go to URL | — |
| `snapshot` | Accessibility tree (refs for interactions) | ~3,600 (interactive) |
| `click/type/press/fill/hover/scroll/select/focus` | Act on element by ref | — |
-| `mousemove/mousedown/mouseup/mousewheel` | Low-level mouse controls by ref/selector/coordinates | — |
+| `mouse-move/mouse-down/mouse-up/mouse-wheel` | Low-level mouse controls by ref/selector/coordinates | — |
| `wait` | Wait for selector/text/url/load/fn/ms conditions | — |
| `handoff` | Human-in-the-loop pause/resume for CAPTCHA/login/2FA | — |
| `text` | Extract readable text (cheapest) | ~800 |
@@ -89,19 +89,19 @@ Use these calls to validate low-level mouse behavior through the plugin:
1. pinchtab({ action: "navigate", url: "https://pinchtab.com" })
2. pinchtab({ action: "snapshot", filter: "interactive", format: "compact" })
→ Pick a target ref like e5
-3. pinchtab({ action: "mousemove", ref: "e5" })
-4. pinchtab({ action: "mousedown", ref: "e5", button: "left" })
-5. pinchtab({ action: "mouseup", ref: "e5", button: "left" })
-6. pinchtab({ action: "mousewheel", ref: "e5", wheelDeltaY: 240 })
+3. pinchtab({ action: "mouse-move", ref: "e5" })
+4. pinchtab({ action: "mouse-down", button: "left" })
+5. pinchtab({ action: "mouse-up", button: "left" })
+6. pinchtab({ action: "mouse-wheel", ref: "e5", deltaY: 240 })
```
Coordinate-driven test (viewport):
```
-pinchtab({ action: "mousemove", x: 400, y: 300 })
-pinchtab({ action: "mousedown", x: 400, y: 300, button: "left" })
-pinchtab({ action: "mouseup", x: 400, y: 300, button: "left" })
-pinchtab({ action: "mousewheel", x: 400, y: 300, wheelDeltaY: -320 })
+pinchtab({ action: "mouse-move", x: 400, y: 300 })
+pinchtab({ action: "mouse-down", button: "left" })
+pinchtab({ action: "mouse-up", button: "left" })
+pinchtab({ action: "mouse-wheel", x: 400, y: 300, deltaY: -320 })
```
**Token strategy:** `text` for reading, `snapshot` with `filter=interactive&format=compact` for interactions, `diff=true` on subsequent snapshots, `screenshot` only for visual verification.
diff --git a/plugin/index.ts b/plugin/index.ts
index 0b71bd2a..d3867f1f 100644
--- a/plugin/index.ts
+++ b/plugin/index.ts
@@ -113,7 +113,7 @@ export default function register(api: PluginApi) {
- navigate: go to URL (url, tabId?, newTab?, blockImages?, timeout?)
- snapshot: accessibility tree (filter?, format?, selector?, maxTokens?, depth?, diff?, tabId?)
- click/type/press/fill/hover/scroll/select/focus: act on element (ref, text?, key?, value?, scrollY?, waitNav?, tabId?)
- - mousemove/mousedown/mouseup/mousewheel: low-level mouse controls (ref|selector|x+y, button?, wheelDeltaX?, wheelDeltaY?, tabId?)
+ - mouse-move/mouse-down/mouse-up/mouse-wheel: low-level mouse controls (ref|selector|x+y, button?, deltaX?, deltaY?, tabId?)
- text: extract readable text (mode?, tabId?)
- wait: pause until condition (selector|text|url|load|fn|ms, tabId?, timeout?, state?)
- handoff: request human intervention mid-flow (captcha/login/2FA/credentials), optionally wait for resume condition
@@ -137,10 +137,10 @@ Token strategy: use "text" for reading (~800 tokens), "snapshot" with filter=int
"press",
"fill",
"hover",
- "mousemove",
- "mousedown",
- "mouseup",
- "mousewheel",
+ "mouse-move",
+ "mouse-down",
+ "mouse-up",
+ "mouse-wheel",
"scroll",
"select",
"focus",
@@ -208,15 +208,15 @@ Token strategy: use "text" for reading (~800 tokens), "snapshot" with filter=int
button: {
type: "string",
enum: ["left", "right", "middle"],
- description: "Mouse button for mousedown/mouseup",
+ description: "Mouse button for mouse-down/mouse-up",
},
- wheelDeltaX: {
+ deltaX: {
type: "number",
- description: "Mouse wheel horizontal delta for mousewheel",
+ description: "Mouse wheel horizontal delta for mouse-wheel",
},
- wheelDeltaY: {
+ deltaY: {
type: "number",
- description: "Mouse wheel vertical delta for mousewheel",
+ description: "Mouse wheel vertical delta for mouse-wheel",
},
waitNav: {
type: "boolean",
@@ -313,10 +313,10 @@ Token strategy: use "text" for reading (~800 tokens), "snapshot" with filter=int
"press",
"fill",
"hover",
- "mousemove",
- "mousedown",
- "mouseup",
- "mousewheel",
+ "mouse-move",
+ "mouse-down",
+ "mouse-up",
+ "mouse-wheel",
"scroll",
"select",
"focus",
@@ -333,8 +333,8 @@ Token strategy: use "text" for reading (~800 tokens), "snapshot" with filter=int
"x",
"y",
"button",
- "wheelDeltaX",
- "wheelDeltaY",
+ "deltaX",
+ "deltaY",
"tabId",
"waitNav",
]) {
diff --git a/plugin/openclaw.plugin.json b/plugin/openclaw.plugin.json
index 923be7e3..ecc4ccec 100644
--- a/plugin/openclaw.plugin.json
+++ b/plugin/openclaw.plugin.json
@@ -1,7 +1,7 @@
{
"id": "pinchtab",
"name": "Pinchtab",
- "description": "Browser control for AI agents via Pinchtab. Single tool, all actions: navigate, snapshot, click/type/press/fill/hover/scroll/select/focus, mousemove/mousedown/mouseup/mousewheel, text, screenshot, evaluate, pdf. Minimal context bloat.",
+ "description": "Browser control for AI agents via Pinchtab. Single tool, all actions: navigate, snapshot, click/type/press/fill/hover/scroll/select/focus, mouse-move/mouse-down/mouse-up/mouse-wheel, text, screenshot, evaluate, pdf.",
"version": "0.1.0",
"skills": ["../skills/pinchtab"],
"configSchema": {
diff --git a/skills/pinchtab/SKILL.md b/skills/pinchtab/SKILL.md
index 01af46f1..4053c7d0 100644
--- a/skills/pinchtab/SKILL.md
+++ b/skills/pinchtab/SKILL.md
@@ -208,10 +208,14 @@ pinchtab click <selector> # Click element
pinchtab click --wait-nav <selector> # Click and wait for navigation
pinchtab click --x 100 --y 200 # Click by coordinates
pinchtab dblclick <selector> # Double-click element
-pinchtab mouse move <selector> # Move pointer to element center or coordinates
-pinchtab mouse down <selector> --button left # Press a mouse button
-pinchtab mouse up <selector> --button left # Release a mouse button
-pinchtab mouse wheel <selector> --wheel-delta-y 240 # Dispatch wheel deltas
+pinchtab mouse move <selector> # Move pointer to element center
+pinchtab mouse move <x> <y> # Move pointer to coordinates
+pinchtab mouse down <selector> --button left # Press a mouse button at an explicit target
+pinchtab mouse down --button left # Press a mouse button at current pointer
+pinchtab mouse up <selector> --button left # Release a mouse button at an explicit target
+pinchtab mouse up --button left # Release a mouse button at current pointer
+pinchtab mouse wheel 240 --dx 40 # Dispatch wheel deltas at current pointer
+pinchtab drag <from> <to> # Drag between selector/ref or x,y points
pinchtab type <selector> <text> # Type with keystrokes
pinchtab fill <selector> <text> # Set value directly
pinchtab press <key> # Press key (Enter, Tab, Escape...)
@@ -323,7 +327,7 @@ curl -X POST http://localhost:9867/tabs/TAB_ID/action \
curl -X POST http://localhost:9867/tabs/TAB_ID/action \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
- -d '{"kind":"mousewheel","x":400,"y":320,"wheelDeltaY":240}'
+ -d '{"kind":"mouse-wheel","x":400,"y":320,"deltaY":240}'
# Navigate back/forward in a specific tab
curl -X POST http://localhost:9867/tabs/TAB_ID/back \
diff --git a/skills/pinchtab/references/api.md b/skills/pinchtab/references/api.md
index cab5b741..3e11f01d 100644
--- a/skills/pinchtab/references/api.md
+++ b/skills/pinchtab/references/api.md
@@ -113,19 +113,19 @@ curl -X POST /action -H 'Content-Type: application/json' \
# Move pointer without clicking
curl -X POST /action -H 'Content-Type: application/json' \
- -d '{"kind": "mousemove", "ref": "e8"}'
+ -d '{"kind": "mouse-move", "ref": "e8"}'
# Press and release a mouse button
curl -X POST /action -H 'Content-Type: application/json' \
- -d '{"kind": "mousedown", "ref": "e8", "button": "left"}'
+ -d '{"kind": "mouse-down", "button": "left"}'
curl -X POST /action -H 'Content-Type: application/json' \
- -d '{"kind": "mouseup", "ref": "e8", "button": "left"}'
+ -d '{"kind": "mouse-up", "button": "left"}'
# Wheel at an element or coordinates
curl -X POST /action -H 'Content-Type: application/json' \
- -d '{"kind": "mousewheel", "ref": "e8", "wheelDeltaY": 240}'
+ -d '{"kind": "mouse-wheel", "ref": "e8", "deltaY": 240}'
curl -X POST /action -H 'Content-Type: application/json' \
- -d '{"kind": "mousewheel", "x": 400, "y": 320, "wheelDeltaY": -320}'
+ -d '{"kind": "mouse-wheel", "x": 400, "y": 320, "deltaY": -320}'
# Select dropdown option (by value or visible text)
curl -X POST /action -H 'Content-Type: application/json' \
@@ -148,8 +148,9 @@ Notes:
- selector-based click and double-click paths resolve through backend node IDs before dispatching pointer events
- low-level pointer actions accept `ref`, `selector`, `nodeId`, or `x`/`y`
-- `mousedown` and `mouseup` accept `button` with `left`, `right`, or `middle`
-- `mousewheel` accepts `wheelDeltaX` and `wheelDeltaY`; when omitted, legacy `scrollX` / `scrollY` still work
+- `mouse-down` and `mouse-up` accept `button` with `left`, `right`, or `middle`
+- `mouse-wheel` accepts `deltaX` and `deltaY`; when omitted, legacy `scrollX` / `scrollY` still work
+- `mouse-down`, `mouse-up`, and `mouse-wheel` use the current pointer position when you do not pass a fresh target
## Wait for page state
diff --git a/skills/pinchtab/references/commands.md b/skills/pinchtab/references/commands.md
index bd35eb69..c8811447 100644
--- a/skills/pinchtab/references/commands.md
+++ b/skills/pinchtab/references/commands.md
@@ -98,10 +98,14 @@ Low-level pointer controls for cases where DOM-native click or hover behavior is
```bash
pinchtab mouse move e5
+pinchtab mouse move 120 220
pinchtab mouse down e5 --button left
+pinchtab mouse down --button left
pinchtab mouse up e5 --button left
-pinchtab mouse wheel e5 --wheel-delta-y 240
+pinchtab mouse up --button left
+pinchtab mouse wheel 240 --dx 40
pinchtab mouse move --x 400 --y 320
+pinchtab drag e5 400,320
```
Use these for drag handles, canvas controls, precise hover choreography, or sites that require exact pointer sequencing.
diff --git a/tests/e2e/scenarios/api/actions-basic.sh b/tests/e2e/scenarios/api/actions-basic.sh
index b2aeb6ef..733c7245 100644
--- a/tests/e2e/scenarios/api/actions-basic.sh
+++ b/tests/e2e/scenarios/api/actions-basic.sh
@@ -104,21 +104,24 @@ assert_ok "snapshot"
REF=$(find_ref_by_name "Mouse Target")
assert_ref_found "$REF" "mouse target ref"
-pt_post /action "{\"kind\":\"mousemove\",\"ref\":\"${REF}\"}"
-assert_ok "mousemove on target"
+pt_post /action "{\"kind\":\"mouse-move\",\"ref\":\"${REF}\"}"
+assert_ok "mouse-move on target"
-pt_post /action "{\"kind\":\"mousedown\",\"ref\":\"${REF}\",\"button\":\"left\"}"
-assert_ok "mousedown on target"
+pt_post /action '{"kind":"mouse-move","x":160,"y":190}'
+assert_ok "mouse-move by coordinates without hasXY"
-pt_post /action "{\"kind\":\"mouseup\",\"ref\":\"${REF}\",\"button\":\"left\"}"
-assert_ok "mouseup on target"
+pt_post /action '{"kind":"mouse-down","button":"left"}'
+assert_ok "mouse-down at current pointer"
-pt_post /action '{"kind":"mousewheel","x":160,"y":190,"hasXY":true,"wheelDeltaY":240}'
-assert_ok "mousewheel on target coordinates"
+pt_post /action '{"kind":"mouse-up","button":"left"}'
+assert_ok "mouse-up at current pointer"
+
+pt_post /action '{"kind":"mouse-wheel","deltaY":240}'
+assert_ok "mouse-wheel at current pointer"
pt_post /evaluate '{"expression":"window.mouseFixtureState.mousemoveCount"}'
assert_ok "evaluate mousemove count"
-assert_result_jq '.result >= 1' "mousemove count incremented" "mousemove count did not increment"
+assert_result_jq '.result >= 2' "mousemove count incremented twice" "mousemove count did not increment twice"
pt_post /evaluate '{"expression":"window.mouseFixtureState.mousedownCount"}'
assert_ok "evaluate mousedown count"
@@ -142,6 +145,31 @@ assert_json_eq "$RESULT" '.result' '240' "wheel delta Y accumulated"
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab mouse current-pointer sequence"
+
+pt_post /navigate "{\"url\":\"${FIXTURES_URL}/mouse-events.html\"}"
+assert_ok "navigate"
+
+pt_post /action '{"kind":"mouse-move","x":160,"y":190}'
+assert_ok "prime pointer position"
+
+pt_post /action '{"kind":"mouse-down","button":"left"}'
+assert_ok "mouse-down without fresh target"
+
+pt_post /action '{"kind":"mouse-move","x":165,"y":195}'
+assert_ok "mouse-move while held"
+
+pt_post /action '{"kind":"mouse-up","button":"left"}'
+assert_ok "mouse-up without fresh target"
+
+pt_post /evaluate '{"expression":"window.mouseFixtureState.sequence.join(\",\")"}'
+assert_ok "evaluate pointer sequence"
+assert_json_contains "$RESULT" '.result' 'mousedown' "sequence includes mousedown"
+assert_json_contains "$RESULT" '.result' 'mouseup' "sequence includes mouseup"
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab focus (ref)"
diff --git a/tests/e2e/scenarios/cli/actions-basic.sh b/tests/e2e/scenarios/cli/actions-basic.sh
index c79de641..4a76c788 100644
--- a/tests/e2e/scenarios/cli/actions-basic.sh
+++ b/tests/e2e/scenarios/cli/actions-basic.sh
@@ -63,13 +63,13 @@ if assert_ref_found "$MOUSE_REF" "mouse target ref"; then
pt_ok mouse move "$MOUSE_REF"
assert_output_contains "moved" "confirms mouse move action"
- pt_ok mouse down "$MOUSE_REF" --button left
+ pt_ok mouse down --button left
assert_output_contains "down" "confirms mouse down action"
- pt_ok mouse up "$MOUSE_REF" --button left
+ pt_ok mouse up --button left
assert_output_contains "up" "confirms mouse up action"
- pt_ok mouse wheel --x 160 --y 190 --wheel-delta-y 240
+ pt_ok mouse wheel 240 --dx 40
assert_output_contains "wheel" "confirms mouse wheel action"
pt_ok eval "window.mouseFixtureState.mousemoveCount"
@@ -93,6 +93,29 @@ fi
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab drag <from> <to>"
+
+pt_ok nav "${FIXTURES_URL}/mouse-events.html"
+pt_ok snap --interactive
+
+DRAG_REF=$(find_ref_by_name "Mouse Target" "$PT_OUT")
+if assert_ref_found "$DRAG_REF" "drag target ref"; then
+ pt_ok drag "$DRAG_REF" "160,190"
+ assert_output_contains "up" "confirms drag wrapper completed"
+
+ pt_ok eval "window.mouseFixtureState.mousemoveCount"
+ assert_output_jq '.result >= 2' "drag performs multiple move events" "drag did not perform multiple move events"
+
+ pt_ok eval "window.mouseFixtureState.mousedownCount"
+ assert_json_field ".result" "1" "drag performed one mouse down"
+
+ pt_ok eval "window.mouseFixtureState.mouseupCount"
+ assert_json_field ".result" "1" "drag performed one mouse up"
+fi
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab check/uncheck <selector>"