High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: a clip with Scale unset is discarded by CDP and returns the full viewport (PIN-051)
Luigi Agostid8fdb283637e
diff --git a/internal/browsers/chrome/instance.go b/internal/browsers/chrome/instance.goindex ceb9e3fb..d4568e5f 100644--- a/internal/browsers/chrome/instance.go+++ b/internal/browsers/chrome/instance.go@@ -53,12 +53,19 @@ func (i *Instance) CaptureScreenshot(ctx context.Context, format string, qualityshot := page.CaptureScreenshot().WithFormat(cdpFormat).WithFromSurface(captureFromSurface(clip))if clip != nil {+ // Scale 0 means native, the contract bridge.ScreenshotOpts states and+ // normalises. CDP does not: it discards a scale-0 clip and returns the+ // whole viewport, which is the defect this path already had once.+ scale := clip.Scale+ if scale == 0 {+ scale = 1+ }shot = shot.WithClip(&page.Viewport{X: clip.X,Y: clip.Y,Width: clip.Width,Height: clip.Height,- Scale: clip.Scale,+ Scale: scale,})}if cdpFormat == page.CaptureScreenshotFormatJpeg && quality > 0 {diff --git a/internal/browsers/chrome/instance_clip_test.go b/internal/browsers/chrome/instance_clip_test.goindex 44de1868..a97309b9 100644--- a/internal/browsers/chrome/instance_clip_test.go+++ b/internal/browsers/chrome/instance_clip_test.go@@ -79,6 +79,22 @@ func TestInstanceCaptureScreenshotHonoursClip(t *testing.T) {}}+// Scale is the one field whose zero value silently reinstates the defect above:+// bridge.ScreenshotOpts documents 0 as native and normalises it, CDP instead+// discards a scale-0 clip and returns the whole viewport. A caller that builds a+// clip without naming a scale gets the full-viewport image back with no error,+// which is why the normalisation is asserted rather than left to the callers who+// happen to set Scale today.+func TestInstanceCaptureScreenshotHonoursClipWithNativeScale(t *testing.T) {+ i, ctx := newClipFixture(t)++ gotW, gotH := captureSize(t, i, ctx, &cdptk.ScreenshotClip{X: 40, Y: 60, Width: 120, Height: 60})++ if gotW != 120 || gotH != 60 {+ t.Errorf("clip with Scale unset captured %dx%d, want 120x60 — scale 0 must mean native, not a discarded clip", gotW, gotH)+ }+}+// The unclipped path keeps reading the view directly, which is why the flag was// hardcoded: screencast polls this method with a nil clip and must not wait on a// compositor frame that an idle headed page never swaps.