Skip to content

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

fix: wire inspect routes through e2e runner path

Luigi Agosti9b95f9a1eed0
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index 03babe4c..5bd3bd6d 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -243,10 +243,10 @@ func configureBrowserFlags() {
htmlCmd.Flags().StringP("selector", "s", "", "Element selector to extract HTML from (ref/CSS/XPath/text)")
htmlCmd.Flags().String("max-chars", "", "Maximum number of HTML characters to return")
htmlCmd.Flags().Bool("json", false, "Output full JSON response instead of just HTML")
- cssCmd.Flags().String("frame", "", "Read computed CSS from a specific iframe by frameId. If unset, uses the tab's active frame scope or top-level document.")
- cssCmd.Flags().StringP("selector", "s", "", "Element selector to extract CSS from (ref/CSS/XPath/text). If omitted, returns computed CSS for the root element.")
- cssCmd.Flags().String("prop", "", "Return only a single computed CSS property")
- cssCmd.Flags().Bool("json", false, "Output full JSON response instead of just CSS")
+ stylesCmd.Flags().String("frame", "", "Read computed styles from a specific iframe by frameId. If unset, uses the tab's active frame scope or top-level document.")
+ stylesCmd.Flags().StringP("selector", "s", "", "Element selector to extract styles from (ref/CSS/XPath/text). If omitted, returns computed styles for the root element.")
+ stylesCmd.Flags().String("prop", "", "Return only a single computed style property")
+ stylesCmd.Flags().Bool("json", false, "Output full JSON response instead of just styles")
navCmd.Flags().Bool("new-tab", false, "Open in new tab")
navCmd.Flags().Bool("block-images", false, "Block image loading")
diff --git a/internal/handlers/frame.go b/internal/handlers/frame.go
index 85c9e984..7dfaa683 100644
--- a/internal/handlers/frame.go
+++ b/internal/handlers/frame.go
@@ -58,9 +58,16 @@ func (h *Handlers) scopeSnapshotNodesByFrame(nodes []bridge.RawAXNode, frameID s
}
func (h *Handlers) resolveSelectorNodeID(ctx context.Context, tabID, raw string) (int64, error) {
+ return h.resolveSelectorNodeIDInFrame(ctx, tabID, raw, "")
+}
+
+func (h *Handlers) resolveSelectorNodeIDInFrame(ctx context.Context, tabID, raw, frameID string) (int64, error) {
sel := selector.Parse(raw)
cache := h.Bridge.GetRefCache(tabID)
- return bridge.ResolveUnifiedSelectorInFrame(ctx, sel, cache, h.selectorFrameID(tabID))
+ if frameID == "" {
+ frameID = h.selectorFrameID(tabID)
+ }
+ return bridge.ResolveUnifiedSelectorInFrame(ctx, sel, cache, frameID)
}
func ownerRefForFrame(cache *bridge.RefCache, frameID string) string {
diff --git a/internal/handlers/inspect.go b/internal/handlers/inspect.go
index c1ecdf1e..ed8bc5c5 100644
--- a/internal/handlers/inspect.go
+++ b/internal/handlers/inspect.go
@@ -34,9 +34,9 @@ type inspectPayload struct {
type inspectKind string
const (
- inspectKindTitle inspectKind = "title"
- inspectKindURL inspectKind = "url"
- inspectKindHTML inspectKind = "html"
+ inspectKindTitle inspectKind = "title"
+ inspectKindURL inspectKind = "url"
+ inspectKindHTML inspectKind = "html"
inspectKindStyles inspectKind = "styles"
)
@@ -202,11 +202,10 @@ func (h *Handlers) inspectByRef(ctx context.Context, tabID, ref string, kind ins
}
func (h *Handlers) inspectBySelector(ctx context.Context, tabID, rawSelector, frameID string, kind inspectKind) (inspectPayload, error) {
- nodeID, err := h.resolveSelectorNodeID(ctx, tabID, rawSelector)
+ nodeID, err := h.resolveSelectorNodeIDInFrame(ctx, tabID, rawSelector, frameID)
if err != nil {
return inspectPayload{}, frameScopedSelectorError("selector", err)
}
- _ = frameID
return inspectByBackendNodeID(ctx, nodeID, kind)
}
diff --git a/internal/routes/routes.go b/internal/routes/routes.go
index b532d4f0..3c130762 100644
--- a/internal/routes/routes.go
+++ b/internal/routes/routes.go
@@ -56,6 +56,10 @@ var coreEndpoints = []Endpoint{
{"POST", "/frame", "Set current frame scope", CapNone, true},
{"GET", "/screenshot", "Page screenshot", CapNone, true},
{"GET", "/text", "Extract page text", CapNone, true},
+ {"GET", "/title", "Read page title", CapNone, true},
+ {"GET", "/url", "Read page URL", CapNone, true},
+ {"GET", "/html", "Read page HTML", CapNone, true},
+ {"GET", "/styles", "Read computed styles", CapNone, true},
{"GET", "/pdf", "Export as PDF (GET)", CapNone, true},
{"POST", "/pdf", "Export as PDF (POST)", CapNone, true},
diff --git a/internal/routes/routes_test.go b/internal/routes/routes_test.go
index 2c6591c6..dfa6acc9 100644
--- a/internal/routes/routes_test.go
+++ b/internal/routes/routes_test.go
@@ -61,6 +61,42 @@ func TestCloseRoutesAreShorthandAndTabScoped(t *testing.T) {
}
}
+func TestInspectRoutesAreShorthandAndTabScoped(t *testing.T) {
+ wantShorthand := map[string]bool{
+ "GET /title": false,
+ "GET /url": false,
+ "GET /html": false,
+ "GET /styles": false,
+ }
+ for _, route := range ShorthandRoutes() {
+ if _, ok := wantShorthand[route]; ok {
+ wantShorthand[route] = true
+ }
+ }
+ for route, ok := range wantShorthand {
+ if !ok {
+ t.Fatalf("ShorthandRoutes() missing %s", route)
+ }
+ }
+
+ wantTabScoped := map[string]bool{
+ "GET /tabs/{id}/title": false,
+ "GET /tabs/{id}/url": false,
+ "GET /tabs/{id}/html": false,
+ "GET /tabs/{id}/styles": false,
+ }
+ for _, route := range TabScopedRoutes() {
+ if _, ok := wantTabScoped[route]; ok {
+ wantTabScoped[route] = true
+ }
+ }
+ for route, ok := range wantTabScoped {
+ if !ok {
+ t.Fatalf("TabScopedRoutes() missing %s", route)
+ }
+ }
+}
+
func TestNoDuplicateRoutes(t *testing.T) {
seen := make(map[string]bool)
for _, ep := range Core() {
diff --git a/tests/e2e/scenarios/api/browser-basic.sh b/tests/e2e/scenarios/api/browser-basic.sh
index 7e487392..893d8c88 100644
--- a/tests/e2e/scenarios/api/browser-basic.sh
+++ b/tests/e2e/scenarios/api/browser-basic.sh
@@ -139,7 +139,7 @@ assert_table_page "$TEXT_RESULT"
end_test
# ─────────────────────────────────────────────────────────────────
-start_test "inspect html/css: GET /tabs/{id}/html and /tabs/{id}/styles"
+start_test "inspect html/styles: GET /tabs/{id}/html and /tabs/{id}/styles"
pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"
assert_ok "navigate to table page"