High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: on-screen nodes report visible:false on scrolled pages because isVisible is still told the box is document-relative (PIN-039)
Luigi Agosti69c7ab362d6e
diff --git a/internal/bridge/observe/bounds.go b/internal/bridge/observe/bounds.goindex 7fbca5c2..f83dc592 100644--- a/internal/bridge/observe/bounds.go+++ b/internal/bridge/observe/bounds.go@@ -82,7 +82,7 @@ func AnnotateBounds(ctx context.Context, nodes []A11yNode, pageCoords bool, vp Vif !ok {continue}- visible := isVisible(box, true, vp)+ visible := isVisible(box, vp)if pageCoords {box.X += vp.ScrollXbox.Y += vp.ScrollY@@ -159,20 +159,17 @@ func boxModelAABB(ctx context.Context, backendNodeID int64, quad boxQuad) (Boundreturn BoundingBox{X: minX, Y: minY, W: maxX - minX, H: maxY - minY}, true}-func isVisible(b BoundingBox, pageCoords bool, vp ViewportInfo) bool {+// isVisible takes b in viewport coordinates, the space DOM.getBoxModel reports+// and the space AnnotateBounds measures in before any document transform.+func isVisible(b BoundingBox, vp ViewportInfo) bool {if b.W <= 0 || b.H <= 0 {return false}if vp.Width <= 0 || vp.Height <= 0 {- // No viewport info to compare against; fall back to area test only.return true}- var vx, vy float64- if pageCoords {- vx, vy = vp.ScrollX, vp.ScrollY- }- return b.X+b.W > vx &&- b.Y+b.H > vy &&- b.X < vx+vp.Width &&- b.Y < vy+vp.Height+ return b.X+b.W > 0 &&+ b.Y+b.H > 0 &&+ b.X < vp.Width &&+ b.Y < vp.Height}diff --git a/internal/bridge/observe/bounds_test.go b/internal/bridge/observe/bounds_test.goindex 6828164a..54955b01 100644--- a/internal/bridge/observe/bounds_test.go+++ b/internal/bridge/observe/bounds_test.go@@ -11,14 +11,20 @@ import ("github.com/pinchtab/pinchtab/internal/testbrowser")-func TestIsVisibleWithDocumentCoordinates(t *testing.T) {+// The scroll offset must not enter the test: boxes reach isVisible in viewport+// coordinates, so a page scrolled to y=1000 sees the same numbers as an+// unscrolled one.+func TestIsVisibleUsesViewportCoordinates(t *testing.T) {vp := ViewportInfo{Width: 800, Height: 600, ScrollX: 0, ScrollY: 1000}- if !isVisible(BoundingBox{X: 20, Y: 1050, W: 100, H: 40}, true, vp) {- t.Fatal("box inside scrolled viewport should be visible")+ if !isVisible(BoundingBox{X: 20, Y: 50, W: 100, H: 40}, vp) {+ t.Fatal("box inside the viewport should be visible")}- if isVisible(BoundingBox{X: 20, Y: 50, W: 100, H: 40}, true, vp) {- t.Fatal("box above scrolled viewport should not be visible")+ if isVisible(BoundingBox{X: 20, Y: -200, W: 100, H: 40}, vp) {+ t.Fatal("box scrolled above the viewport should not be visible")+ }+ if isVisible(BoundingBox{X: 20, Y: 700, W: 100, H: 40}, vp) {+ t.Fatal("box below the viewport should not be visible")}}@@ -38,6 +44,11 @@ type scrollFixture struct {}func newScrollFixture(t *testing.T, scrollX, scrollY int) scrollFixture {+ t.Helper()+ return newScrollFixtureFrom(t, scrollFixtureHTML, scrollX, scrollY)+}++func newScrollFixtureFrom(t *testing.T, html string, scrollX, scrollY int) scrollFixture {t.Helper()chromePath := testbrowser.Path(t)@@ -56,7 +67,7 @@ func newScrollFixture(t *testing.T, scrollX, scrollY int) scrollFixture {cancelAlloc()})- dataURL := "data:text/html;base64," + base64.StdEncoding.EncodeToString([]byte(scrollFixtureHTML))+ dataURL := "data:text/html;base64," + base64.StdEncoding.EncodeToString([]byte(html))if err := chromedp.Run(ctx,chromedp.Navigate(dataURL),chromedp.WaitVisible("#target", chromedp.ByID),@@ -202,3 +213,30 @@ func TestAnnotateBoundsVisibleIsIndependentOfCoordinateSpace(t *testing.T) {t.Errorf("Visible = %v in viewport space and %v in document space; it is computed from the same viewport-relative box either way", viewportVisible, documentVisible)}}++// onScreenFixtureHTML places the target where a scroll to (300,400) leaves it at+// viewport (50,100) — well inside any default viewport. The existing scroll+// fixture puts its target below the fold, so no test could tell a correct+// Visible from one computed in the wrong coordinate space.+const onScreenFixtureHTML = `<body style="margin:0;width:3000px;height:3000px">+<div style="position:absolute;left:350px;top:500px;width:120px;height:40px">+<button id="target">target</button>+</div>+</body>`++func TestAnnotateBoundsVisibleForOnScreenNodeWhenScrolled(t *testing.T) {+ f := newScrollFixtureFrom(t, onScreenFixtureHTML, 300, 400)++ rect := f.clientRect(t)+ if rect.X < 0 || rect.Y < 0 {+ t.Fatalf("fixture target is not on screen: %+v", rect)+ }++ for _, pageCoords := range []bool{false, true} {+ box, visible, vp := f.annotate(t, pageCoords)+ if !visible {+ t.Errorf("pageCoords=%v: target at viewport %+v in a %.0fx%.0f viewport reported not visible (box %+v)",+ pageCoords, rect, vp.Width, vp.Height, box)+ }+ }+}