Skip to content

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

feat: added human-readable default output for frame and network

Luigi Agostif61bd1a9d662
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index 9aa247b8..83b21df0 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -307,6 +307,8 @@ func configureBrowserFlags() {
healthCmd,
cacheClearCmd,
cacheStatusCmd,
+ frameCmd,
+ networkCmd,
)
scrollintoviewCmd.Flags().String("css", "", "CSS selector instead of ref")
diff --git a/internal/cli/actions/actions_frame.go b/internal/cli/actions/actions_frame.go
index 1c5ee995..9e39dc2b 100644
--- a/internal/cli/actions/actions_frame.go
+++ b/internal/cli/actions/actions_frame.go
@@ -1,6 +1,8 @@
package actions
import (
+ "encoding/json"
+ "fmt"
"net/http"
"net/url"
@@ -10,12 +12,42 @@ import (
func Frame(client *http.Client, base, token string, args []string, cmd *cobra.Command) {
tabID, _ := cmd.Flags().GetString("tab")
+ jsonOutput, _ := cmd.Flags().GetBool("json")
+
if len(args) == 0 {
params := url.Values{}
if tabID != "" {
params.Set("tabId", tabID)
}
- apiclient.DoGet(client, base, token, "/frame", params)
+ if jsonOutput {
+ apiclient.DoGet(client, base, token, "/frame", params)
+ return
+ }
+
+ body := apiclient.DoGetRaw(client, base, token, "/frame", params)
+ var resp struct {
+ Current any `json:"current"`
+ Scoped bool `json:"scoped"`
+ }
+ if err := json.Unmarshal(body, &resp); err != nil {
+ fmt.Println(string(body))
+ return
+ }
+ if !resp.Scoped {
+ fmt.Println("main")
+ return
+ }
+ if scope, ok := resp.Current.(map[string]any); ok {
+ frameID, _ := scope["frameId"].(string)
+ name, _ := scope["name"].(string)
+ if name != "" {
+ fmt.Printf("%s (%s)\n", frameID, name)
+ } else {
+ fmt.Println(frameID)
+ }
+ } else if s, ok := resp.Current.(string); ok {
+ fmt.Println(s)
+ }
return
}
@@ -23,5 +55,23 @@ func Frame(client *http.Client, base, token string, args []string, cmd *cobra.Co
if tabID != "" {
body["tabId"] = tabID
}
- apiclient.DoPost(client, base, token, "/frame", body)
+ if jsonOutput {
+ apiclient.DoPost(client, base, token, "/frame", body)
+ return
+ }
+
+ result := apiclient.DoPostQuiet(client, base, token, "/frame", body)
+ if scoped, ok := result["scoped"].(bool); ok && !scoped {
+ fmt.Println("main")
+ return
+ }
+ if scope, ok := result["current"].(map[string]any); ok {
+ frameID, _ := scope["frameId"].(string)
+ name, _ := scope["name"].(string)
+ if name != "" {
+ fmt.Printf("%s (%s)\n", frameID, name)
+ } else {
+ fmt.Println(frameID)
+ }
+ }
}
diff --git a/internal/cli/actions/actions_network.go b/internal/cli/actions/actions_network.go
index 77b8f71e..04e09c3a 100644
--- a/internal/cli/actions/actions_network.go
+++ b/internal/cli/actions/actions_network.go
@@ -2,6 +2,7 @@ package actions
import (
"bufio"
+ "encoding/json"
"fmt"
"net/http"
"net/url"
@@ -54,7 +55,37 @@ func Network(client *http.Client, base, token string, cmd *cobra.Command, args [
if v, _ := cmd.Flags().GetString("buffer-size"); v != "" {
params.Set("bufferSize", v)
}
- apiclient.DoGet(client, base, token, "/network", params)
+
+ jsonOutput, _ := cmd.Flags().GetBool("json")
+ if jsonOutput {
+ apiclient.DoGet(client, base, token, "/network", params)
+ return
+ }
+
+ body := apiclient.DoGetRaw(client, base, token, "/network", params)
+ var resp struct {
+ Count int `json:"count"`
+ Entries []struct {
+ Method string `json:"method"`
+ Status int `json:"status"`
+ URL string `json:"url"`
+ } `json:"entries"`
+ }
+ if err := json.Unmarshal(body, &resp); err != nil {
+ fmt.Println(string(body))
+ return
+ }
+ if resp.Count == 0 {
+ fmt.Println("No requests captured")
+ return
+ }
+ for _, e := range resp.Entries {
+ truncURL := e.URL
+ if len(truncURL) > 80 {
+ truncURL = truncURL[:77] + "..."
+ }
+ fmt.Printf("%-6s %3d %s\n", e.Method, e.Status, truncURL)
+ }
}
// NetworkDetail shows full details for a specific request.
diff --git a/internal/cli/output/format.go b/internal/cli/output/format.go
index 79a4620f..baebc1db 100644
--- a/internal/cli/output/format.go
+++ b/internal/cli/output/format.go
@@ -47,10 +47,10 @@ func JSON(v any) {
// Exit codes per the spec.
const (
- ExitSuccess = 0
- ExitUsage = 1 // bad flags, missing arg
- ExitRuntime = 2 // server returned non-2xx
- ExitNotFound = 3 // ref/selector didn't resolve
- ExitTimeout = 4 // wait/nav exceeded budget
- ExitIDPIBlocked = 5 // blocked by IDPI
+ ExitSuccess = 0
+ ExitUsage = 1 // bad flags, missing arg
+ ExitRuntime = 2 // server returned non-2xx
+ ExitNotFound = 3 // ref/selector didn't resolve
+ ExitTimeout = 4 // wait/nav exceeded budget
+ ExitIDPIBlocked = 5 // blocked by IDPI
)
diff --git a/tests/e2e/scenarios/cli/tabs-extended.sh b/tests/e2e/scenarios/cli/tabs-extended.sh
index b355fcf4..bc26746f 100644
--- a/tests/e2e/scenarios/cli/tabs-extended.sh
+++ b/tests/e2e/scenarios/cli/tabs-extended.sh
@@ -47,7 +47,7 @@ end_test
start_test "pinchtab tab (list)"
pt_ok nav "${FIXTURES_URL}/form.html"
-pt_ok tab
+pt_ok tab --json
assert_output_json
end_test
@@ -55,7 +55,7 @@ end_test
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab tab returns valid JSON array"
-pt_ok tab
+pt_ok tab --json
assert_output_json "tabs output is valid JSON"
assert_output_contains "tabs" "response contains tabs field"