High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: clear stale annotate overlay on empty refresh, 400 on bad selector, wire shared --tab flag
Luigi Agosti4adcc2280271
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.goindex 40d530f1..c24ec6b7 100644--- a/cmd/pinchtab/cmd_cli_register.go+++ b/cmd/pinchtab/cmd_cli_register.go@@ -120,7 +120,6 @@ func configureBrowserFlags() {_ = screenshotCmd.Flags().MarkDeprecated("css-1x", "css-1x was removed; use --scale to rescale output")annotateCmd.Flags().StringP("selector", "s", "", "Scope the overlay to elements within this selector (ref/CSS/XPath/text)")- annotateCmd.Flags().String("tab", "", "Tab ID")annotateCmd.Flags().Bool("clear", false, "Remove the persistent annotation overlay instead of injecting it")captureCmd.Flags().StringP("output", "o", "", "Save the captured image to this local file path (default: capture-<ts>.jpg)")@@ -213,6 +212,7 @@ func configureBrowserFlags() {snapCmd,frameCmd,screenshotCmd,+ annotateCmd,pdfCmd,findCmd,textCmd,diff --git a/internal/cdptk/annotate_interactive.go b/internal/cdptk/annotate_interactive.goindex 26f57e5c..f95efd1f 100644--- a/internal/cdptk/annotate_interactive.go+++ b/internal/cdptk/annotate_interactive.go@@ -167,7 +167,10 @@ const interactiveOverlayScript = `(function(items, rootId) {// via RemoveInteractiveOverlay.func InjectInteractiveOverlay(ctx context.Context, items []AnnotationItem) error {if len(items) == 0 {- return nil+ // A refresh that finds nothing to annotate must still clear any prior+ // overlay — otherwise re-running annotate on a page (or --selector scope)+ // with no annotatable elements leaves the previous page's boxes on screen.+ return RemoveInteractiveOverlay(ctx)}type overlayItem struct {Ref string `json:"ref"`diff --git a/internal/handlers/annotate.go b/internal/handlers/annotate.goindex 473ae844..7c5f0368 100644--- a/internal/handlers/annotate.go+++ b/internal/handlers/annotate.go@@ -41,6 +41,16 @@ func (h *Handlers) HandleAnnotate(w http.ResponseWriter, r *http.Request) {return}+ // Validate the selector up front so a bad selector surfaces as a 400 (user+ // error), matching the /screenshot and /capture convention, rather than the+ // generic 500 the collector would otherwise produce.+ if selector != "" {+ if _, sErr := h.resolveSelectorNodeID(tCtx, resolvedTabID, selector); sErr != nil {+ httpx.Error(w, 400, frameScopedSelectorError("selector", sErr))+ return+ }+ }+// Reuse the screenshot annotation collector: it records refs in the tab's// ref cache (so a follow-up `click e5` resolves the same node) and returns// viewport-relative rects. We keep every candidate — not just the visiblediff --git a/tests/e2e/scenarios/api/annotate-basic.sh b/tests/e2e/scenarios/api/annotate-basic.shindex 5fb6b328..f2f54608 100755--- a/tests/e2e/scenarios/api/annotate-basic.sh+++ b/tests/e2e/scenarios/api/annotate-basic.sh@@ -96,6 +96,35 @@ fiend_test+# ─────────────────────────────────────────────────────────────────+start_test "annotate: a zero-result refresh clears the stale overlay"++# Regression: a refresh that finds nothing to annotate must still remove the+# previous overlay, not leave its boxes on screen. Inject first, then re-scope+# to a subtree with no interactive elements (the first <label>, which has no+# interactive descendants) and assert the count is zero AND the overlay is gone.+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\"}"+pt_get "/annotate"+assert_ok "annotate inject before zero-result refresh"++pt_get "/annotate?selector=label"+assert_ok "annotate zero-result refresh"+assert_result_eq '.annotated' '0' 'zero-result scope reports annotated=0'++pt_post /evaluate -d "{\"expression\":\"document.getElementById('${OVERLAY_ID}') === null\"}"+assert_ok "evaluate stale-overlay probe"+assert_result_eq '.result' 'true' 'stale overlay removed on zero-result refresh'++end_test++# ─────────────────────────────────────────────────────────────────+start_test "annotate: bad selector is a 400, not a 500"++pt_get "/annotate?selector=%23definitely-not-here"+assert_http_status "400" "bad selector returns 400"++end_test+# ─────────────────────────────────────────────────────────────────start_test "annotate: clear removes the overlay"