Skip to content

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

fix: a scroll direction aimed at an element was reinterpreted as scroll-into-view, discarding the keyword, the distance and the sign (PIN-233)

Luigi Agostic13b1d88e87c
diff --git a/internal/mcp/handlers_interaction.go b/internal/mcp/handlers_interaction.go
index 55f8e95c..c0af8acd 100644
--- a/internal/mcp/handlers_interaction.go
+++ b/internal/mcp/handlers_interaction.go
@@ -187,11 +187,19 @@ func handleAction(c *Client, kind string) func(context.Context, mcp.CallToolRequ
// (down and up only, no horizontal) and its own bare 120 — a wheel notch,
// which is a device unit: "down" moved a sixth of what the CLI moved, took
// six round trips to bring the next content into view, and said so nowhere.
- if direction != "" && !hasDeltaY && !hasDeltaX {
+ if direction != "" {
resolved, ok := scroll.DirectionFor(direction)
if !ok {
return mcp.NewToolResultError(fmt.Sprintf("direction must be one of %s", strings.Join(scroll.DirectionKeywords(), ", "))), nil
}
+ // Two magnitudes and no rule that picks between them. The keyword used to be
+ // dropped here without a word, which is the silent reinterpretation this tool
+ // is being fixed to stop — so it is refused instead, naming both spellings.
+ if hasDeltaX || hasDeltaY {
+ return mcp.NewToolResultError(fmt.Sprintf(
+ "direction and deltaX/deltaY each set a scroll magnitude; send one — direction for a %s step, or an explicit delta for a precise wheel move",
+ scrollStepDescription)), nil
+ }
distance := resolved.Delta * steps
if hasPixels && pixels != 0 {
magnitude := pixels
@@ -203,6 +211,18 @@ func handleAction(c *Client, kind string) func(context.Context, mcp.CallToolRequ
distance = -distance
}
}
+ // An element target means the caller is aiming the keyword INSIDE something —
+ // an inner scrollable container — so it rides the wheel at that element, the
+ // same routing an explicit magnitude gets. Posting it as a page scroll instead
+ // reaches actionScroll, which short-circuits on a target into scroll-into-view
+ // and discards the direction, the distance and the sign while still answering
+ // scrolled:true. A coordinate target needs no such move: actionScroll honours
+ // x/y and the delta together.
+ if hasSelector || hasNodeID {
+ payload["kind"] = "mouse-wheel"
+ }
+ // scrollX/scrollY is the wheel's legacy spelling, so the axis mapping stays
+ // owned by the direction table on both routes.
payload[resolved.Axis] = distance
break
}
diff --git a/internal/mcp/handlers_interaction_test.go b/internal/mcp/handlers_interaction_test.go
index 2d106d68..10c272cb 100644
--- a/internal/mcp/handlers_interaction_test.go
+++ b/internal/mcp/handlers_interaction_test.go
@@ -876,6 +876,70 @@ func TestScrollDirectionAcceptsEveryOwnedKeyword(t *testing.T) {
}
}
+// A direction aimed at an element must still land AT the element. Routing the keyword to
+// the page-scroll action put a selector in a body actionScroll short-circuits on, so it
+// revealed the element instead of scrolling inside it — the direction, the distance and
+// the SIGN all discarded, with scrolled:true in the response. The sign is asserted because
+// it is the half that survives a wrong-magnitude fix: 'up' reading as a reveal looks like
+// success from the outside.
+func TestScrollDirectionAtAnElementStaysOnTheWheel(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ target map[string]any
+ }{
+ {name: "selector", target: map[string]any{"selector": "#feed"}},
+ {name: "ref", target: map[string]any{"ref": "e5"}},
+ {name: "nodeId", target: map[string]any{"nodeId": float64(42)}},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ srv := mockPinchTab()
+ defer srv.Close()
+
+ args := map[string]any{"direction": "up"}
+ for k, v := range tc.target {
+ args[k] = v
+ }
+ body, _ := resultJSON(t, callTool(t, "pinchtab_scroll", args, srv))["body"].(map[string]any)
+
+ if got, _ := body["kind"].(string); got != "mouse-wheel" {
+ t.Errorf("kind = %q, want mouse-wheel; a page scroll carrying an element target is reinterpreted as scroll-into-view and the direction is dropped", got)
+ }
+ want, _ := scroll.DirectionFor("up")
+ if got, _ := body[want.Axis].(float64); got != float64(want.Delta) {
+ t.Errorf("%s = %v, want %d — the keyword magnitude and its sign must reach the element", want.Axis, body[want.Axis], want.Delta)
+ }
+ })
+ }
+}
+
+// Both spellings carry a magnitude and nothing decides between them, so the request is
+// refused rather than resolved by whichever the handler happens to read first. It used to
+// drop the direction without a word.
+func TestScrollDirectionRefusesACompetingDelta(t *testing.T) {
+ for _, key := range []string{"deltaX", "deltaY"} {
+ t.Run(key, func(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ t.Error("a scroll carrying two magnitudes was posted instead of refused")
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{}`))
+ }))
+ defer srv.Close()
+
+ res := callTool(t, "pinchtab_scroll", map[string]any{"direction": "down", key: float64(50)}, srv)
+
+ if !res.IsError {
+ t.Fatalf("accepted direction plus %s", key)
+ }
+ message := resultText(t, res)
+ for _, want := range []string{"direction", "deltaX/deltaY"} {
+ if !strings.Contains(message, want) {
+ t.Errorf("refusal %q does not name %q, so the caller cannot tell which two settings collided", message, want)
+ }
+ }
+ })
+ }
+}
+
// The tool description is where an agent learns the distance — the whole reason `steps`
// was unusable was that the magnitude appeared nowhere it reads.
func TestScrollToolDescriptionStatesTheMagnitudeAndEveryDirection(t *testing.T) {
diff --git a/internal/mcp/tools.go b/internal/mcp/tools.go
index c8a0ff3b..ae38561b 100644
--- a/internal/mcp/tools.go
+++ b/internal/mcp/tools.go
@@ -189,7 +189,9 @@ func allTools() []mcp.Tool {
mcp.WithNumber("deltaY", mcp.Description("Vertical wheel delta for precise scrolling")),
mcp.WithString("direction", mcp.Description(
"Convenience direction: 'down', 'left', 'right' or 'up'. Moves "+scrollStepDescription+
- " per step, the same distance as the CLI's `pinchtab scroll <direction>`; multiply it with 'steps' or override it with 'pixels'.")),
+ " per step, the same distance as the CLI's `pinchtab scroll <direction>`; multiply it with 'steps' or override it with 'pixels'. "+
+ "With a selector or nodeId it scrolls that far INSIDE the element (wheel semantics) rather than revealing it. "+
+ "It cannot be combined with deltaX/deltaY, which set their own magnitude.")),
mcp.WithNumber("steps", mcp.Description("Multiplier for direction-based scrolling (default 1), so steps=2 moves twice "+scrollStepDescription)),
mcp.WithNumber("x", mcp.Description("Optional X coordinate for wheel target")),
mcp.WithNumber("y", mcp.Description("Optional Y coordinate for wheel target")),