Skip to content

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

fix(cli): wait gains --timeout-ms; --timeout kept as a deprecated ms alias that hints at it, ending the bare --timeout unit clash with nav/scrape (PIN-418)

Luigi Agosti3b0a1954f43e
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index 8167d5d4..b8637868 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -376,7 +376,12 @@ func configureBrowserFlags() {
waitCmd.Flags().String("load", "", "Wait for load state (networkidle)")
waitCmd.Flags().String("fn", "", "Wait for JS expression to be truthy")
waitCmd.Flags().String("state", "", "Element state: visible (default) or hidden")
- waitCmd.Flags().Int("timeout", 0, "Timeout in milliseconds (default 10000, max 30000)")
+ waitCmd.Flags().Int("timeout-ms", 0, "Timeout in milliseconds (default 10000, max 30000)")
+ // --timeout on wait is milliseconds, but the same bare flag is SECONDS on
+ // nav/scrape — a 1000x footgun. Keep it for back-compat as a deprecated alias
+ // (still ms); cobra prints its deprecation note pointing at --timeout-ms on use.
+ waitCmd.Flags().Int("timeout", 0, "Deprecated: use --timeout-ms")
+ _ = waitCmd.Flags().MarkDeprecated("timeout", "use --timeout-ms (this flag is milliseconds; bare --timeout means seconds on nav and scrape)")
consoleCmd.Flags().Bool("clear", false, "Clear console logs")
consoleCmd.Flags().String("limit", "", "Maximum entries to return")
diff --git a/internal/cli/actions/actions_wait.go b/internal/cli/actions/actions_wait.go
index c2730279..3a9b1ec1 100644
--- a/internal/cli/actions/actions_wait.go
+++ b/internal/cli/actions/actions_wait.go
@@ -19,9 +19,16 @@ func Wait(client *http.Client, base, token string, args []string, cmd *cobra.Com
loadFlag, _ := cmd.Flags().GetString("load")
fnFlag, _ := cmd.Flags().GetString("fn")
stateFlag, _ := cmd.Flags().GetString("state")
- timeoutFlag, _ := cmd.Flags().GetInt("timeout")
tabID, _ := cmd.Flags().GetString("tab")
+ // The server's /wait timeout is milliseconds. --timeout-ms is the canonical
+ // flag; --timeout is the deprecated millisecond alias (cobra prints its
+ // deprecation note on use). --timeout-ms wins when both are given.
+ timeoutMs, _ := cmd.Flags().GetInt("timeout-ms")
+ if timeoutMs == 0 {
+ timeoutMs, _ = cmd.Flags().GetInt("timeout")
+ }
+
switch {
case textFlag != "":
body["text"] = textFlag
@@ -44,12 +51,12 @@ func Wait(client *http.Client, base, token string, args []string, cmd *cobra.Com
}
}
default:
- fmt.Println("Usage: pinchtab wait <selector|ms> [--text|--not-text|--url|--load|--fn] [--timeout ms] [--tab id]")
+ fmt.Println("Usage: pinchtab wait <selector|ms> [--text|--not-text|--url|--load|--fn] [--timeout-ms ms] [--tab id]")
return
}
- if timeoutFlag > 0 {
- body["timeout"] = timeoutFlag
+ if timeoutMs > 0 {
+ body["timeout"] = timeoutMs
}
path := "/wait"
diff --git a/internal/cli/actions/actions_wait_test.go b/internal/cli/actions/actions_wait_test.go
index f6c910b9..c1860708 100644
--- a/internal/cli/actions/actions_wait_test.go
+++ b/internal/cli/actions/actions_wait_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
+ "io"
"net/http"
"net/http/httptest"
"os"
@@ -23,11 +24,103 @@ func newWaitCmd() *cobra.Command {
cmd.Flags().String("fn", "", "")
cmd.Flags().String("state", "", "")
cmd.Flags().String("tab", "", "")
+ cmd.Flags().Int("timeout-ms", 0, "")
cmd.Flags().Int("timeout", 0, "")
cmd.Flags().Bool("json", false, "")
return cmd
}
+func newNavTimeoutCmd() *cobra.Command {
+ cmd := &cobra.Command{}
+ cmd.Flags().String("tab", "", "")
+ cmd.Flags().Float64("timeout", 0, "")
+ for _, name := range []string{"new-tab", "block-images", "block-ads", "dismiss-banners"} {
+ cmd.Flags().Bool(name, false, "")
+ }
+ return cmd
+}
+
+func newScrapeTimeoutCmd() *cobra.Command {
+ cmd := &cobra.Command{}
+ cmd.Flags().String("format", "json", "")
+ cmd.Flags().String("profile", "", "")
+ cmd.Flags().String("cookies-file", "", "")
+ cmd.Flags().String("output-dir", "", "")
+ cmd.Flags().StringArray("cookie", nil, "")
+ cmd.Flags().StringArray("include", nil, "")
+ cmd.Flags().StringArray("exclude", nil, "")
+ cmd.Flags().StringArray("only", nil, "")
+ cmd.Flags().Int("max-pages", 0, "")
+ cmd.Flags().Int("max-per-pattern", 0, "")
+ cmd.Flags().Int("concurrency", 0, "")
+ cmd.Flags().Int("timeout", 0, "")
+ for _, name := range []string{"enrich-all", "no-browser", "preview", "json"} {
+ cmd.Flags().Bool(name, false, "")
+ }
+ return cmd
+}
+
+// The card's core: the bare --timeout flag meant different units per verb. This
+// pins the unit each verb's timeout flag feeds to the request — wait in
+// milliseconds (via the new --timeout-ms and the deprecated --timeout alias),
+// nav and scrape in seconds — so the 1000x divergence cannot silently return.
+func TestTimeoutFlagUnitsPerVerb(t *testing.T) {
+ var lastBody map[string]any
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ b, _ := io.ReadAll(r.Body)
+ lastBody = nil
+ _ = json.Unmarshal(b, &lastBody)
+ if strings.HasSuffix(r.URL.Path, "/wait") {
+ _ = json.NewEncoder(w).Encode(map[string]any{"waited": true})
+ return
+ }
+ _ = json.NewEncoder(w).Encode(map[string]any{}) // a valid, empty scrape report
+ }))
+ defer srv.Close()
+ base, client := srv.URL, srv.Client()
+
+ t.Run("wait --timeout-ms feeds milliseconds", func(t *testing.T) {
+ cmd := newWaitCmd()
+ _ = cmd.Flags().Set("timeout-ms", "2500")
+ Wait(client, base, "", []string{"#x"}, cmd)
+ if lastBody["timeout"] != float64(2500) {
+ t.Fatalf("wait --timeout-ms 2500 sent timeout=%v, want 2500 (ms)", lastBody["timeout"])
+ }
+ })
+
+ t.Run("wait --timeout (deprecated alias) still feeds milliseconds", func(t *testing.T) {
+ cmd := newWaitCmd()
+ _ = cmd.Flags().Set("timeout", "2500")
+ Wait(client, base, "", []string{"#x"}, cmd)
+ if lastBody["timeout"] != float64(2500) {
+ t.Fatalf("wait --timeout 2500 sent timeout=%v, want 2500 (ms, back-compat)", lastBody["timeout"])
+ }
+ })
+
+ t.Run("nav --timeout feeds seconds", func(t *testing.T) {
+ cmd := newNavTimeoutCmd()
+ _ = cmd.Flags().Set("timeout", "10")
+ req := buildNavigateRequest("http://example.test", cmd)
+ if req.body["timeout"] != float64(10) {
+ t.Fatalf("nav --timeout 10 built timeout=%v, want 10 (seconds)", req.body["timeout"])
+ }
+ })
+
+ t.Run("scrape --timeout feeds seconds on the unit-named key", func(t *testing.T) {
+ cmd := newScrapeTimeoutCmd()
+ _ = cmd.Flags().Set("timeout", "10")
+ if err := Scrape(client, base, "", cmd, "http://example.test"); err != nil {
+ t.Fatalf("Scrape: %v", err)
+ }
+ if lastBody["timeoutSeconds"] != float64(10) {
+ t.Fatalf("scrape --timeout 10 sent timeoutSeconds=%v, want 10 (seconds)", lastBody["timeoutSeconds"])
+ }
+ if _, carriesBareTimeout := lastBody["timeout"]; carriesBareTimeout {
+ t.Errorf("scrape must not send a bare ms-ambiguous timeout key: %v", lastBody)
+ }
+ })
+}
+
const waitChildEnv = "PINCHTAB_TEST_WAIT_MODE"
// runWaitChild serves a /wait response for the case named by mode ("met"/"timeout"