High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(cli): console and errors gain --json printing the structured /console and /errors body once, following the network idiom (PIN-422)
Luigi Agosti471b568e9471
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.goindex b8637868..c905ad0e 100644--- a/cmd/pinchtab/cmd_cli_register.go+++ b/cmd/pinchtab/cmd_cli_register.go@@ -387,6 +387,7 @@ func configureBrowserFlags() {consoleCmd.Flags().String("limit", "", "Maximum entries to return")errorsCmd.Flags().Bool("clear", false, "Clear error logs")errorsCmd.Flags().String("limit", "", "Maximum entries to return")+ addJSONFlag(consoleCmd, errorsCmd)auditCmd.Flags().Bool("sitemap", false, "Treat the URL as a sitemap.xml and audit the discovered pages")auditCmd.Flags().Int("sample-size", 0, "Pages audited per template group, e.g. /products/p1..pN (0 = all pages; deterministic picks)")diff --git a/internal/cli/actions/actions_console.go b/internal/cli/actions/actions_console.goindex f079a647..68680bf3 100644--- a/internal/cli/actions/actions_console.go+++ b/internal/cli/actions/actions_console.go@@ -13,76 +13,59 @@ import ("github.com/spf13/cobra")-// Console displays browser console logs.func Console(client *http.Client, base, token string, cmd *cobra.Command) {if v, _ := cmd.Flags().GetBool("clear"); v {ConsoleClear(client, base, token, cmd)return}-- params := url.Values{}- if v, _ := cmd.Flags().GetString("tab"); v != "" {- params.Set("tabId", v)- }- if v, _ := cmd.Flags().GetString("limit"); v != "" {- params.Set("limit", v)- }-- result := apiclient.DoGetRaw(client, base, token, "/console", params)- if result == nil {- fmt.Fprintln(os.Stderr, "Failed to get console logs")- os.Exit(1)- }-- printConsoleLogs(result)+ readLog(client, base, token, cmd, "/console", "Failed to get console logs", printConsoleLogs)}-// ConsoleClear clears console logs.func ConsoleClear(client *http.Client, base, token string, cmd *cobra.Command) {- params := url.Values{}- if v, _ := cmd.Flags().GetString("tab"); v != "" {- params.Set("tabId", v)- }- result := apiclient.DoPost(client, base, token, "/console/clear?"+params.Encode(), nil)- if result != nil {- fmt.Println("Console logs cleared")- }+ clearLog(client, base, token, cmd, "/console/clear", "Console logs cleared")}-// Errors displays browser error logs.func Errors(client *http.Client, base, token string, cmd *cobra.Command) {if v, _ := cmd.Flags().GetBool("clear"); v {ErrorsClear(client, base, token, cmd)return}+ readLog(client, base, token, cmd, "/errors", "Failed to get error logs", printErrorLogs)+}- params := url.Values{}- if v, _ := cmd.Flags().GetString("tab"); v != "" {- params.Set("tabId", v)- }+func ErrorsClear(client *http.Client, base, token string, cmd *cobra.Command) {+ clearLog(client, base, token, cmd, "/errors/clear", "Error logs cleared")+}++func readLog(client *http.Client, base, token string, cmd *cobra.Command, path, failMsg string, print func([]byte)) {+ params := tabParams(cmd)if v, _ := cmd.Flags().GetString("limit"); v != "" {params.Set("limit", v)}-- result := apiclient.DoGetRaw(client, base, token, "/errors", params)+ if v, _ := cmd.Flags().GetBool("json"); v {+ apiclient.DoGet(client, base, token, path, params)+ return+ }+ result := apiclient.DoGetRaw(client, base, token, path, params)if result == nil {- fmt.Fprintln(os.Stderr, "Failed to get error logs")+ fmt.Fprintln(os.Stderr, failMsg)os.Exit(1)}+ print(result)+}- printErrorLogs(result)+func clearLog(client *http.Client, base, token string, cmd *cobra.Command, path, doneMsg string) {+ if apiclient.DoPost(client, base, token, path+"?"+tabParams(cmd).Encode(), nil) != nil {+ fmt.Println(doneMsg)+ }}-// ErrorsClear clears error logs.-func ErrorsClear(client *http.Client, base, token string, cmd *cobra.Command) {+func tabParams(cmd *cobra.Command) url.Values {params := url.Values{}if v, _ := cmd.Flags().GetString("tab"); v != "" {params.Set("tabId", v)}- result := apiclient.DoPost(client, base, token, "/errors/clear?"+params.Encode(), nil)- if result != nil {- fmt.Println("Error logs cleared")- }+ return params}func printConsoleLogs(data []byte) {diff --git a/internal/cli/actions/actions_console_test.go b/internal/cli/actions/actions_console_test.goindex 39ecaf96..1a18d411 100644--- a/internal/cli/actions/actions_console_test.go+++ b/internal/cli/actions/actions_console_test.go@@ -2,10 +2,16 @@ package actionsimport ("bytes"+ "encoding/json""io"+ "net/http"+ "net/http/httptest""os"+ "reflect""strings""testing"++ "github.com/spf13/cobra")func TestSanitizeTerminalText(t *testing.T) {@@ -76,3 +82,56 @@ func captureStdout(t *testing.T, fn func()) string {}return buf.String()}++func logCommand(t *testing.T, args ...string) *cobra.Command {+ t.Helper()+ cmd := &cobra.Command{Use: "log"}+ cmd.Flags().Bool("clear", false, "")+ cmd.Flags().Bool("json", false, "")+ cmd.Flags().String("tab", "", "")+ cmd.Flags().String("limit", "", "")+ if err := cmd.Flags().Parse(args); err != nil {+ t.Fatalf("parse flags: %v", err)+ }+ return cmd+}++func TestConsoleAndErrors_JSONPrintsBodyOnce(t *testing.T) {+ bodies := map[string]string{+ "/console": `{"tabId":"tab1","console":[{"timestamp":"2026-03-19T12:00:00Z","level":"warning","message":"careful","source":"console-api"}]}`,+ "/errors": `{"tabId":"tab1","errors":[{"timestamp":"2026-03-19T12:00:00Z","message":"boom","url":"https://example.com/a.js","line":2,"column":23,"stack":"ReferenceError: boom"}]}`,+ }+ var hits []string+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ hits = append(hits, r.URL.RequestURI())+ w.Header().Set("Content-Type", "application/json")+ _, _ = io.WriteString(w, bodies[r.URL.Path])+ }))+ defer srv.Close()++ run := map[string]func(*http.Client, string, string, *cobra.Command){"/console": Console, "/errors": Errors}+ for path, action := range run {+ hits = nil+ output := captureStdout(t, func() {+ action(srv.Client(), srv.URL, "", logCommand(t, "--json", "--tab", "tab1", "--limit", "5"))+ })+ var got, want map[string]any+ if err := json.Unmarshal([]byte(output), &got); err != nil {+ t.Fatalf("%s --json output is not one JSON document: %v\n%s", path, err, output)+ }+ _ = json.Unmarshal([]byte(bodies[path]), &want)+ if !reflect.DeepEqual(got, want) {+ t.Errorf("%s --json printed %v, want the response body %v", path, got, want)+ }+ if len(hits) != 1 || !strings.Contains(hits[0], "tabId=tab1") || !strings.Contains(hits[0], "limit=5") {+ t.Errorf("%s --json requests = %v, want one carrying tab and limit", path, hits)+ }+ }++ terse := captureStdout(t, func() {+ Errors(srv.Client(), srv.URL, "", logCommand(t))+ })+ if strings.Contains(terse, "{") || !strings.Contains(terse, "12:00:00 [ERROR] boom") {+ t.Errorf("terse errors output changed: %q", terse)+ }+}diff --git a/plugins/grok/skills/pinchtab/SKILL.md b/plugins/grok/skills/pinchtab/SKILL.mdindex 281803d5..3c00564d 100644--- a/plugins/grok/skills/pinchtab/SKILL.md+++ b/plugins/grok/skills/pinchtab/SKILL.md@@ -248,8 +248,8 @@ pinchtab pdf [-o path.pdf] [--landscape]pinchtab record start out.gif [--fps 5] [--scale 1.0] # .gif/.webm/.mp4; requires security.allowScreencast; .gif works without ffmpeg, .webm/.mp4 need ffmpegpinchtab record stop # stop, encode, and save to path given at startpinchtab record status # check active recording-pinchtab console [--clear] # browser console logs for the tab-pinchtab errors [--clear] # uncaught JS exceptions the page threw+pinchtab console [--clear] [--json] # browser console logs for the tab+pinchtab errors [--clear] [--json] # uncaught JS exceptions the page threw```**When a snapshot looks right but the page does not respond to actions, check `pinchtab errors` (and `pinchtab console`) before retrying.** A script that threw on load leaves the DOM present and the handlers unwired, so clicks land on nothing; the error log is the only channel that says so. A buffer full of errors is the useful answer, not a failed command.diff --git a/plugins/grok/skills/pinchtab/references/commands.md b/plugins/grok/skills/pinchtab/references/commands.mdindex e6feb3e9..a214cd0e 100644--- a/plugins/grok/skills/pinchtab/references/commands.md+++ b/plugins/grok/skills/pinchtab/references/commands.md@@ -221,8 +221,14 @@ Extract readable text from the page.pinchtab textpinchtab text --raw # no formatting cleanuppinchtab text "#main" # text from one element+pinchtab text --markdown # Markdown for article-shaped pages (keeps links, tables)+pinchtab text --markdown --output page.md # write Markdown to a file, print a one-line confirmation```+Prefer `--markdown` for articles, docs and other prose-heavy pages: it preserves+headings, inline links and tables, and `--output` keeps a long page out of the+context window. It cannot be combined with `--full`/`--raw`.+### `pinchtab find <query>`Find elements by text content or CSS selector.@@ -260,6 +266,7 @@ Read the tab's captured browser console logs (`console.log`/`warn`/`error`). Chepinchtab consolepinchtab console --limit 20pinchtab console --clear # empty the buffer instead of reading it+pinchtab console --json # structured entries (level, message, timestamp) for jq```### `pinchtab errors`@@ -268,6 +275,7 @@ Read the tab's **uncaught JavaScript errors** — exceptions the page threw. A s```bashpinchtab errorspinchtab errors --clear # empty the buffer instead of reading it+pinchtab errors --json # structured entries (url, line, column, stack) for jq```A buffer full of errors is the normal, useful case — it is what tells you the page failed, not an error in the command itself.diff --git a/skills/pinchtab/SKILL.md b/skills/pinchtab/SKILL.mdindex 281803d5..3c00564d 100644--- a/skills/pinchtab/SKILL.md+++ b/skills/pinchtab/SKILL.md@@ -248,8 +248,8 @@ pinchtab pdf [-o path.pdf] [--landscape]pinchtab record start out.gif [--fps 5] [--scale 1.0] # .gif/.webm/.mp4; requires security.allowScreencast; .gif works without ffmpeg, .webm/.mp4 need ffmpegpinchtab record stop # stop, encode, and save to path given at startpinchtab record status # check active recording-pinchtab console [--clear] # browser console logs for the tab-pinchtab errors [--clear] # uncaught JS exceptions the page threw+pinchtab console [--clear] [--json] # browser console logs for the tab+pinchtab errors [--clear] [--json] # uncaught JS exceptions the page threw```**When a snapshot looks right but the page does not respond to actions, check `pinchtab errors` (and `pinchtab console`) before retrying.** A script that threw on load leaves the DOM present and the handlers unwired, so clicks land on nothing; the error log is the only channel that says so. A buffer full of errors is the useful answer, not a failed command.diff --git a/skills/pinchtab/references/commands.md b/skills/pinchtab/references/commands.mdindex 2dd05c01..a214cd0e 100644--- a/skills/pinchtab/references/commands.md+++ b/skills/pinchtab/references/commands.md@@ -266,6 +266,7 @@ Read the tab's captured browser console logs (`console.log`/`warn`/`error`). Chepinchtab consolepinchtab console --limit 20pinchtab console --clear # empty the buffer instead of reading it+pinchtab console --json # structured entries (level, message, timestamp) for jq```### `pinchtab errors`@@ -274,6 +275,7 @@ Read the tab's **uncaught JavaScript errors** — exceptions the page threw. A s```bashpinchtab errorspinchtab errors --clear # empty the buffer instead of reading it+pinchtab errors --json # structured entries (url, line, column, stack) for jq```A buffer full of errors is the normal, useful case — it is what tells you the page failed, not an error in the command itself.