Skip to content

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

feat: implement dblclick action (#270) (#282)

luigiagent043bb1537a4b
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index f3b7343f..01e853b2 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -97,6 +97,22 @@ var clickCmd = &cobra.Command{
},
}
+var dblclickCmd = &cobra.Command{
+ Use: "dblclick <ref>",
+ Short: "Double-click element",
+ Args: cobra.MaximumNArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ ref := ""
+ if len(args) > 0 {
+ ref = args[0]
+ }
+ cfg := config.Load()
+ runCLIWith(cfg, func(client *http.Client, base, token string) {
+ browseractions.Action(client, base, token, "dblclick", ref, cmd)
+ })
+ },
+}
+
var typeCmd = &cobra.Command{
Use: "type <ref> <text>",
Short: "Type into element",
@@ -371,6 +387,9 @@ func init() {
clickCmd.Flags().Float64("x", 0, "X coordinate for click")
clickCmd.Flags().Float64("y", 0, "Y coordinate for click")
clickCmd.Flags().Bool("wait-nav", false, "Wait for navigation after click")
+ dblclickCmd.Flags().String("css", "", "CSS selector instead of ref")
+ dblclickCmd.Flags().Float64("x", 0, "X coordinate for dblclick")
+ dblclickCmd.Flags().Float64("y", 0, "Y coordinate for dblclick")
hoverCmd.Flags().String("css", "", "CSS selector instead of ref")
hoverCmd.Flags().Float64("x", 0, "X coordinate for hover")
hoverCmd.Flags().Float64("y", 0, "Y coordinate for hover")
@@ -425,6 +444,7 @@ func init() {
reloadCmd.Flags().String("tab", "", "Tab ID")
clickCmd.Flags().String("tab", "", "Tab ID")
+ dblclickCmd.Flags().String("tab", "", "Tab ID")
hoverCmd.Flags().String("tab", "", "Tab ID")
typeCmd.Flags().String("tab", "", "Tab ID")
pressCmd.Flags().String("tab", "", "Tab ID")
@@ -440,6 +460,7 @@ func init() {
rootCmd.AddCommand(reloadCmd)
rootCmd.AddCommand(snapCmd)
rootCmd.AddCommand(clickCmd)
+ rootCmd.AddCommand(dblclickCmd)
rootCmd.AddCommand(typeCmd)
rootCmd.AddCommand(screenshotCmd)
rootCmd.AddCommand(tabsCmd)
diff --git a/docs/commands.md b/docs/commands.md
index 48ddf02c..1ca1c133 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -57,6 +57,8 @@ Numeric arguments are resolved as 1-based tab indices via `/tabs`. Non-numeric a
pinchtab click <ref> # Click element by ref
pinchtab click --css <selector> # Click element by CSS selector
pinchtab click --wait-nav <ref> # Click and wait for navigation
+pinchtab dblclick <ref> # Double-click element by ref
+pinchtab dblclick --css <selector> # Double-click element by CSS selector
pinchtab type <ref> <text> # Type into element
pinchtab fill <ref|selector> <text> # Fill input directly (no keystroke events)
pinchtab press <key> # Press key (Enter, Tab, Escape...)
@@ -144,7 +146,7 @@ pinchtab security down # Relax security settings
Most browser commands support `--tab <id>` to target a specific tab.
-Commands with `--tab`: nav, snap, click, type, fill, press, hover, scroll, select, eval, screenshot, pdf, find, text
+Commands with `--tab`: nav, snap, click, dblclick, type, fill, press, hover, scroll, select, eval, screenshot, pdf, find, text
```
pinchtab <command> --tab <id> # Run command against specific tab
diff --git a/docs/endpoints.md b/docs/endpoints.md
index e4930c1d..65b66a71 100644
--- a/docs/endpoints.md
+++ b/docs/endpoints.md
@@ -72,9 +72,9 @@ POST /tabs/{id}/action # Action on specific tab
POST /tabs/{id}/actions # Batch actions on specific tab
```
-Action kinds: `click`, `type`, `fill`, `press`, `hover`, `scroll`, `select`, `focus`, `drag`
+Action kinds: `click`, `dblclick`, `type`, `fill`, `press`, `hover`, `scroll`, `select`, `focus`, `drag`
-Body: `{"kind": "click", "ref": "e5"}` / `{"kind": "type", "ref": "e12", "text": "hello"}`
+Body: `{"kind": "click", "ref": "e5"}` / `{"kind": "dblclick", "ref": "e5"}` / `{"kind": "type", "ref": "e12", "text": "hello"}`
## Page Analysis
diff --git a/internal/bridge/actions.go b/internal/bridge/actions.go
index 6cc859cb..c904d3da 100644
--- a/internal/bridge/actions.go
+++ b/internal/bridge/actions.go
@@ -10,17 +10,18 @@ import (
)
const (
- ActionClick = "click"
- ActionType = "type"
- ActionFill = "fill"
- ActionPress = "press"
- ActionFocus = "focus"
- ActionHover = "hover"
- ActionSelect = "select"
- ActionScroll = "scroll"
- ActionDrag = "drag"
- ActionHumanClick = "humanClick"
- ActionHumanType = "humanType"
+ ActionClick = "click"
+ ActionDoubleClick = "dblclick"
+ ActionType = "type"
+ ActionFill = "fill"
+ ActionPress = "press"
+ ActionFocus = "focus"
+ ActionHover = "hover"
+ ActionSelect = "select"
+ ActionScroll = "scroll"
+ ActionDrag = "drag"
+ ActionHumanClick = "humanClick"
+ ActionHumanType = "humanType"
)
func (b *Bridge) InitActionRegistry() {
@@ -44,6 +45,22 @@ func (b *Bridge) InitActionRegistry() {
}
return map[string]any{"clicked": true}, nil
},
+ ActionDoubleClick: func(ctx context.Context, req ActionRequest) (map[string]any, error) {
+ var err error
+ if req.Selector != "" {
+ err = chromedp.Run(ctx, chromedp.DoubleClick(req.Selector, chromedp.ByQuery))
+ } else if req.NodeID > 0 {
+ err = DoubleClickByNodeID(ctx, req.NodeID)
+ } else if req.HasXY {
+ err = DoubleClickByCoordinate(ctx, req.X, req.Y)
+ } else {
+ return nil, fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
+ }
+ if err != nil {
+ return nil, err
+ }
+ return map[string]any{"doubleclicked": true}, nil
+ },
ActionType: func(ctx context.Context, req ActionRequest) (map[string]any, error) {
if req.Text == "" {
return nil, fmt.Errorf("text required for type")
diff --git a/internal/bridge/actions_test.go b/internal/bridge/actions_test.go
index 1e28f8a6..46af9809 100644
--- a/internal/bridge/actions_test.go
+++ b/internal/bridge/actions_test.go
@@ -23,6 +23,21 @@ func TestClickAction_UsesCoordinatePathIncludingZeroZero(t *testing.T) {
}
}
+func TestDoubleClickAction_UsesCoordinatePathIncludingZeroZero(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ _, err := b.Actions[ActionDoubleClick](ctx, ActionRequest{HasXY: true, X: 0, Y: 0})
+ if err == nil {
+ t.Fatal("expected error from cancelled context")
+ }
+ if strings.Contains(err.Error(), "need selector") {
+ t.Fatalf("expected coordinate path, got selector/ref validation error: %v", err)
+ }
+}
+
func TestHoverAction_UsesCoordinatePath(t *testing.T) {
b := New(context.TODO(), nil, &config.RuntimeConfig{})
diff --git a/internal/bridge/cdp.go b/internal/bridge/cdp.go
index 0b3fba90..5741a6f5 100644
--- a/internal/bridge/cdp.go
+++ b/internal/bridge/cdp.go
@@ -220,6 +220,67 @@ func ClickByNodeID(ctx context.Context, nodeID int64) error {
)
}
+func DoubleClickByCoordinate(ctx context.Context, x, y float64) error {
+ if x < 0 || y < 0 {
+ return fmt.Errorf("x/y coordinates must be >= 0")
+ }
+
+ return chromedp.Run(ctx,
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx,
+ "Input.dispatchMouseEvent", map[string]any{
+ "type": "mousePressed",
+ "button": "left",
+ "clickCount": 2,
+ "x": x,
+ "y": y,
+ }, nil)
+ }),
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx,
+ "Input.dispatchMouseEvent", map[string]any{
+ "type": "mouseReleased",
+ "button": "left",
+ "clickCount": 2,
+ "x": x,
+ "y": y,
+ }, nil)
+ }),
+ )
+}
+
+func DoubleClickByNodeID(ctx context.Context, nodeID int64) error {
+ x, y, err := getElementCenter(ctx, nodeID)
+ if err != nil {
+ return err
+ }
+
+ return chromedp.Run(ctx,
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx, "DOM.scrollIntoViewIfNeeded", map[string]any{"backendNodeId": nodeID}, nil)
+ }),
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx, "DOM.focus", map[string]any{"backendNodeId": nodeID}, nil)
+ }),
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx, "Input.dispatchMouseEvent", map[string]any{
+ "type": "mousePressed",
+ "button": "left",
+ "clickCount": 2,
+ "x": x, "y": y,
+ }, nil)
+ }),
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx, "Input.dispatchMouseEvent", map[string]any{
+ "type": "mouseReleased",
+ "button": "left",
+ "clickCount": 2,
+ "x": x, "y": y,
+ }, nil)
+ }),
+ )
+}
+
// getElementCenter returns the center coordinates of an element using DOM.getBoxModel.
func getElementCenter(ctx context.Context, backendNodeID int64) (x, y float64, err error) {
var result json.RawMessage
diff --git a/internal/bridge/cdp_test.go b/internal/bridge/cdp_test.go
index 27fa0321..279da24c 100644
--- a/internal/bridge/cdp_test.go
+++ b/internal/bridge/cdp_test.go
@@ -188,6 +188,28 @@ func TestHoverByCoordinate_ContextCancelled(t *testing.T) {
}
}
+func TestDoubleClickByCoordinate_ContextCancelled(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ err := DoubleClickByCoordinate(ctx, 0, 0)
+ if err == nil {
+ t.Fatal("expected error for cancelled context")
+ }
+}
+
+func TestDoubleClickByCoordinate_RejectNegativeCoordinates(t *testing.T) {
+ ctx := context.Background()
+
+ if err := DoubleClickByCoordinate(ctx, -1, 0); err == nil {
+ t.Fatal("expected dblclick negative X coordinate to fail")
+ }
+
+ if err := DoubleClickByCoordinate(ctx, 0, -1); err == nil {
+ t.Fatal("expected dblclick negative Y coordinate to fail")
+ }
+}
+
func TestCoordinateActions_RejectNegativeCoordinates(t *testing.T) {
ctx := context.Background()
diff --git a/tests/e2e/scenarios/05b-dblclick.sh b/tests/e2e/scenarios/05b-dblclick.sh
new file mode 100755
index 00000000..666a24ee
--- /dev/null
+++ b/tests/e2e/scenarios/05b-dblclick.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+# 05b-dblclick.sh — Double-click action tests
+
+source "$(dirname "$0")/common.sh"
+
+# ─────────────────────────────────────────────────────────────────
+start_test "HTTP: dblclick by ref"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
+sleep 1
+
+pt_get /snapshot
+REF=$(echo "$RESULT" | jq -r '.nodes[0].ref // .tree.ref // "e0"')
+
+pt_post /action -d "{\"kind\":\"dblclick\",\"ref\":\"$REF\"}"
+assert_ok "dblclick by ref"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "HTTP: dblclick by CSS selector"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
+sleep 1
+
+pt_post /action -d "{\"kind\":\"dblclick\",\"selector\":\"#increment\"}"
+assert_ok "dblclick by selector"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "HTTP: dblclick by coordinates"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
+sleep 1
+
+pt_post /action -d "{\"kind\":\"dblclick\",\"x\":100,\"y\":100}"
+assert_ok "dblclick by coordinates"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "CLI: pinchtab dblclick <ref>"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
+sleep 1
+
+pt_get /snapshot
+REF=$(echo "$RESULT" | jq -r '.nodes[0].ref // .tree.ref // "e0"')
+
+run_cli dblclick "$REF"
+assert_ok "CLI dblclick by ref"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "CLI: pinchtab dblclick --css <selector>"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
+sleep 1
+
+run_cli dblclick --css "#increment"
+assert_ok "CLI dblclick by selector"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "CLI: pinchtab dblclick --tab <id>"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\",\"newTab\":true}"
+assert_ok "navigate for new tab"
+TAB_ID=$(echo "$RESULT" | jq -r '.tabId')
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
+sleep 1
+
+pt_get /snapshot
+REF=$(echo "$RESULT" | jq -r '.nodes[0].ref // .tree.ref // "e0"')
+
+run_cli dblclick "$REF" --tab "$TAB_ID"
+assert_ok "CLI dblclick with --tab flag"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "HTTP: dblclick validation - missing ref/selector/coordinates"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"
+
+pt_post /action -d "{\"kind\":\"dblclick\"}"
+assert_error "dblclick without parameters should fail"
+
+end_test
diff --git a/tests/e2e/scenarios/helpers/actions.sh b/tests/e2e/scenarios/helpers/actions.sh
index c7643b25..7934e3de 100644
--- a/tests/e2e/scenarios/helpers/actions.sh
+++ b/tests/e2e/scenarios/helpers/actions.sh
@@ -11,6 +11,14 @@ action_click() {
assert_ok "click ref=$ref"
}
+# Double-click an element by ref.
+# Usage: action_dblclick "$ref"
+action_dblclick() {
+ local ref="$1"
+ pt_post /action -d "{\"kind\":\"dblclick\",\"ref\":\"$ref\"}" > /dev/null
+ assert_ok "dblclick ref=$ref"
+}
+
# Type text into an element by ref (standard CDP type).
# Usage: action_type "$ref" "hello"
action_type() {