Skip to content

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

feat: add focus CLI command (#294) (#303)

Alice Losassof2ab23717bfe
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index c648e6e4..d7420943 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -218,6 +218,22 @@ var hoverCmd = &cobra.Command{
},
}
+var focusCmd = &cobra.Command{
+ Use: "focus <ref>",
+ Short: "Focus 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, "focus", ref, cmd)
+ })
+ },
+}
+
var scrollCmd = &cobra.Command{
Use: "scroll <ref|pixels>",
Short: "Scroll to element or by pixels",
@@ -428,6 +444,7 @@ func init() {
pressCmd.GroupID = "browser"
fillCmd.GroupID = "browser"
hoverCmd.GroupID = "browser"
+ focusCmd.GroupID = "browser"
scrollCmd.GroupID = "browser"
evalCmd.GroupID = "browser"
pdfCmd.GroupID = "browser"
@@ -483,6 +500,7 @@ func init() {
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")
+ focusCmd.Flags().String("css", "", "CSS selector instead of ref")
snapCmd.Flags().BoolP("interactive", "i", false, "Filter interactive elements only")
snapCmd.Flags().BoolP("compact", "c", false, "Compact output format")
@@ -536,6 +554,7 @@ func init() {
clickCmd.Flags().String("tab", "", "Tab ID")
dblclickCmd.Flags().String("tab", "", "Tab ID")
hoverCmd.Flags().String("tab", "", "Tab ID")
+ focusCmd.Flags().String("tab", "", "Tab ID")
typeCmd.Flags().String("tab", "", "Tab ID")
pressCmd.Flags().String("tab", "", "Tab ID")
fillCmd.Flags().String("tab", "", "Tab ID")
@@ -561,6 +580,7 @@ func init() {
rootCmd.AddCommand(pressCmd)
rootCmd.AddCommand(fillCmd)
rootCmd.AddCommand(hoverCmd)
+ rootCmd.AddCommand(focusCmd)
rootCmd.AddCommand(scrollCmd)
rootCmd.AddCommand(evalCmd)
rootCmd.AddCommand(pdfCmd)
diff --git a/internal/cli/actions/actions_element_test.go b/internal/cli/actions/actions_element_test.go
index 99f9fe61..8156a7e5 100644
--- a/internal/cli/actions/actions_element_test.go
+++ b/internal/cli/actions/actions_element_test.go
@@ -142,6 +142,26 @@ func TestHoverWithCSS(t *testing.T) {
}
}
+func TestFocus(t *testing.T) {
+ m := newMockServer()
+ defer m.close()
+ client := m.server.Client()
+
+ cmd := newActionCmd()
+ Action(client, m.base(), "", "focus", "e5", cmd)
+ if m.lastPath != "/action" {
+ t.Errorf("expected /action, got %s", m.lastPath)
+ }
+ var body map[string]any
+ _ = json.Unmarshal([]byte(m.lastBody), &body)
+ if body["kind"] != "focus" {
+ t.Errorf("expected kind=focus, got %v", body["kind"])
+ }
+ if body["ref"] != "e5" {
+ t.Errorf("expected ref=e5, got %v", body["ref"])
+ }
+}
+
func TestFocusWithCSS(t *testing.T) {
m := newMockServer()
defer m.close()