Skip to content

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

refactor: rename inspect css to styles

Boschc7d6ab201885
diff --git a/cmd/pinchtab/cmd_cli_browser_inspect.go b/cmd/pinchtab/cmd_cli_browser_inspect.go
index 4066a816..9d27597e 100644
--- a/cmd/pinchtab/cmd_cli_browser_inspect.go
+++ b/cmd/pinchtab/cmd_cli_browser_inspect.go
@@ -100,13 +100,13 @@ var htmlCmd = &cobra.Command{
},
}
-var cssCmd = &cobra.Command{
- Use: "css [selector]",
- Short: "Get computed CSS for the root element or a matched element",
+var stylesCmd = &cobra.Command{
+ Use: "styles [selector]",
+ Short: "Get computed styles for the root element or a matched element",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runCLI(func(rt cliRuntime) {
- browseractions.CSS(rt.client, rt.base, rt.token, cmd, args)
+ browseractions.Styles(rt.client, rt.base, rt.token, cmd, args)
})
},
}
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index d9515731..03babe4c 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -41,7 +41,7 @@ func registerBrowserCommands() {
titleCmd,
urlCmd,
htmlCmd,
- cssCmd,
+ stylesCmd,
downloadCmd,
uploadCmd,
findCmd,
@@ -106,7 +106,7 @@ func registerBrowserCommands() {
titleCmd,
urlCmd,
htmlCmd,
- cssCmd,
+ stylesCmd,
downloadCmd,
uploadCmd,
findCmd,
@@ -286,7 +286,7 @@ func configureBrowserFlags() {
titleCmd,
urlCmd,
htmlCmd,
- cssCmd,
+ stylesCmd,
clickCmd,
dblclickCmd,
hoverCmd,
diff --git a/internal/cli/actions/actions_inspect.go b/internal/cli/actions/actions_inspect.go
index dfe2092a..4b027ff4 100644
--- a/internal/cli/actions/actions_inspect.go
+++ b/internal/cli/actions/actions_inspect.go
@@ -51,26 +51,26 @@ func HTML(client *http.Client, base, token string, cmd *cobra.Command, args []st
})
}
-func CSS(client *http.Client, base, token string, cmd *cobra.Command, args []string) {
- inspectGet(client, base, token, "/css", cmd, args, func(body []byte) {
+func Styles(client *http.Client, base, token string, cmd *cobra.Command, args []string) {
+ inspectGet(client, base, token, "/styles", cmd, args, func(body []byte) {
var result struct {
- CSS map[string]any `json:"css"`
+ Styles map[string]any `json:"styles"`
}
if err := json.Unmarshal(body, &result); err != nil {
output.Value(string(body))
return
}
if prop, _ := cmd.Flags().GetString("prop"); prop != "" {
- if v, ok := result.CSS[prop]; ok {
+ if v, ok := result.Styles[prop]; ok {
output.Value(fmt.Sprint(v))
return
}
output.Value("")
return
}
- pretty, err := json.MarshalIndent(result.CSS, "", " ")
+ pretty, err := json.MarshalIndent(result.Styles, "", " ")
if err != nil {
- output.Value(fmt.Sprint(result.CSS))
+ output.Value(fmt.Sprint(result.Styles))
return
}
output.Value(string(pretty))
diff --git a/internal/cli/actions/actions_inspect_test.go b/internal/cli/actions/actions_inspect_test.go
index ba219bea..93beb972 100644
--- a/internal/cli/actions/actions_inspect_test.go
+++ b/internal/cli/actions/actions_inspect_test.go
@@ -82,18 +82,18 @@ func TestHTML_UsesRefForRefSelector(t *testing.T) {
}
}
-func TestCSS_WithPropAndTab(t *testing.T) {
+func TestStyles_WithPropAndTab(t *testing.T) {
m := newMockServer()
- m.response = `{"css":{"display":"block"}}`
+ m.response = `{"styles":{"display":"block"}}`
defer m.close()
cmd := newInspectCmd()
_ = cmd.Flags().Set("tab", "TAB1")
_ = cmd.Flags().Set("prop", "display")
- CSS(m.server.Client(), m.base(), "", cmd, []string{"button.primary"})
+ Styles(m.server.Client(), m.base(), "", cmd, []string{"button.primary"})
- if m.lastPath != "/css" {
- t.Fatalf("expected /css, got %s", m.lastPath)
+ if m.lastPath != "/styles" {
+ t.Fatalf("expected /styles, got %s", m.lastPath)
}
if !strings.Contains(m.lastQuery, "tabId=TAB1") {
t.Fatalf("expected tabId query, got %s", m.lastQuery)
@@ -106,16 +106,16 @@ func TestCSS_WithPropAndTab(t *testing.T) {
}
}
-func TestCSS_WithoutSelectorHitsDocumentCSS(t *testing.T) {
+func TestStyles_WithoutSelectorHitsDocumentStyles(t *testing.T) {
m := newMockServer()
- m.response = `{"css":{"display":"block"}}`
+ m.response = `{"styles":{"display":"block"}}`
defer m.close()
cmd := newInspectCmd()
- CSS(m.server.Client(), m.base(), "", cmd, nil)
+ Styles(m.server.Client(), m.base(), "", cmd, nil)
- if m.lastPath != "/css" {
- t.Fatalf("expected /css, got %s", m.lastPath)
+ if m.lastPath != "/styles" {
+ t.Fatalf("expected /styles, got %s", m.lastPath)
}
if strings.Contains(m.lastQuery, "selector=") || strings.Contains(m.lastQuery, "ref=") {
t.Fatalf("did not expect selector/ref query, got %s", m.lastQuery)
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index f4d976e8..b6f870f3 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -206,7 +206,7 @@ func (h *Handlers) RegisterRoutes(mux *http.ServeMux, doShutdown func()) {
mux.HandleFunc("GET /tabs/{id}/title", h.HandleTabTitle)
mux.HandleFunc("GET /tabs/{id}/url", h.HandleTabURL)
mux.HandleFunc("GET /tabs/{id}/html", h.HandleTabHTML)
- mux.HandleFunc("GET /tabs/{id}/css", h.HandleTabCSS)
+ mux.HandleFunc("GET /tabs/{id}/styles", h.HandleTabStyles)
mux.HandleFunc("GET /tabs/{id}/metrics", h.HandleTabMetrics)
mux.HandleFunc("GET /metrics", h.HandleMetrics)
mux.HandleFunc("GET /snapshot", h.HandleSnapshot)
@@ -221,7 +221,7 @@ func (h *Handlers) RegisterRoutes(mux *http.ServeMux, doShutdown func()) {
mux.HandleFunc("GET /title", h.HandleTitle)
mux.HandleFunc("GET /url", h.HandleURL)
mux.HandleFunc("GET /html", h.HandleHTML)
- mux.HandleFunc("GET /css", h.HandleCSS)
+ mux.HandleFunc("GET /styles", h.HandleStyles)
mux.HandleFunc("GET /openapi.json", h.HandleOpenAPI)
mux.HandleFunc("GET /help", h.HandleOpenAPI) // alias
mux.HandleFunc("POST /navigate", h.HandleNavigate)
diff --git a/internal/handlers/inspect.go b/internal/handlers/inspect.go
index 83d3cdf1..c1ecdf1e 100644
--- a/internal/handlers/inspect.go
+++ b/internal/handlers/inspect.go
@@ -20,15 +20,15 @@ type inspectResponse struct {
URL string `json:"url,omitempty"`
Title string `json:"title,omitempty"`
HTML string `json:"html,omitempty"`
- CSS map[string]any `json:"css,omitempty"`
+ Styles map[string]any `json:"styles,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
type inspectPayload struct {
- Title string `json:"title"`
- URL string `json:"url"`
- HTML string `json:"html,omitempty"`
- CSS map[string]any `json:"css,omitempty"`
+ Title string `json:"title"`
+ URL string `json:"url"`
+ HTML string `json:"html,omitempty"`
+ Styles map[string]any `json:"styles,omitempty"`
}
type inspectKind string
@@ -37,7 +37,7 @@ const (
inspectKindTitle inspectKind = "title"
inspectKindURL inspectKind = "url"
inspectKindHTML inspectKind = "html"
- inspectKindCSS inspectKind = "css"
+ inspectKindStyles inspectKind = "styles"
)
func (h *Handlers) HandleTitle(w http.ResponseWriter, r *http.Request) {
@@ -64,12 +64,12 @@ func (h *Handlers) HandleTabHTML(w http.ResponseWriter, r *http.Request) {
h.forwardInspectTabRoute(w, r, h.HandleHTML)
}
-func (h *Handlers) HandleCSS(w http.ResponseWriter, r *http.Request) {
- h.handleInspect(w, r, inspectKindCSS)
+func (h *Handlers) HandleStyles(w http.ResponseWriter, r *http.Request) {
+ h.handleInspect(w, r, inspectKindStyles)
}
-func (h *Handlers) HandleTabCSS(w http.ResponseWriter, r *http.Request) {
- h.forwardInspectTabRoute(w, r, h.HandleCSS)
+func (h *Handlers) HandleTabStyles(w http.ResponseWriter, r *http.Request) {
+ h.forwardInspectTabRoute(w, r, h.HandleStyles)
}
func (h *Handlers) handleInspect(w http.ResponseWriter, r *http.Request, kind inspectKind) {
@@ -124,12 +124,12 @@ func (h *Handlers) handleInspect(w http.ResponseWriter, r *http.Request, kind in
resp.Truncated = true
}
}
- if kind == inspectKindCSS {
- css := payload.CSS
+ if kind == inspectKindStyles {
+ styles := payload.Styles
if prop := strings.TrimSpace(r.URL.Query().Get("prop")); prop != "" {
- resp.CSS = map[string]any{prop: css[prop]}
+ resp.Styles = map[string]any{prop: styles[prop]}
} else {
- resp.CSS = sortCSSMap(css)
+ resp.Styles = sortCSSMap(styles)
}
}
@@ -158,21 +158,21 @@ func (h *Handlers) inspectDocument(ctx context.Context, frameID string, kind ins
func inspectDocumentExpression(kind inspectKind) string {
switch kind {
- case inspectKindCSS:
+ case inspectKindStyles:
return `(() => {
const doc = document;
const win = doc.defaultView || window;
const root = doc.documentElement || doc.body;
const style = root ? win.getComputedStyle(root) : null;
- const css = {};
+ const styles = {};
if (style) {
- for (const name of style) css[name] = style.getPropertyValue(name);
+ for (const name of style) styles[name] = style.getPropertyValue(name);
}
return {
title: doc.title || "",
url: String(doc.location ? doc.location.href : win.location.href),
html: doc.documentElement ? doc.documentElement.outerHTML : "",
- css
+ styles
};
})()`
default:
@@ -183,7 +183,7 @@ func inspectDocumentExpression(kind inspectKind) string {
title: doc.title || "",
url: String(doc.location ? doc.location.href : win.location.href),
html: doc.documentElement ? doc.documentElement.outerHTML : "",
- css: {}
+ styles: {}
};
})()`
}
@@ -268,18 +268,18 @@ func inspectByBackendNodeID(ctx context.Context, nodeID int64, kind inspectKind)
func inspectFunctionDeclaration(kind inspectKind) string {
switch kind {
- case inspectKindCSS:
+ case inspectKindStyles:
return `function() {
const el = this;
const doc = el.ownerDocument || document;
const win = doc.defaultView || window;
const style = win.getComputedStyle(el);
- const css = {};
- for (const name of style) css[name] = style.getPropertyValue(name);
+ const styles = {};
+ for (const name of style) styles[name] = style.getPropertyValue(name);
return {
title: doc.title || '',
url: String(doc.location ? doc.location.href : win.location.href),
- css,
+ styles,
};
}`
default:
diff --git a/internal/handlers/inspect_test.go b/internal/handlers/inspect_test.go
index b7412099..75185076 100644
--- a/internal/handlers/inspect_test.go
+++ b/internal/handlers/inspect_test.go
@@ -39,21 +39,21 @@ func TestHandleHTML_WithFrame_NoTab(t *testing.T) {
}
}
-func TestHandleCSS_WithSelector_NoTab(t *testing.T) {
+func TestHandleStyles_WithSelector_NoTab(t *testing.T) {
h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{}, nil, nil, nil)
- req := httptest.NewRequest("GET", "/css?selector=button&prop=display", nil)
+ req := httptest.NewRequest("GET", "/styles?selector=button&prop=display", nil)
w := httptest.NewRecorder()
- h.HandleCSS(w, req)
+ h.HandleStyles(w, req)
if w.Code != http.StatusNotFound {
t.Fatalf("expected 404, got %d", w.Code)
}
}
-func TestHandleCSS_WithoutSelector_NoTab(t *testing.T) {
+func TestHandleStyles_WithoutSelector_NoTab(t *testing.T) {
h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{}, nil, nil, nil)
- req := httptest.NewRequest("GET", "/css?prop=display", nil)
+ req := httptest.NewRequest("GET", "/styles?prop=display", nil)
w := httptest.NewRecorder()
- h.HandleCSS(w, req)
+ h.HandleStyles(w, req)
if w.Code != http.StatusNotFound {
t.Fatalf("expected 404, got %d", w.Code)
}
@@ -69,7 +69,7 @@ func TestHandleTabInspect_MissingTabID(t *testing.T) {
{name: "title", fn: h.HandleTabTitle},
{name: "url", fn: h.HandleTabURL},
{name: "html", fn: h.HandleTabHTML},
- {name: "css", fn: h.HandleTabCSS},
+ {name: "styles", fn: h.HandleTabStyles},
}
for _, tc := range cases {
@@ -94,7 +94,7 @@ func TestHandleTabInspect_ForwardsTabID(t *testing.T) {
{name: "title", fn: h.HandleTabTitle},
{name: "url", fn: h.HandleTabURL},
{name: "html", fn: h.HandleTabHTML},
- {name: "css", fn: h.HandleTabCSS},
+ {name: "styles", fn: h.HandleTabStyles},
}
for _, tc := range cases {
@@ -115,7 +115,7 @@ func TestInspectRoutesRegistered(t *testing.T) {
mux := http.NewServeMux()
h.RegisterRoutes(mux, nil)
- paths := []string{"/title", "/url", "/html", "/css", "/tabs/tab1/title", "/tabs/tab1/url", "/tabs/tab1/html", "/tabs/tab1/css"}
+ paths := []string{"/title", "/url", "/html", "/styles", "/tabs/tab1/title", "/tabs/tab1/url", "/tabs/tab1/html", "/tabs/tab1/styles"}
for _, path := range paths {
t.Run(path, func(t *testing.T) {
req := httptest.NewRequest("GET", path, nil)
diff --git a/tests/e2e/fixtures/table.html b/tests/e2e/fixtures/table.html
index 5598c27a..e9707123 100644
--- a/tests/e2e/fixtures/table.html
+++ b/tests/e2e/fixtures/table.html
@@ -8,6 +8,7 @@
table { border-collapse: collapse; width: 100%; max-width: 600px; }
th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }
th { background: #f5f5f5; }
+ .status-active { display: inline-block; font-weight: 600; color: #0a7f39; }
</style>
</head>
<body>
@@ -26,7 +27,7 @@
<td>1</td>
<td>Alice Johnson</td>
- <td>Active</td>
+ <td><span class="status-active">Active</span></td>
</tr>
<tr>
<td>2</td>
diff --git a/tests/e2e/scenarios/api/browser-basic.sh b/tests/e2e/scenarios/api/browser-basic.sh
index 3eb6da09..7e487392 100644
--- a/tests/e2e/scenarios/api/browser-basic.sh
+++ b/tests/e2e/scenarios/api/browser-basic.sh
@@ -138,6 +138,24 @@ assert_table_page "$TEXT_RESULT"
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "inspect html/css: GET /tabs/{id}/html and /tabs/{id}/styles"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"
+assert_ok "navigate to table page"
+TAB_ID=$(get_tab_id)
+
+pt_get "/tabs/${TAB_ID}/html?selector=%23data-table"
+assert_ok "get selected table html"
+assert_json_contains "$RESULT" '.html' '<table id="data-table">'
+assert_json_contains "$RESULT" '.html' 'Alice Johnson'
+
+pt_get "/tabs/${TAB_ID}/styles?selector=%23data-table&prop=display"
+assert_ok "get selected table styles"
+assert_json_eq "$RESULT" '.styles.display' 'table'
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "snapshot: diff mode"
diff --git a/tests/e2e/scenarios/cli/browser-basic.sh b/tests/e2e/scenarios/cli/browser-basic.sh
index 679f168d..dc479012 100644
--- a/tests/e2e/scenarios/cli/browser-basic.sh
+++ b/tests/e2e/scenarios/cli/browser-basic.sh
@@ -160,6 +160,27 @@ assert_output_contains "Welcome" "extracts text from element"
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab title url html styles"
+
+pt_ok nav "${FIXTURES_URL}/table.html"
+TAB_ID=$(echo "$PT_OUT" | tr -d '[:space:]')
+
+pt_ok title --tab "$TAB_ID"
+assert_output_contains "E2E Test - Table" "returns page title"
+
+pt_ok url --tab "$TAB_ID"
+assert_output_contains "table.html" "returns page url"
+
+pt_ok html "#data-table" --tab "$TAB_ID"
+assert_output_contains "<table id=\"data-table\">" "returns selected table html"
+assert_output_contains "Alice Johnson" "html contains table row content"
+
+pt_ok styles ".status-active" --prop display --tab "$TAB_ID"
+assert_output_contains "inline-block" "returns computed display property"
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab text <ref>"
diff --git a/tests/tools/scripts/baseline.sh b/tests/tools/scripts/baseline.sh
index 3d2f0658..b62e97e5 100755
--- a/tests/tools/scripts/baseline.sh
+++ b/tests/tools/scripts/baseline.sh
@@ -228,7 +228,7 @@ NAV "http://fixtures/article.html"
HTML=$(curl -sf "$BASE/html?tabId=$T&selector=article" -H "$AUTH")
echo "$HTML" | grep -q "VERIFY_ARTICLE_PAGE_41414" && REC 15 3 pass "html article marker" || REC 15 3 fail "missing article html marker"
NAV "http://fixtures/pricing.html"
-CSS_DISPLAY=$(curl -sf "$BASE/css?tabId=$T&selector=%23plan-pro&prop=display" -H "$AUTH" | jq -r '.css.display // empty' 2>/dev/null)
+CSS_DISPLAY=$(curl -sf "$BASE/styles?tabId=$T&selector=%23plan-pro&prop=display" -H "$AUTH" | jq -r '.styles.display // empty' 2>/dev/null)
[ "$CSS_DISPLAY" = "flex" ] && REC 15 4 pass "display=flex" || REC 15 4 fail "display=$CSS_DISPLAY"
# Group 16