High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: add CLI command 'pinchtab launch' to create instances
Mario1644c3e260b8
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.goindex 34c835b4..f88f8954 100644--- a/cmd/pinchtab/cmd_cli.go+++ b/cmd/pinchtab/cmd_cli.go@@ -150,6 +150,8 @@ func runCLI(cfg *config.RuntimeConfig) {cliPDF(client, base, token, args)case "health":cliHealth(client, base, token)+ case "launch":+ cliLaunch(client, base, token, args)case "instances":cliInstances(client, base, token)case "profiles":@@ -178,6 +180,12 @@ WORKFLOW:Commands:quick <url> Navigate and analyze page (beginner-friendly)++ INSTANCE MANAGEMENT:+ launch Create new instance (--name test, --headed for visible window)+ instances List all running instances++ BROWSER CONTROL:nav, navigate <url> Navigate to URL (--new-tab, --block-images, --block-ads)snap, snapshot Accessibility tree snapshot (-i, -c, -d, --max-tokens N)click <ref> Click element by ref@@ -195,6 +203,8 @@ Commands:ss, screenshot Take screenshot (-o file, -q quality)eval <expression> Evaluate JavaScriptpdf Export page as PDF (-o file, --landscape, --scale N)++ OTHER:health Server health checkhelp Show this help@@ -632,6 +642,53 @@ func cliHealth(client *http.Client, base, token string) {doGet(client, base, token, "/health", nil)}+// --- launch ---++func cliLaunch(client *http.Client, base, token string, args []string) {+ body := map[string]any{}++ for i := 0; i < len(args); i++ {+ switch args[i] {+ case "--name":+ if i+1 < len(args) {+ body["name"] = args[i+1]+ i+++ }+ case "--headed":+ body["headless"] = false+ case "--headless":+ body["headless"] = true+ }+ }++ result := doPost(client, base, token, "/instances/launch", body)+ if result == nil {+ return+ }++ // Display instance info+ if id, ok := result["id"].(string); ok {+ if name, ok := result["profileName"].(string); ok {+ if port, ok := result["port"].(string); ok {+ if headless, ok := result["headless"].(bool); ok {+ mode := "headless"+ if !headless {+ mode = "headed"+ }+ fmt.Printf("✅ Instance created\n")+ fmt.Printf(" ID: %s\n", id)+ fmt.Printf(" Name: %s\n", name)+ fmt.Printf(" Port: %s\n", port)+ fmt.Printf(" Mode: %s\n", mode)+ if status, ok := result["status"].(string); ok {+ fmt.Printf(" Status: %s\n", status)+ }+ }+ }+ }+ }+}+// --- instances ---func cliInstances(client *http.Client, base, token string) {diff --git a/internal/handlers/actions.go b/internal/handlers/actions.goindex 7744e2ff..a7d8cd79 100644--- a/internal/handlers/actions.go+++ b/internal/handlers/actions.go@@ -32,33 +32,40 @@ import (// @Response 500 application/json Chrome error//// @Example curl click:-// curl -X POST http://localhost:9867/action \-// -H "Content-Type: application/json" \-// -d '{"tabId":"abc123","kind":"click","ref":"e5"}'+//+// curl -X POST http://localhost:9867/action \+// -H "Content-Type: application/json" \+// -d '{"tabId":"abc123","kind":"click","ref":"e5"}'//// @Example curl type:-// curl -X POST http://localhost:9867/action \-// -H "Content-Type: application/json" \-// -d '{"tabId":"abc123","kind":"type","ref":"e3","text":"[email protected]"}'+//+// curl -X POST http://localhost:9867/action \+// -H "Content-Type: application/json" \+// -d '{"tabId":"abc123","kind":"type","ref":"e3","text":"[email protected]"}'//// @Example curl fill form:-// curl -X POST http://localhost:9867/action \-// -H "Content-Type: application/json" \-// -d '{"tabId":"abc123","kind":"fill","ref":"e3","text":"John Doe"}'+//+// curl -X POST http://localhost:9867/action \+// -H "Content-Type: application/json" \+// -d '{"tabId":"abc123","kind":"fill","ref":"e3","text":"John Doe"}'//// @Example curl press key:-// curl -X POST http://localhost:9867/action \-// -H "Content-Type: application/json" \-// -d '{"tabId":"abc123","kind":"press","ref":"e7","key":"Enter"}'+//+// curl -X POST http://localhost:9867/action \+// -H "Content-Type: application/json" \+// -d '{"tabId":"abc123","kind":"press","ref":"e7","key":"Enter"}'//// @Example cli click:-// pinchtab click e5+//+// pinchtab click e5//// @Example cli type:-// pinchtab type e3 "[email protected]"+//+// pinchtab type e3 "[email protected]"//// @Example cli fill:-// pinchtab fill e3 "John Doe"+//+// pinchtab fill e3 "John Doe"func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {// Ensure Chrome is initializedif err := h.ensureChrome(); err != nil {diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.goindex e438afa2..b4a9e5ca 100644--- a/internal/handlers/navigation.go+++ b/internal/handlers/navigation.go@@ -31,17 +31,20 @@ const maxBodySize = 1 << 20// @Response 500 application/json Chrome error//// @Example curl navigate new:-// curl -X POST http://localhost:9867/navigate \-// -H "Content-Type: application/json" \-// -d '{"url":"https://example.com"}'+//+// curl -X POST http://localhost:9867/navigate \+// -H "Content-Type: application/json" \+// -d '{"url":"https://example.com"}'//// @Example curl navigate existing:-// curl -X POST http://localhost:9867/navigate \-// -H "Content-Type: application/json" \-// -d '{"tabId":"abc123","url":"https://google.com"}'+//+// curl -X POST http://localhost:9867/navigate \+// -H "Content-Type: application/json" \+// -d '{"tabId":"abc123","url":"https://google.com"}'//// @Example cli:-// pinchtab nav https://example.com+//+// pinchtab nav https://example.comfunc (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {// Ensure Chrome is initializedif err := h.ensureChrome(); err != nil {diff --git a/internal/handlers/snapshot.go b/internal/handlers/snapshot.goindex b913aab8..2c7f027f 100644--- a/internal/handlers/snapshot.go+++ b/internal/handlers/snapshot.go@@ -36,21 +36,26 @@ import (// @Response 404 application/json Tab not found//// @Example curl all elements:-// curl "http://localhost:9867/snapshot?tabId=abc123"+//+// curl "http://localhost:9867/snapshot?tabId=abc123"//// @Example curl interactive only:-// curl "http://localhost:9867/snapshot?tabId=abc123&filter=interactive"+//+// curl "http://localhost:9867/snapshot?tabId=abc123&filter=interactive"//// @Example curl compact:-// curl "http://localhost:9867/snapshot?tabId=abc123&filter=interactive&compact=true"+//+// curl "http://localhost:9867/snapshot?tabId=abc123&filter=interactive&compact=true"//// @Example cli:-// pinchtab snap -i -c+//+// pinchtab snap -i -c//// @Example python:-// import requests-// r = requests.get("http://localhost:9867/snapshot", params={"tabId": "abc123", "filter": "interactive"})-// tree = r.json()+//+// import requests+// r = requests.get("http://localhost:9867/snapshot", params={"tabId": "abc123", "filter": "interactive"})+// tree = r.json()func (h *Handlers) HandleSnapshot(w http.ResponseWriter, r *http.Request) {// Ensure Chrome is initializedif err := h.ensureChrome(); err != nil {diff --git a/scripts/gen-api-docs/main.go b/scripts/gen-api-docs/main.goindex 369ba0c8..8fbdfad1 100644--- a/scripts/gen-api-docs/main.go+++ b/scripts/gen-api-docs/main.go@@ -32,8 +32,8 @@ type Parameter struct {}type ExampleGroup struct {- Curl string `json:"curl,omitempty"`- CLI string `json:"cli,omitempty"`+ Curl string `json:"curl,omitempty"`+ CLI string `json:"cli,omitempty"`Payload string `json:"payload,omitempty"` // Example JSON payload}