Skip to content

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

fix(snapshot): honour the documented interactive alias instead of ignoring it

Luigi Agosti5c7c5de42628
diff --git a/docs/endpoints.md b/docs/endpoints.md
index 7ed4934e..7d9eaba1 100644
--- a/docs/endpoints.md
+++ b/docs/endpoints.md
@@ -174,6 +174,15 @@ or `interactive`; `maxTokens` is a positive whole number; `depth` is a whole num
tree, because the comparison was an exact string match, and every one of these controls used
to fail toward the *more expensive* answer without telling the caller.
+`interactive` is the documented boolean alias for `filter`: `interactive=true` is
+`filter=interactive`, `interactive=false` is `filter=all`. It takes the values Go's
+`ParseBool` accepts (`true`/`false`, `1`/`0`, `t`/`f`), and anything else is a `400` rather
+than a fall-through to the whole tree. Sending both is fine while they agree; `filter=all`
+next to `interactive=true` is refused, because resolving that by a precedence rule the
+caller cannot see would mean one of the two parameters it sent did nothing. The alias was
+advertised on this endpoint for a long time without ever being read, so a raw HTTP caller
+that followed the docs bought the full tree and was told nothing.
+
An unknown parameter NAME is reported rather than refused: `ignoredParams` on JSON and YAML
responses, an `# ignored params: ...` line on `compact` and `text` ones. `/action` can
refuse because its parameter set is the action request's own fields, and a caller sending
@@ -253,8 +262,8 @@ Selector lookup is limited to the current frame scope. The default scope is `mai
Snapshot query parameters:
-- `interactive`
-- `compact`
+- `filter`
+- `interactive` (boolean alias for `filter`)
- `diff`
- `selector`
- `maxTokens`
diff --git a/docs/reference/snapshot.md b/docs/reference/snapshot.md
index c5a1c910..871eaf51 100644
--- a/docs/reference/snapshot.md
+++ b/docs/reference/snapshot.md
@@ -46,7 +46,8 @@ pinchtab snap --max-tokens 2000 # Limit output size
| Parameter | Description |
|-----------|-------------|
-| `filter` | `interactive` for interactive + headings |
+| `filter` | `interactive` for interactive + headings, `all` (default) for the whole tree |
+| `interactive` | Boolean alias for `filter`: `true` is `filter=interactive`, `false` is `filter=all`. Contradicting an explicit `filter` is a 400 |
| `format` | `compact`, `text`, `yaml`, or default JSON. The CLI and the MCP tool both ask for `compact`; the HTTP default is unchanged |
| `diff` | `true` for diff mode |
| `selector` | CSS selector to scope |
diff --git a/docs/reference/tabs.md b/docs/reference/tabs.md
index be98971a..53b1be72 100644
--- a/docs/reference/tabs.md
+++ b/docs/reference/tabs.md
@@ -134,7 +134,7 @@ pinchtab nav https://pinchtab.com --tab <tabId>
### Snapshot
```bash
-curl "http://localhost:9867/tabs/<tabId>/snapshot?interactive=true&compact=true"
+curl "http://localhost:9867/tabs/<tabId>/snapshot?filter=interactive&format=compact"
# CLI Alternative
pinchtab snap --tab <tabId> -i -c
```
diff --git a/internal/handlers/snapshot.go b/internal/handlers/snapshot.go
index c1d15f62..b6b19396 100644
--- a/internal/handlers/snapshot.go
+++ b/internal/handlers/snapshot.go
@@ -25,6 +25,7 @@ import (
//
// @Param tabId string query Tab ID (required)
// @Param filter string query Filter type: "interactive" for clickable/inputs only, "all" for everything (optional, default: "all")
+// @Param interactive bool query Alias for filter: true means filter=interactive, false means filter=all; a value contradicting an explicit filter is a 400 (optional)
// @Param depth int query Max nesting depth (optional, default: -1 for full tree)
// @Param maxTokens int query Token budget for the response (optional, positive)
// @Param format string query Output format: "json", "compact", "text" or "yaml" (optional, default: "json")
diff --git a/internal/handlers/snapshot_params.go b/internal/handlers/snapshot_params.go
index a57774fc..ae8a5f8e 100644
--- a/internal/handlers/snapshot_params.go
+++ b/internal/handlers/snapshot_params.go
@@ -15,7 +15,10 @@ import (
var snapshotFormats = []string{"json", "compact", "text", "yaml"}
// snapshotFilters are the node subsets /snapshot can return. "all" and the empty string
-// both mean the whole tree; bridge.FilterInteractive is the only value that narrows it.
+// both mean the whole tree; bridge.FilterInteractive is the only value that narrows it. The
+// boolean `interactive` parameter is an alias: true selects bridge.FilterInteractive, false
+// the whole tree, and a value that contradicts an explicit `filter` is refused rather than
+// resolved by precedence the caller cannot see.
var snapshotFilters = []string{"all", bridge.FilterInteractive}
// snapshotKnownParams is every query parameter HandleSnapshot reads. A parameter absent
@@ -29,6 +32,7 @@ var snapshotKnownParams = map[string]bool{
// somewhere else still gets reported as ignored if this set only covers one file.
"browser": true,
"filter": true,
+ "interactive": true,
"format": true,
"depth": true,
"maxTokens": true,
@@ -72,16 +76,33 @@ func ParseSnapshotCostControls(q url.Values) (SnapshotCostControls, error) {
controls.Format = format
}
+ filterSet := false
filter := normalizeParam(q.Get("filter"))
if filter != "" {
if !acceptsValue(snapshotFilters, filter) {
return controls, fmt.Errorf("filter must be one of %s (got %q)", joinQuoted(snapshotFilters), q.Get("filter"))
}
+ filterSet = true
if filter == bridge.FilterInteractive {
controls.Filter = filter
}
}
+ if raw := normalizeParam(q.Get("interactive")); raw != "" {
+ want, err := strconv.ParseBool(raw)
+ if err != nil {
+ return controls, fmt.Errorf("interactive must be \"true\" or \"false\" (got %q)", q.Get("interactive"))
+ }
+ aliased := ""
+ if want {
+ aliased = bridge.FilterInteractive
+ }
+ if filterSet && aliased != controls.Filter {
+ return controls, fmt.Errorf("filter=%q and interactive=%q ask for different subsets; send one or the other", q.Get("filter"), q.Get("interactive"))
+ }
+ controls.Filter = aliased
+ }
+
if raw := strings.TrimSpace(q.Get("maxTokens")); raw != "" {
value, err := strconv.Atoi(raw)
if err != nil || value <= 0 {
diff --git a/internal/handlers/snapshot_params_test.go b/internal/handlers/snapshot_params_test.go
index c43a3bdb..7a6bc6a3 100644
--- a/internal/handlers/snapshot_params_test.go
+++ b/internal/handlers/snapshot_params_test.go
@@ -159,11 +159,11 @@ func TestFilterAllIsTheWholeTree(t *testing.T) {
// the normal direction — a newer client sending a parameter an older server has not learned
// — keeps working while a typo stops being invisible.
func TestUnknownParamsAreReportedNotRejected(t *testing.T) {
- got, err := parseQuery(t, "tabId=abc&compact=true&interactive=true&format=compact")
+ got, err := parseQuery(t, "tabId=abc&compact=true&interactve=true&format=compact")
if err != nil {
t.Fatalf("an unknown parameter was rejected; version skew would break: %v", err)
}
- if want := []string{"compact", "interactive"}; !equalStrings(got.Ignored, want) {
+ if want := []string{"compact", "interactve"}; !equalStrings(got.Ignored, want) {
t.Errorf("ignored = %v, want %v — this is the disclosure that would have caught `compact=true` in the CLI", got.Ignored, want)
}
if got.Format != "compact" {
@@ -171,12 +171,96 @@ func TestUnknownParamsAreReportedNotRejected(t *testing.T) {
}
}
+// `interactive` is documented on /snapshot as the boolean alias for filter=interactive, and
+// a shipped example still sends it. It was advertised without ever being read, so a raw HTTP
+// caller that followed the docs paid for the whole tree and was told nothing. The alias has
+// to be honoured on the wire, not merely disclosed as ignored.
+func TestInteractiveAliasSelectsTheInteractiveSubset(t *testing.T) {
+ for _, tc := range []struct {
+ query string
+ want string
+ }{
+ {query: "tabId=abc&interactive=true", want: bridge.FilterInteractive},
+ {query: "tabId=abc&interactive=TRUE", want: bridge.FilterInteractive},
+ {query: "tabId=abc&interactive=+true+", want: bridge.FilterInteractive},
+ {query: "tabId=abc&interactive=1", want: bridge.FilterInteractive},
+ {query: "tabId=abc&interactive=false", want: ""},
+ {query: "tabId=abc&interactive=0", want: ""},
+ {query: "tabId=abc&interactive=", want: ""},
+ {query: "tabId=abc&filter=interactive&interactive=true", want: bridge.FilterInteractive},
+ {query: "tabId=abc&filter=all&interactive=false", want: ""},
+ } {
+ t.Run(tc.query, func(t *testing.T) {
+ got, err := parseQuery(t, tc.query)
+ if err != nil {
+ t.Fatalf("the documented alias was rejected: %v", err)
+ }
+ if got.Filter != tc.want {
+ t.Errorf("filter = %q, want %q — the alias resolved to the wrong subset", got.Filter, tc.want)
+ }
+ if len(got.Ignored) != 0 {
+ t.Errorf("ignored = %v, but interactive is a parameter the server reads", got.Ignored)
+ }
+ })
+ }
+}
+
+// A bad alias value must fail the same way every other cost control does. Falling through to
+// the whole tree is the exact failure this parser exists to end: `interactive=yes` would
+// otherwise buy the expensive answer silently.
+func TestInteractiveAliasRefusesValuesItCannotRead(t *testing.T) {
+ for _, query := range []string{
+ "interactive=yes",
+ "interactive=on",
+ "interactive=interactive",
+ "interactive=2",
+ } {
+ t.Run(query, func(t *testing.T) {
+ _, err := parseQuery(t, query)
+ if err == nil {
+ t.Fatalf("%s was accepted; a caller that mistyped the alias silently gets the whole tree", query)
+ }
+ sent := strings.SplitN(query, "=", 2)[1]
+ if !strings.Contains(err.Error(), sent) {
+ t.Errorf("the rejection does not quote the offending value %q: %v", sent, err)
+ }
+ for _, want := range []string{"interactive", "true", "false"} {
+ if !strings.Contains(err.Error(), want) {
+ t.Errorf("the rejection does not name %q, so the caller cannot tell what to send instead: %v", want, err)
+ }
+ }
+ })
+ }
+}
+
+// An alias only stays honest while it cannot disagree with the thing it aliases. Picking a
+// winner by precedence would mean one of the two parameters the caller sent did nothing,
+// which is the silence this endpoint stopped keeping.
+func TestFilterAndInteractiveMayNotContradictEachOther(t *testing.T) {
+ for _, query := range []string{
+ "filter=all&interactive=true",
+ "filter=interactive&interactive=false",
+ } {
+ t.Run(query, func(t *testing.T) {
+ _, err := parseQuery(t, query)
+ if err == nil {
+ t.Fatalf("%s was accepted, so one of the two parameters was silently discarded", query)
+ }
+ for _, want := range []string{"filter", "interactive"} {
+ if !strings.Contains(err.Error(), want) {
+ t.Errorf("the rejection does not name %q, so the caller cannot tell which pair conflicts: %v", want, err)
+ }
+ }
+ })
+ }
+}
+
// The failure this guard exists for is a parameter the request path DOES read being
// reported as ignored: `browser` is consumed by the routing prelude rather than by
// HandleSnapshot, so a known-params set derived from one file alone gets it wrong and every
// browser-routed call grows a false disclosure.
func TestParamsTheRequestPathReadsAreNotReportedAsIgnored(t *testing.T) {
- got, err := parseQuery(t, "tabId=abc&browser=chrome&filter=interactive&format=compact&depth=3&maxTokens=500&diff=true&noAnimations=true&selector=%23main&output=file&path=out.txt")
+ got, err := parseQuery(t, "tabId=abc&browser=chrome&filter=interactive&interactive=true&format=compact&depth=3&maxTokens=500&diff=true&noAnimations=true&selector=%23main&output=file&path=out.txt")
if err != nil {
t.Fatal(err)
}
@@ -185,11 +269,13 @@ func TestParamsTheRequestPathReadsAreNotReportedAsIgnored(t *testing.T) {
}
}
-var queryGetPattern = regexp.MustCompile(`Query\(\)\.Get\("([^"]+)"\)`)
+var queryGetPattern = regexp.MustCompile(`\.Get\("([^"]+)"\)`)
-// snapshotPathSources are the files whose Query().Get calls can run for a /snapshot
-// request. Listed rather than derived because the call graph decides membership.
-var snapshotPathSources = []string{"snapshot.go", "read_prelude.go"}
+// snapshotPathSources are the files whose query reads can run for a /snapshot request.
+// Listed rather than derived because the call graph decides membership. snapshot_params.go
+// is on it because that is where the cost controls moved: a scan of the handler alone would
+// no longer see `filter`, `format`, `depth`, `maxTokens` or the `interactive` alias at all.
+var snapshotPathSources = []string{"snapshot.go", "read_prelude.go", "snapshot_params.go"}
// notOnTheSnapshotPath are parameters those files read from a function /snapshot never
// calls. They belong OUT of snapshotKnownParams: /snapshot genuinely ignores them, so
@@ -206,6 +292,7 @@ var notOnTheSnapshotPath = map[string]string{
func TestKnownParamsCoversEveryParamTheHandlerReads(t *testing.T) {
var missing []string
seen := 0
+ reported := map[string]bool{}
exemptionsUsed := map[string]bool{}
for _, name := range snapshotPathSources {
body, err := os.ReadFile(filepath.Join(".", name))
@@ -219,7 +306,8 @@ func TestKnownParamsCoversEveryParamTheHandlerReads(t *testing.T) {
exemptionsUsed[param] = true
continue
}
- if !snapshotKnownParams[param] {
+ if !snapshotKnownParams[param] && !reported[name+param] {
+ reported[name+param] = true
missing = append(missing, name+": "+param)
}
}
@@ -255,9 +343,11 @@ func equalStrings(got, want []string) bool {
type snapshotStubBridge struct {
*mockBridge
+ gotFilter string
}
-func (b *snapshotStubBridge) Snapshot(context.Context, string, string, bridge.ContentParams) (*bridge.SnapshotResult, error) {
+func (b *snapshotStubBridge) Snapshot(_ context.Context, _ string, filter string, _ bridge.ContentParams) (*bridge.SnapshotResult, error) {
+ b.gotFilter = filter
return &bridge.SnapshotResult{
Nodes: []bridge.A11yNode{{Role: "button", Name: "Buy"}},
URL: "http://127.0.0.1:1/fixture",
@@ -269,9 +359,10 @@ func (b *snapshotStubBridge) GetRefCache(string) *bridge.RefCache {
return &bridge.RefCache{Nodes: []bridge.A11yNode{{Role: "link", Name: "Home"}}}
}
-func snapshotBodyFor(t *testing.T, query string) string {
+func serveSnapshot(t *testing.T, query string) (*httptest.ResponseRecorder, *snapshotStubBridge) {
t.Helper()
- h := New(&snapshotStubBridge{mockBridge: &mockBridge{}}, &config.RuntimeConfig{
+ stub := &snapshotStubBridge{mockBridge: &mockBridge{}}
+ h := New(stub, &config.RuntimeConfig{
ActionTimeout: 5 * time.Second,
DefaultBrowser: config.BrowserGhostChrome,
BrowsersAvailable: []string{config.BrowserGhostChrome},
@@ -280,12 +371,61 @@ func snapshotBodyFor(t *testing.T, query string) string {
req := httptest.NewRequest("GET", "/snapshot?"+query, nil)
w := httptest.NewRecorder()
h.HandleSnapshot(w, req)
+ return w, stub
+}
+
+func snapshotBodyFor(t *testing.T, query string) string {
+ t.Helper()
+ w, _ := serveSnapshot(t, query)
if w.Code != http.StatusOK {
t.Fatalf("snapshot?%s: status %d body=%s", query, w.Code, w.Body.String())
}
return w.Body.String()
}
+// The parser resolving the alias is not the same claim as the request path carrying it: the
+// regression this guards is wire-level, so it is checked at the wire.
+func TestTheInteractiveAliasReachesTheBridgeAsAFilter(t *testing.T) {
+ for _, tc := range []struct {
+ query string
+ want string
+ }{
+ {query: "tabId=tab1&interactive=true", want: bridge.FilterInteractive},
+ {query: "tabId=tab1&interactive=false", want: ""},
+ {query: "tabId=tab1&filter=interactive", want: bridge.FilterInteractive},
+ {query: "tabId=tab1", want: ""},
+ } {
+ t.Run(tc.query, func(t *testing.T) {
+ w, stub := serveSnapshot(t, tc.query)
+ if w.Code != http.StatusOK {
+ t.Fatalf("status %d body=%s", w.Code, w.Body.String())
+ }
+ if stub.gotFilter != tc.want {
+ t.Errorf("the bridge was asked for filter %q, want %q — the caller pays for a tree it did not request", stub.gotFilter, tc.want)
+ }
+ if strings.Contains(w.Body.String(), "ignoredParams") {
+ t.Errorf("a parameter the request path honoured was disclosed as ignored:\n%s", w.Body.String())
+ }
+ })
+ }
+}
+
+// A refused cost control has to reach the caller as a 400 naming it, not as an expensive 200.
+func TestContradictoryFilterAndInteractiveAnswer400(t *testing.T) {
+ w, stub := serveSnapshot(t, "tabId=tab1&filter=all&interactive=true")
+ if w.Code != http.StatusBadRequest {
+ t.Fatalf("status %d, want 400: %s", w.Code, w.Body.String())
+ }
+ if stub.gotFilter != "" {
+ t.Errorf("the snapshot was captured anyway (filter %q); a refused request must not be charged", stub.gotFilter)
+ }
+ for _, want := range []string{"filter", "interactive"} {
+ if !strings.Contains(w.Body.String(), want) {
+ t.Errorf("the 400 body does not name %q: %s", want, w.Body.String())
+ }
+ }
+}
+
func jsonEnvelope(t *testing.T, body string) []string {
t.Helper()
return ignoredFromEnvelope(t, body, func(b []byte, v any) error { return json.Unmarshal(b, v) })