Skip to content

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

docs: correct ElementBorderBox coordinate space and pin it on a scrolled page (PIN-039)

Luigi Agosti372859e12970
diff --git a/internal/bridge/observe/bounds.go b/internal/bridge/observe/bounds.go
index f83dc592..63a96426 100644
--- a/internal/bridge/observe/bounds.go
+++ b/internal/bridge/observe/bounds.go
@@ -97,8 +97,9 @@ func getBoxAABB(ctx context.Context, backendNodeID int64) (BoundingBox, bool) {
return boxModelAABB(ctx, backendNodeID, boxQuadContent)
}
-// ElementBorderBox is the border-box rectangle of a node in document-relative
-// CSS coordinates, the same measurement the capture path uses. It is the
+// ElementBorderBox is the border-box rectangle of a node in viewport-relative
+// CSS coordinates, the space getBoxModel reports and the space /box and
+// ScrollIntoViewAndGetBox hand to their callers unchanged. It is the
// cross-frame-correct alternative to evaluating getBoundingClientRect in the
// element's own context, which is relative to the document the element lives in
// and therefore frame-relative for anything inside an iframe.
diff --git a/internal/bridge/observe/bounds_test.go b/internal/bridge/observe/bounds_test.go
index 54955b01..91656f02 100644
--- a/internal/bridge/observe/bounds_test.go
+++ b/internal/bridge/observe/bounds_test.go
@@ -240,3 +240,29 @@ func TestAnnotateBoundsVisibleForOnScreenNodeWhenScrolled(t *testing.T) {
}
}
}
+
+// ElementBorderBox is the third consumer of the getBoxModel premise, behind
+// /box and ScrollIntoViewAndGetBox, and both hand its numbers to callers
+// unchanged. The premise is only checkable on a scrolled page: at scroll 0 the
+// viewport and document answers are the same number, which is why the existing
+// /box fixture could not tell them apart.
+func TestElementBorderBoxIsViewportRelativeWhenScrolled(t *testing.T) {
+ f := newScrollFixtureFrom(t, onScreenFixtureHTML, 300, 400)
+
+ vp, err := FetchLayout(f.ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if vp.ScrollX == 0 || vp.ScrollY == 0 {
+ t.Fatalf("fixture did not scroll: %+v", vp)
+ }
+
+ box, ok := ElementBorderBox(f.ctx, f.nodeID)
+ if !ok {
+ t.Fatal("ElementBorderBox produced no box for the target")
+ }
+ rect := f.clientRect(t)
+
+ assertNear(t, "border-box x", box.X, rect.X)
+ assertNear(t, "border-box y", box.Y, rect.Y)
+}