Skip to content

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

feat: add beyondViewport screenshot capture

Luigi Agostif845c4ed6215
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index e37c980a..9bbcbeb2 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -242,6 +242,7 @@ func configureBrowserFlags() {
screenshotCmd.Flags().Bool("css-1x", false, "When used with --selector, output image at CSS pixel size instead of device pixels")
screenshotCmd.Flags().Bool("annotate", false, "Overlay numbered ref boxes on interactive elements (or on --selector matches). Prints a [n] ref legend to stdout.")
screenshotCmd.Flags().String("format", "", "Image format: 'jpeg' (default) or 'png'")
+ screenshotCmd.Flags().Bool("beyond-viewport", false, "Capture the entire scrollable document, not just the visible viewport. Ignored when --selector is set.")
pdfCmd.Flags().StringP("output", "o", "", "Save PDF to file path")
pdfCmd.Flags().Bool("landscape", false, "Landscape orientation")
diff --git a/docs/commands.md b/docs/commands.md
index f24c6280..e61dda0e 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -212,6 +212,7 @@ pinchtab screenshot -o <path> # Save screenshot to a chosen path
pinchtab screenshot -q <0-100> # JPEG quality
pinchtab screenshot -s <selector> # Capture a specific element by selector
pinchtab screenshot -s <selector> --css-1x # Export selector screenshot at CSS pixel size
+pinchtab screenshot --beyond-viewport # Capture the full scrollable document (ignored with -s)
pinchtab pdf # Export the active page as PDF
pinchtab pdf -o <path> # Save PDF to a chosen path
pinchtab pdf --landscape # Landscape orientation
diff --git a/docs/reference/cli.md b/docs/reference/cli.md
index 7adafdb3..b06855fd 100644
--- a/docs/reference/cli.md
+++ b/docs/reference/cli.md
@@ -146,7 +146,7 @@ Common commands:
| `pinchtab fill <selector> <text>` | Fill directly |
| `pinchtab text` | Extract page text (`--full`, `--raw`, `--frame <frameId>`) |
| `pinchtab find <query>` | Semantic element search |
-| `pinchtab screenshot` | Save a screenshot (`-s/--selector` captures a specific element, `--css-1x` exports selector shots at CSS size) |
+| `pinchtab screenshot` | Save a screenshot (`-s/--selector` captures a specific element, `--css-1x` exports selector shots at CSS size, `--beyond-viewport` captures the full scrollable document) |
| `pinchtab pdf` | Export the page as PDF |
| `pinchtab network` | Inspect captured network requests |
| `pinchtab wait ...` | Wait for selector, text, URL, JS, or time |
diff --git a/docs/reference/mcp-tools.md b/docs/reference/mcp-tools.md
index 9e30452c..6c84f2c4 100644
--- a/docs/reference/mcp-tools.md
+++ b/docs/reference/mcp-tools.md
@@ -26,7 +26,7 @@ Structured semantic locators are matched by the semantic engine; CSS, XPath, ref
| `pinchtab_navigate` | `url` required, `tabId`, `snap` | Uses `/navigate`; omitting `tabId` opens a new tab. `snap=true` returns an interactive compact snapshot in the same response |
| `pinchtab_snapshot` | `tabId`, `interactive`, `compact`, `format`, `diff`, `selector`, `maxTokens`, `depth`, `noAnimations` | `selector` scopes the snapshot; `format` is limited to `compact` or `text` |
| `pinchtab_frame` | `tabId`, `target` | Get or set the frame scope for selector-based actions on the tab; `target` accepts `main`, a snapshot ref, an iframe selector, or a frame name/URL |
-| `pinchtab_screenshot` | `tabId`, `selector`, `css1x`, `format`, `quality`, `annotate` | `selector` captures a specific element in current frame scope; `css1x=true` exports selector shots at CSS pixel size; `format` is `jpeg` or `png`; `annotate=true` overlays numbered ref boxes and populates the annotations envelope |
+| `pinchtab_screenshot` | `tabId`, `selector`, `css1x`, `format`, `quality`, `annotate`, `beyondViewport` | `selector` captures a specific element in current frame scope; `css1x=true` exports selector shots at CSS pixel size; `format` is `jpeg` or `png`; `annotate=true` overlays numbered ref boxes and populates the annotations envelope; `beyondViewport=true` captures the full scrollable document (ignored when `selector` is set) — box coords are document-relative in that mode |
| `pinchtab_get_text` | `tabId`, `raw`, `format`, `maxChars` | `raw=true` maps to `/text?mode=raw`; `format=text/plain` returns plain text; inherits the current `pinchtab_frame` scope for that tab |
## Interaction
diff --git a/docs/reference/screenshot.md b/docs/reference/screenshot.md
index c4393a0e..44c35970 100644
--- a/docs/reference/screenshot.md
+++ b/docs/reference/screenshot.md
@@ -12,6 +12,9 @@ curl "http://localhost:9867/screenshot?selector=%23checkout-button&raw=true" > b
# Capture element at CSS 1x size (instead of device pixels)
curl "http://localhost:9867/screenshot?selector=%23checkout-button&css1x=true&raw=true" > button-1x.jpg
+# Capture the entire scrollable document, not just the visible viewport
+curl "http://localhost:9867/screenshot?beyondViewport=true&raw=true" > fullpage.jpg
+
# Get JSON with base64 JPEG (default)
curl "http://localhost:9867/screenshot"
@@ -38,6 +41,7 @@ curl "http://localhost:9867/screenshot?output=file"
- `quality`: JPEG quality `0-100` (default: `80`). Ignored for PNG.
- `selector`: Unified selector to capture one element (e.g. `e5`, `#id`, `xpath://...`, `text:Submit`).
- `css1x`: `true` to output selector screenshots at CSS pixel size (1x). Ignored when `selector` is omitted.
+- `beyondViewport`: `true` to capture the full scrollable document instead of just the visible viewport. Ignored when `selector` is set. With `annotate=true` the returned box coordinates are document-relative.
- `raw`: `true` to return image bytes directly instead of JSON.
- `output`: `file` to save to state directory.
- `tabId`: Target a specific tab.
@@ -48,6 +52,7 @@ curl "http://localhost:9867/screenshot?output=file"
- `-q <0-100>`: Set JPEG quality.
- `-s <selector>`: Capture a specific element.
- `--css-1x`: With `-s/--selector`, export at CSS 1x size.
+- `--beyond-viewport`: Capture the full scrollable document. Ignored when `--selector` is set.
- `--tab <id>`: Target a specific tab.
## Related Pages
diff --git a/internal/cli/actions/actions_screenshot.go b/internal/cli/actions/actions_screenshot.go
index 4673b6d4..95901311 100644
--- a/internal/cli/actions/actions_screenshot.go
+++ b/internal/cli/actions/actions_screenshot.go
@@ -50,6 +50,9 @@ func Screenshot(client *http.Client, base, token string, cmd *cobra.Command) {
if v, _ := cmd.Flags().GetBool("css-1x"); v {
params.Set("css1x", "true")
}
+ if v, _ := cmd.Flags().GetBool("beyond-viewport"); v {
+ params.Set("beyondViewport", "true")
+ }
if v, _ := cmd.Flags().GetString("tab"); v != "" {
params.Set("tabId", v)
}
diff --git a/internal/handlers/screenshot.go b/internal/handlers/screenshot.go
index 33fc68b5..41a52e6e 100644
--- a/internal/handlers/screenshot.go
+++ b/internal/handlers/screenshot.go
@@ -37,6 +37,13 @@ func (h *Handlers) HandleScreenshot(w http.ResponseWriter, r *http.Request) {
css1x := r.URL.Query().Get("css1x") == "true"
reqNoAnim := r.URL.Query().Get("noAnimations") == "true"
annotate := r.URL.Query().Get("annotate") == "true" || r.URL.Query().Get("annotate") == "1"
+ // beyondViewport captures the full scrollable document. selector wins
+ // silently when both are set — selector already clips to an element, and
+ // stacking a doc-sized clip on top would be meaningless.
+ beyondViewport := r.URL.Query().Get("beyondViewport") == "true" || r.URL.Query().Get("beyondViewport") == "1"
+ if selector != "" {
+ beyondViewport = false
+ }
ctx, resolvedTabID, err := h.tabContext(r, tabID)
if err != nil {
@@ -69,7 +76,7 @@ func (h *Handlers) HandleScreenshot(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("format") == "png" {
fmtStr = "png"
}
- img, items, outFormat, err := h.captureAnnotatedScreenshot(tCtx, resolvedTabID, selector, fmtStr, quality)
+ img, items, outFormat, err := h.captureAnnotatedScreenshot(tCtx, resolvedTabID, selector, fmtStr, quality, beyondViewport)
if err != nil {
httpx.Error(w, 500, fmt.Errorf("annotate: %w", err))
return
@@ -105,6 +112,13 @@ func (h *Handlers) HandleScreenshot(w http.ResponseWriter, r *http.Request) {
httpx.Error(w, 500, fmt.Errorf("selector screenshot: %w", err))
return
}
+ } else if beyondViewport {
+ docW, docH, err := documentSize(tCtx)
+ if err != nil {
+ httpx.Error(w, 500, fmt.Errorf("document size: %w", err))
+ return
+ }
+ clip = &page.Viewport{X: 0, Y: 0, Width: docW, Height: docH, Scale: 1}
}
var buf []byte
@@ -132,6 +146,9 @@ func (h *Handlers) HandleScreenshot(w http.ResponseWriter, r *http.Request) {
if clip != nil {
shot = shot.WithClip(clip)
}
+ if beyondViewport {
+ shot = shot.WithCaptureBeyondViewport(true)
+ }
if format == page.CaptureScreenshotFormatJpeg {
shot = shot.WithQuality(int64(quality))
}
diff --git a/internal/handlers/screenshot_annotate.go b/internal/handlers/screenshot_annotate.go
index b1a63b39..9c74e5a2 100644
--- a/internal/handlers/screenshot_annotate.go
+++ b/internal/handlers/screenshot_annotate.go
@@ -27,6 +27,7 @@ type captureMode int
const (
modeViewport captureMode = iota
modeSelectorClip
+ modeBeyondViewport
)
type annotationItem struct {
@@ -269,25 +270,34 @@ func rectsOverlap(a, b annotationRect) bool {
// projectAnnotationBoxes returns boxes in the coordinate space of the
// returned screenshot. Viewport mode passes the rects through unchanged;
// selector-clip mode subtracts the target origin so boxes are relative to
-// the clipped image.
-func projectAnnotationBoxes(items []annotationItem, target *annotationRect, mode captureMode) []annotationItem {
+// the clipped image; beyond-viewport mode adds the current document scroll
+// because the image origin is the document top-left, not the viewport.
+func projectAnnotationBoxes(items []annotationItem, target *annotationRect, mode captureMode, scrollX, scrollY float64) []annotationItem {
out := make([]annotationItem, len(items))
for i, it := range items {
out[i] = it
- if mode == modeSelectorClip && target != nil {
+ switch {
+ case mode == modeSelectorClip && target != nil:
out[i].Box = annotationRect{
X: roundFloat(it.Box.X - target.X),
Y: roundFloat(it.Box.Y - target.Y),
W: roundFloat(it.Box.W),
H: roundFloat(it.Box.H),
}
- continue
- }
- out[i].Box = annotationRect{
- X: roundFloat(it.Box.X),
- Y: roundFloat(it.Box.Y),
- W: roundFloat(it.Box.W),
- H: roundFloat(it.Box.H),
+ case mode == modeBeyondViewport:
+ out[i].Box = annotationRect{
+ X: roundFloat(it.Box.X + scrollX),
+ Y: roundFloat(it.Box.Y + scrollY),
+ W: roundFloat(it.Box.W),
+ H: roundFloat(it.Box.H),
+ }
+ default:
+ out[i].Box = annotationRect{
+ X: roundFloat(it.Box.X),
+ Y: roundFloat(it.Box.Y),
+ W: roundFloat(it.Box.W),
+ H: roundFloat(it.Box.H),
+ }
}
}
return out
@@ -438,6 +448,7 @@ func (h *Handlers) captureAnnotatedScreenshot(
ctx context.Context,
tabID, selector, format string,
quality int,
+ beyondViewport bool,
) (img []byte, projected []annotationItem, outFormat string, err error) {
items, target, err := h.collectScreenshotAnnotations(ctx, tabID, selector)
if err != nil {
@@ -445,16 +456,35 @@ func (h *Handlers) captureAnnotatedScreenshot(
}
mode := modeViewport
- if target != nil {
+ switch {
+ case target != nil:
mode = modeSelectorClip
+ case beyondViewport:
+ mode = modeBeyondViewport
}
+ // scrollX/scrollY are read once and reused for region shift, clipTopY,
+ // and final box projection so all three stay consistent if the page
+ // scrolls between calls.
+ var scrollX, scrollY float64
+ var docW, docH float64
region := annotationRect{}
- if mode == modeViewport {
+ switch mode {
+ case modeViewport:
region, err = viewportRect(ctx)
if err != nil {
return nil, nil, "", err
}
+ case modeBeyondViewport:
+ docW, docH, err = documentSize(ctx)
+ if err != nil {
+ return nil, nil, "", fmt.Errorf("document size: %w", err)
+ }
+ scrollX, scrollY, _ = pageScroll(ctx)
+ // Item rects are viewport-relative; shift the document rect into the
+ // same space so filterAnnotationItems can keep every element that
+ // lives anywhere inside the captured document.
+ region = annotationRect{X: -scrollX, Y: -scrollY, W: docW, H: docH}
}
items = filterAnnotationItems(items, target, region)
@@ -465,8 +495,14 @@ func (h *Handlers) captureAnnotatedScreenshot(
overlayInjected := false
if len(items) > 0 {
clipTopY := 0.0
- if mode == modeSelectorClip && target != nil {
+ switch {
+ case mode == modeSelectorClip && target != nil:
clipTopY = target.Y
+ case mode == modeBeyondViewport:
+ // Document top in viewport coords. Lets the overlay's "is there
+ // room for a label above the box inside the captured image" check
+ // reduce to "document y >= labelHeight".
+ clipTopY = -scrollY
}
if err := injectAnnotationOverlay(ctx, items, clipTopY); err != nil {
return nil, nil, "", fmt.Errorf("inject overlay: %w", err)
@@ -494,7 +530,8 @@ func (h *Handlers) captureAnnotatedScreenshot(
}
var clip *page.Viewport
- if mode == modeSelectorClip && target != nil {
+ switch {
+ case mode == modeSelectorClip && target != nil:
// Translate viewport rect into page coords for CDP clip.
dpr, _ := devicePixelRatioForAnnotation(ctx)
_ = dpr // CDP clip uses CSS pixels with `scale: 1`.
@@ -509,6 +546,8 @@ func (h *Handlers) captureAnnotatedScreenshot(
Height: target.H,
Scale: 1,
}
+ case mode == modeBeyondViewport:
+ clip = &page.Viewport{X: 0, Y: 0, Width: docW, Height: docH, Scale: 1}
}
if err := chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error {
@@ -516,6 +555,9 @@ func (h *Handlers) captureAnnotatedScreenshot(
if clip != nil {
shot = shot.WithClip(clip)
}
+ if mode == modeBeyondViewport {
+ shot = shot.WithCaptureBeyondViewport(true)
+ }
if cdpFormat == page.CaptureScreenshotFormatJpeg {
shot = shot.WithQuality(int64(quality))
}
@@ -526,7 +568,7 @@ func (h *Handlers) captureAnnotatedScreenshot(
return nil, nil, "", fmt.Errorf("capture: %w", err)
}
- projected = projectAnnotationBoxes(items, target, mode)
+ projected = projectAnnotationBoxes(items, target, mode, scrollX, scrollY)
return img, projected, outFormat, nil
}
@@ -556,6 +598,46 @@ func pageScroll(ctx context.Context) (float64, float64, error) {
return resp.Result.Value.X, resp.Result.Value.Y, nil
}
+// documentSize returns the CSS-pixel scrollable size of the document. Used
+// to clip beyond-viewport captures to the full page content. Mirrors what
+// Puppeteer/Playwright measure for fullPage screenshots — max of
+// documentElement and body across scrollWidth/scrollHeight.
+func documentSize(ctx context.Context) (float64, float64, error) {
+ const fn = `(() => {
+ const d = document;
+ const de = d.documentElement;
+ const b = d.body || de;
+ return {
+ w: Math.max(de.scrollWidth, b.scrollWidth, de.clientWidth, de.offsetWidth),
+ h: Math.max(de.scrollHeight, b.scrollHeight, de.clientHeight, de.offsetHeight)
+ };
+ })()`
+ var raw json.RawMessage
+ if err := chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx, "Runtime.evaluate", map[string]any{
+ "expression": fn,
+ "returnByValue": true,
+ }, &raw)
+ })); err != nil {
+ return 0, 0, err
+ }
+ var resp struct {
+ Result struct {
+ Value struct {
+ W float64 `json:"w"`
+ H float64 `json:"h"`
+ } `json:"value"`
+ } `json:"result"`
+ }
+ if err := json.Unmarshal(raw, &resp); err != nil {
+ return 0, 0, err
+ }
+ if resp.Result.Value.W <= 0 || resp.Result.Value.H <= 0 {
+ return 0, 0, fmt.Errorf("invalid document size (%.0fx%.0f)", resp.Result.Value.W, resp.Result.Value.H)
+ }
+ return resp.Result.Value.W, resp.Result.Value.H, nil
+}
+
// devicePixelRatioForAnnotation kept as a small helper in case callers want
// to scale to image pixels. Annotation boxes themselves stay in CSS pixels.
func devicePixelRatioForAnnotation(ctx context.Context) (float64, error) {
diff --git a/internal/handlers/screenshot_annotate_test.go b/internal/handlers/screenshot_annotate_test.go
index 9e1d907d..4e146175 100644
--- a/internal/handlers/screenshot_annotate_test.go
+++ b/internal/handlers/screenshot_annotate_test.go
@@ -38,7 +38,7 @@ func TestProjectAnnotationBoxes_Viewport(t *testing.T) {
items := []annotationItem{
{Ref: "e1", Box: annotationRect{X: 12.4, Y: 33.6, W: 100, H: 32}},
}
- got := projectAnnotationBoxes(items, nil, modeViewport)
+ got := projectAnnotationBoxes(items, nil, modeViewport, 0, 0)
want := annotationRect{X: 12, Y: 34, W: 100, H: 32}
if !reflect.DeepEqual(got[0].Box, want) {
t.Fatalf("viewport projection = %+v, want %+v", got[0].Box, want)
@@ -50,7 +50,7 @@ func TestProjectAnnotationBoxes_SelectorClipSubtractsOrigin(t *testing.T) {
items := []annotationItem{
{Ref: "e1", Box: annotationRect{X: 110, Y: 130, W: 50, H: 20}},
}
- got := projectAnnotationBoxes(items, &target, modeSelectorClip)
+ got := projectAnnotationBoxes(items, &target, modeSelectorClip, 0, 0)
want := annotationRect{X: 10, Y: 30, W: 50, H: 20}
if !reflect.DeepEqual(got[0].Box, want) {
t.Fatalf("selector projection = %+v, want %+v", got[0].Box, want)
@@ -61,6 +61,39 @@ func TestProjectAnnotationBoxes_SelectorClipSubtractsOrigin(t *testing.T) {
}
}
+func TestProjectAnnotationBoxes_BeyondViewportAddsScroll(t *testing.T) {
+ // Item rect is viewport-relative; scroll offsets convert it into the
+ // document-coord image origin captured by beyondViewport mode.
+ items := []annotationItem{
+ {Ref: "e1", Box: annotationRect{X: 50, Y: -200, W: 100, H: 40}},
+ }
+ got := projectAnnotationBoxes(items, nil, modeBeyondViewport, 25, 500)
+ want := annotationRect{X: 75, Y: 300, W: 100, H: 40}
+ if !reflect.DeepEqual(got[0].Box, want) {
+ t.Fatalf("beyondViewport projection = %+v, want %+v", got[0].Box, want)
+ }
+ if items[0].Box.Y != -200 {
+ t.Fatalf("source mutated: %+v", items[0].Box)
+ }
+}
+
+func TestFilterAnnotationItems_BeyondViewportKeepsOffscreen(t *testing.T) {
+ // Document is 800×3000; viewport is 800×600 scrolled to y=500.
+ // Items live at document y=10 (above viewport) and y=2500 (below viewport).
+ // Both should survive the filter because both fall inside the document.
+ docRegion := annotationRect{X: 0, Y: -500, W: 800, H: 3000} // viewport-rel doc bounds
+ items := []annotationItem{
+ {Ref: "e1", Box: annotationRect{X: 10, Y: -490, W: 100, H: 30}}, // doc y=10
+ {Ref: "e2", Box: annotationRect{X: 10, Y: 2000, W: 100, H: 30}}, // doc y=2500
+ {Ref: "e3", Box: annotationRect{X: 10, Y: 2510, W: 100, H: 30}}, // doc y=3010 — outside doc
+ }
+ src := append([]annotationItem(nil), items...)
+ got := filterAnnotationItems(src, nil, docRegion)
+ if len(got) != 2 || got[0].Ref != "e1" || got[1].Ref != "e2" {
+ t.Fatalf("beyondViewport filter = %+v, want e1+e2", got)
+ }
+}
+
func TestRefLessOrdersByNumber(t *testing.T) {
cases := []struct {
a, b string
diff --git a/internal/handlers/screenshot_test.go b/internal/handlers/screenshot_test.go
index 5ee29da1..d9aef5c5 100644
--- a/internal/handlers/screenshot_test.go
+++ b/internal/handlers/screenshot_test.go
@@ -49,3 +49,15 @@ func TestHandleTabScreenshot_NoTab(t *testing.T) {
t.Errorf("expected 404, got %d", w.Code)
}
}
+
+func TestHandleScreenshot_BeyondViewportRequestParses(t *testing.T) {
+ // Sanity check that the new query param does not blow up parsing — the
+ // handler still bails at the tab lookup because mockBridge is failing.
+ h := New(&mockBridge{failTab: true}, &config.RuntimeConfig{}, nil, nil, nil)
+ req := httptest.NewRequest("GET", "/screenshot?beyondViewport=true", nil)
+ w := httptest.NewRecorder()
+ h.HandleScreenshot(w, req)
+ if w.Code != http.StatusNotFound {
+ t.Errorf("expected 404, got %d", w.Code)
+ }
+}
diff --git a/internal/mcp/handlers_navigation.go b/internal/mcp/handlers_navigation.go
index 76ea8366..5bbbe568 100644
--- a/internal/mcp/handlers_navigation.go
+++ b/internal/mcp/handlers_navigation.go
@@ -147,6 +147,9 @@ func handleScreenshot(c *Client) func(context.Context, mcp.CallToolRequest) (*mc
if v, ok := optBool(r, "css1x"); ok && v {
q.Set("css1x", "true")
}
+ if v, ok := optBool(r, "beyondViewport"); ok && v {
+ q.Set("beyondViewport", "true")
+ }
annotate := false
if v, ok := optBool(r, "annotate"); ok && v {
q.Set("annotate", "true")
diff --git a/internal/mcp/handlers_navigation_test.go b/internal/mcp/handlers_navigation_test.go
index 7ab3bc2d..255d97cb 100644
--- a/internal/mcp/handlers_navigation_test.go
+++ b/internal/mcp/handlers_navigation_test.go
@@ -192,9 +192,10 @@ func TestHandleScreenshot(t *testing.T) {
defer srv.Close()
r := callTool(t, "pinchtab_screenshot", map[string]any{
- "quality": float64(90),
- "selector": "#hero",
- "css1x": true,
+ "quality": float64(90),
+ "selector": "#hero",
+ "css1x": true,
+ "beyondViewport": true,
}, srv)
text := resultText(t, r)
@@ -207,6 +208,9 @@ func TestHandleScreenshot(t *testing.T) {
if !strings.Contains(text, `"css1x"`) {
t.Errorf("expected css1x query param, got %s", text)
}
+ if !strings.Contains(text, `"beyondViewport"`) {
+ t.Errorf("expected beyondViewport query param, got %s", text)
+ }
}
func TestHandleScreenshotEnvelopeReturnsImage(t *testing.T) {
diff --git a/internal/mcp/tools.go b/internal/mcp/tools.go
index 2b20c15a..9575078b 100644
--- a/internal/mcp/tools.go
+++ b/internal/mcp/tools.go
@@ -30,13 +30,14 @@ func allTools() []mcp.Tool {
mcp.WithString("target", mcp.Description("Frame target: 'main', a snapshot ref, a selector for an iframe element, or a frame name/URL")),
),
mcp.NewTool("pinchtab_screenshot",
- mcp.WithDescription("Take a screenshot of the current page. The result is delivered as an MCP image content block (image/jpeg by default, image/png with format='png') so clients render it directly. The accompanying text block is always a JSON envelope `{\"format\": \"jpeg\"|\"png\", \"annotations\": [...]}` — `annotations` is an empty array by default. With `annotate=true`, the picture has numbered overlay boxes on interactive elements and `annotations` is populated with `[{\"ref\": \"e5\", \"role\": \"button\", \"name\": \"Submit\", \"tag\": \"button\", \"box\": {\"x\": <number>, \"y\": <number>, \"w\": <number>, \"h\": <number>}}, ...]`; the `ref` values reuse the same selectors as pinchtab_click/fill/etc."),
+ mcp.WithDescription("Take a screenshot of the current page. The result is delivered as an MCP image content block (image/jpeg by default, image/png with format='png') so clients render it directly. The accompanying text block is always a JSON envelope `{\"format\": \"jpeg\"|\"png\", \"annotations\": [...]}` — `annotations` is an empty array by default. With `annotate=true`, the picture has numbered overlay boxes on interactive elements and `annotations` is populated with `[{\"ref\": \"e5\", \"role\": \"button\", \"name\": \"Submit\", \"tag\": \"button\", \"box\": {\"x\": <number>, \"y\": <number>, \"w\": <number>, \"h\": <number>}}, ...]`; the `ref` values reuse the same selectors as pinchtab_click/fill/etc. Set `beyondViewport=true` to capture the entire scrollable document instead of the visible viewport."),
mcp.WithString("tabId", mcp.Description("Target tab ID")),
mcp.WithString("selector", mcp.Description("Unified selector. Without annotate it clips the screenshot to the element. With annotate=true it narrows which elements receive overlay boxes (default: all interactive elements).")),
mcp.WithString("format", mcp.Description("Image format: 'jpeg' (default) or 'png'")),
mcp.WithNumber("quality", mcp.Description("JPEG quality 0-100 (only for JPEG format)")),
mcp.WithBoolean("css1x", mcp.Description("When selector is set (without annotate), return element screenshot at CSS pixel size (1x) instead of device pixels")),
mcp.WithBoolean("annotate", mcp.Description("Overlay numbered ref boxes on interactive elements (or on selector matches). Returns the image plus a structured list of {ref, role, name, box}.")),
+ mcp.WithBoolean("beyondViewport", mcp.Description("Capture the entire scrollable document, not just the visible viewport. Box coordinates in the annotations envelope are document-relative when this is true. Ignored when selector is set.")),
),
mcp.NewTool("pinchtab_get_text",
mcp.WithDescription("Extract readable text content from the current page. Inherits the current frame scope for the tab unless no frame is selected."),
diff --git a/skills/pinchtab-mcp/SKILL.md b/skills/pinchtab-mcp/SKILL.md
index 9f97d9ae..d6994cba 100644
--- a/skills/pinchtab-mcp/SKILL.md
+++ b/skills/pinchtab-mcp/SKILL.md
@@ -107,6 +107,7 @@ Returns an MCP image (image/jpeg by default) — clients render it inline. The t
- Add `quality=60` to reduce file size for JPEG screenshots.
- Use `selector="e5"` to capture a specific element instead of the full page.
- Use `annotate=true` to overlay numbered ref boxes and get the matching annotations list.
+- Use `beyondViewport=true` to capture the entire scrollable document (annotation box coords become document-relative). Ignored when `selector` is set.
**When to use screenshots**:
- Visual layout verification (CSS issues, overlapping elements)
diff --git a/skills/pinchtab/SKILL.md b/skills/pinchtab/SKILL.md
index 0d716875..a172dedb 100644
--- a/skills/pinchtab/SKILL.md
+++ b/skills/pinchtab/SKILL.md
@@ -223,7 +223,7 @@ Timeout 10s default, 30s max via `--timeout <ms>`. Prefer `--not-text`/`--state
### Export, debug, verification
```bash
-pinchtab screenshot [-o path.png] [-q <jpeg-quality>] # format by extension
+pinchtab screenshot [-o path.png] [-q <jpeg-quality>] [--beyond-viewport] # format by extension; --beyond-viewport captures the full scrollable page
pinchtab pdf [-o path.pdf] [--landscape]
pinchtab record start out.gif [--fps 5] [--scale 1.0] # .gif/.webm/.mp4; requires security.allowScreencast; .gif works without ffmpeg, .webm/.mp4 need ffmpeg
pinchtab record stop # stop, encode, and save to path given at start
diff --git a/skills/pinchtab/references/api.md b/skills/pinchtab/references/api.md
index 50404b42..21c793b0 100644
--- a/skills/pinchtab/references/api.md
+++ b/skills/pinchtab/references/api.md
@@ -345,6 +345,9 @@ curl "/screenshot?raw=true&quality=50" -o screenshot.jpg
# Returns raw PNG
curl "/screenshot?raw=true&format=png" -o screenshot.png
+
+# Returns raw JPEG of the entire scrollable document (not just the viewport)
+curl "/screenshot?raw=true&beyondViewport=true" -o fullpage.jpg
```
## Recording
diff --git a/skills/pinchtab/references/commands.md b/skills/pinchtab/references/commands.md
index c1f769f1..d2b4cfb1 100644
--- a/skills/pinchtab/references/commands.md
+++ b/skills/pinchtab/references/commands.md
@@ -175,11 +175,14 @@ Capture a screenshot of the current page.
```bash
pinchtab screenshot
-pinchtab screenshot --quality 80 # JPEG at 80%
+pinchtab screenshot --quality 80 # JPEG at 80%
+pinchtab screenshot --beyond-viewport # full scrollable page, not just the viewport
```
> ⚠️ **Quirk:** Use `screenshot` (full word), not `ss` or `shot`.
+`--beyond-viewport` is ignored when `-s/--selector` is set — selectors already clip to an element.
+
### `pinchtab record`
Record browser activity as a video file.
diff --git a/skills/pinchtab/references/mcp.md b/skills/pinchtab/references/mcp.md
index 5a1f86bb..245e90bc 100644
--- a/skills/pinchtab/references/mcp.md
+++ b/skills/pinchtab/references/mcp.md
@@ -53,7 +53,7 @@ All tool names are prefixed with `pinchtab_`.
|------|-------------|
| `pinchtab_navigate` | Navigate to a URL. Required param: `url`. Optional: `tabId`. |
| `pinchtab_snapshot` | Accessibility tree. Optional: `interactive`, `compact`, `format` (`compact` or `text`), `diff`, `selector`, `maxTokens`, `depth`, `noAnimations`, `tabId`. |
-| `pinchtab_screenshot` | Capture screenshot. Optional: `format` (`jpeg` default, `png`), `quality`, `selector`, `css1x`, `annotate`, `tabId`. Returns an MCP image content block (rendered inline by clients) plus a stable JSON text block `{"format", "annotations": [...]}`; `annotations` is `[]` by default and is populated with `{ref, role, name, tag, box {x,y,w,h}}` entries when `annotate=true` so refs in the picture map back to selectors. |
+| `pinchtab_screenshot` | Capture screenshot. Optional: `format` (`jpeg` default, `png`), `quality`, `selector`, `css1x`, `annotate`, `beyondViewport`, `tabId`. Returns an MCP image content block (rendered inline by clients) plus a stable JSON text block `{"format", "annotations": [...]}`; `annotations` is `[]` by default and is populated with `{ref, role, name, tag, box {x,y,w,h}}` entries when `annotate=true` so refs in the picture map back to selectors. `beyondViewport=true` captures the full scrollable page (ignored when `selector` is set) and returns document-relative box coords. |
| `pinchtab_get_text` | Extract readable page text. Optional: `raw`, `format`, `maxChars`, `tabId`. |
### Interaction
diff --git a/tests/e2e/fixtures/tall.html b/tests/e2e/fixtures/tall.html
new file mode 100644
index 00000000..147c1663
--- /dev/null
+++ b/tests/e2e/fixtures/tall.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>E2E Test - Tall Page</title>
+ <style>
+ body { margin: 0; font-family: sans-serif; }
+ #spacer {
+ height: 4000px;
+ background: linear-gradient(to bottom, #ffffff 0%, #888888 50%, #111111 100%);
+ }
+ #top, #bottom { padding: 16px; }
+ </style>
+</head>
+<body>
+ <div id="top">
+ <h1 id="hero">Tall Page Top</h1>
+ <p>Used by beyondViewport screenshot tests. The spacer below is 4000px tall so a full-page capture is unambiguously larger than a viewport-only capture.</p>
+ </div>
+ <div id="spacer"></div>
+ <div id="bottom">
+ <h2 id="footer-heading">Tall Page Bottom</h2>
+ <button id="bottom-btn">Bottom button</button>
+ </div>
+</body>
+</html>
diff --git a/tests/e2e/scenarios/api/files-basic.sh b/tests/e2e/scenarios/api/files-basic.sh
index a085ff49..9b4efe1a 100644
--- a/tests/e2e/scenarios/api/files-basic.sh
+++ b/tests/e2e/scenarios/api/files-basic.sh
@@ -75,6 +75,26 @@ fi
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "screenshot: beyondViewport captures full document"
+
+# tall.html is ~4000px high — much taller than the viewport — so the
+# full-document capture is unambiguously larger than the viewport-only
+# capture. Same size-delta heuristic as the quality test above; avoids
+# needing image-decode tooling in the e2e container.
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/tall.html\"}"
+
+VIEWPORT_SIZE=$(e2e_curl -s "${E2E_SERVER}/screenshot" | wc -c)
+BEYOND_SIZE=$(e2e_curl -s "${E2E_SERVER}/screenshot?beyondViewport=true" | wc -c)
+
+if [ "$BEYOND_SIZE" -gt "$VIEWPORT_SIZE" ]; then
+ pass_assert "beyondViewport ($BEYOND_SIZE bytes) > viewport ($VIEWPORT_SIZE bytes)"
+else
+ fail_assert "beyondViewport ($BEYOND_SIZE) not larger than viewport ($VIEWPORT_SIZE)"
+fi
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "screenshot: output=file"
diff --git a/tests/e2e/scenarios/cli/files-extended.sh b/tests/e2e/scenarios/cli/files-extended.sh
index 16e2d486..19319be9 100644
--- a/tests/e2e/scenarios/cli/files-extended.sh
+++ b/tests/e2e/scenarios/cli/files-extended.sh
@@ -58,6 +58,20 @@ close_capture_tab
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab screenshot --beyond-viewport"
+
+# Captures the full scrollable document. The fixture (tall.html) is
+# deliberately ~4000px tall so the file is unambiguously larger than the
+# viewport-only capture from the previous tests.
+rm -f /tmp/e2e-beyond.jpg
+pt_ok nav "${FIXTURES_URL}/tall.html"
+pt_ok screenshot --beyond-viewport -o /tmp/e2e-beyond.jpg
+assert_file_exists /tmp/e2e-beyond.jpg "beyond-viewport screenshot file created"
+rm -f /tmp/e2e-beyond.jpg
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab pdf -o custom.pdf"