High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: scroll -300 is documented twice and never works, and the only workaround silently scrolls the wrong tab (PIN-136)
Luigi Agosti08e8c1458392
diff --git a/cmd/pinchtab/cmd_cli_browser_actions.go b/cmd/pinchtab/cmd_cli_browser_actions.goindex fba8a510..2cb80307 100644--- a/cmd/pinchtab/cmd_cli_browser_actions.go+++ b/cmd/pinchtab/cmd_cli_browser_actions.go@@ -166,9 +166,29 @@ func scrollArgs(cmd *cobra.Command, args []string) error {if len(args) == 1 && byFlag {return fmt.Errorf("give either %q or --dy/--dx, not both", args[0])}+ // A delta of zero on both axes is indistinguishable from sending no delta at+ // all, and the server reads that as "scroll down by the default" — so+ // `--dy 0` would scroll 120px instead of nothing. Dropping the field client+ // side lands in the same default, so the only honest client-side answer is to+ // refuse. An explicit zero on ONE axis is fine and passes through.+ if byFlag && scrollFlagDelta(cmd, "dy") == 0 && scrollFlagDelta(cmd, "dx") == 0 {+ return fmt.Errorf("a zero delta is not a scroll: the server reads no-delta as its default and would scroll down 120px; pass a non-zero --dy/--dx")+ }return nil}+// scrollFlagDelta is the value of an int scroll flag, 0 when unset or unreadable.+func scrollFlagDelta(cmd *cobra.Command, name string) int {+ if !cmd.Flags().Changed(name) {+ return 0+ }+ value, err := cmd.Flags().GetInt(name)+ if err != nil {+ return 0+ }+ return value+}+var selectCmd = newSimpleActionCmd("select <ref> <value>", "Select option in dropdown", "select", cobra.MinimumNArgs(2))var checkCmd = newRequiredRefActionCmd("check <selector>", "Check a checkbox or radio", "check")diff --git a/cmd/pinchtab/cmd_cli_scroll_test.go b/cmd/pinchtab/cmd_cli_scroll_test.goindex b45fd043..c0a4d127 100644--- a/cmd/pinchtab/cmd_cli_scroll_test.go+++ b/cmd/pinchtab/cmd_cli_scroll_test.go@@ -58,6 +58,23 @@ func TestScrollRefusesArgumentsItCannotHonour(t *testing.T) {flags: map[string]string{"dy": "-300"},wantErr: "not both",},+ {+ name: "an explicit zero delta",+ args: nil,+ flags: map[string]string{"dy": "0"},+ wantErr: "zero delta",+ },+ {+ name: "zero on both axes",+ args: nil,+ flags: map[string]string{"dy": "0", "dx": "0"},+ wantErr: "zero delta",+ },+ {+ name: "an explicit zero on ONE axis is a real scroll",+ args: nil,+ flags: map[string]string{"dy": "0", "dx": "500"},+ },{name: "a positional alone",args: []string{"800"},diff --git a/internal/cli/actions/actions_element.go b/internal/cli/actions/actions_element.goindex 7ee4563a..3ae3228d 100644--- a/internal/cli/actions/actions_element.go+++ b/internal/cli/actions/actions_element.go@@ -235,21 +235,27 @@ func ScrollDirectionKeywords() []string {return keywords}-// applyScrollTarget fills a scroll body from --dy/--dx, or from the single positional by-// precedence: integer pixels, then direction keyword, then unified selector. Pixels and-// directions would otherwise parse as CSS tag selectors ("up", "down"), so they are-// intercepted before setSelectorBody.+// applyScrollTarget fills a scroll body from the single positional — integer pixels, then+// direction keyword, then unified selector — or from --dy/--dx when there is no positional.+// Pixels and directions would otherwise parse as CSS tag selectors ("up", "down"), so they+// are intercepted before setSelectorBody.//// A negative count is only reachable through the flags: cobra reads a leading minus on a// positional as bundled shorthand flags.+//+// The positional and the flags are two spellings of ONE argument, so a positional wins+// outright instead of merging: assigning both would build a diagonal scroll out of a flag+// axis and a positional axis that no caller asked for. The CLI refuses that combination+// before it gets here, but this is exported and callable without cobra's Args hook, so the+// rule lives here rather than on loan from another package.func applyScrollTarget(body map[string]any, args []string, cmd *cobra.Command) {- if deltaY, ok := readIntFlag(cmd, "dy"); ok {- body["scrollY"] = deltaY- }- if deltaX, ok := readIntFlag(cmd, "dx"); ok {- body["scrollX"] = deltaX- }if len(args) == 0 {+ if deltaY, ok := readIntFlag(cmd, "dy"); ok {+ body["scrollY"] = deltaY+ }+ if deltaX, ok := readIntFlag(cmd, "dx"); ok {+ body["scrollX"] = deltaX+ }return}if px, err := strconv.Atoi(args[0]); err == nil {diff --git a/internal/cli/actions/actions_element_test.go b/internal/cli/actions/actions_element_test.goindex 1d63d75f..440d8cb0 100644--- a/internal/cli/actions/actions_element_test.go+++ b/internal/cli/actions/actions_element_test.go@@ -899,3 +899,76 @@ func TestScrollPositionalFormsAreUnchangedByThePixelFlags(t *testing.T) {m.close()}}++// ActionSimple is exported and reachable without cobra's Args hook, so the CLI's+// refusal of the both-specified form is a friendly early error, not the thing that+// keeps this correct. The rule has to live in the builder: a positional wins+// outright. Before it did, the flags were assigned first and the positional then+// overwrote scrollY — so `800` with `--dx -100` built a diagonal scroll out of one+// axis from each spelling, resolved by statement order rather than by any rule.+func TestScrollPositionalWinsOverThePixelFlagsWithoutCobrasArgsHook(t *testing.T) {+ for _, tc := range []struct {+ name string+ arg string+ flags map[string]string+ want map[string]any+ absent []string+ }{+ {+ name: "same axis",+ arg: "800",+ flags: map[string]string{"dy": "-300"},+ want: map[string]any{"scrollY": float64(800)},+ absent: []string{"scrollX"},+ },+ {+ name: "other axis must not survive as half a diagonal",+ arg: "800",+ flags: map[string]string{"dx": "-100"},+ want: map[string]any{"scrollY": float64(800)},+ absent: []string{"scrollX"},+ },+ {+ name: "a direction keyword also wins",+ arg: "left",+ flags: map[string]string{"dy": "-300"},+ want: map[string]any{"scrollX": float64(-800)},+ absent: []string{"scrollY"},+ },+ {+ name: "a selector wins and carries no delta",+ arg: "e12",+ flags: map[string]string{"dy": "-300", "dx": "40"},+ want: map[string]any{"ref": "e12"},+ absent: []string{"scrollX", "scrollY"},+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ m := newMockServer()+ defer m.close()+ cmd := newScrollCmd()+ for flag, value := range tc.flags {+ if err := cmd.Flags().Set(flag, value); err != nil {+ t.Fatal(err)+ }+ }++ ActionSimple(m.server.Client(), m.base(), "", "scroll", []string{tc.arg}, cmd)++ var body map[string]any+ if err := json.Unmarshal([]byte(m.lastBody), &body); err != nil {+ t.Fatalf("decode body: %v (%s)", err, m.lastBody)+ }+ for key, want := range tc.want {+ if body[key] != want {+ t.Errorf("%s = %v, want %v (body %+v)", key, body[key], want, body)+ }+ }+ for _, key := range tc.absent {+ if _, present := body[key]; present {+ t.Errorf("%s is present (%v); the positional is the whole argument, so no flag axis may survive alongside it (body %+v)", key, body[key], body)+ }+ }+ })+ }+}