BlogDebuggingturno-browser
The highlight that landed at twice its place
On a Retina screen, the box Chrome draws on the element the agent acts on showed at twice its position and size. Chrome scales the rectangle it is given, and the tests ran where that scale is 1.
- Shipped in
- Measured
- MethodApple M3 MacBook, macOS 27.2.1, Chrome 158
- Author
- William Monroy
turno-browser shows you where the agent is acting. Since 0.11.0 the default agent cursor is a box that Chrome itself draws on the element the agent clicks or types into, in the agent's window and in the live view.
On a Retina screen that box was in the wrong place. Typing into the Username field of a sign-in form, it landed level with the Login button two rows below, to the right of it, and ran off the right edge of the page.


It looked intermittent
Some runs had the box on the element and some did not have a box at all, which made it look like a race. It was neither.
The box only shows when the browser can be seen and the action draws one. And when twice its position falls past the viewport, there is nothing to see: the box is drawn off the page. A field near the top left of a page got a box that was wrong but visible. A button further down got none.
The tests never saw it. They ran with a scale factor of 1, where a CSS pixel and a device-independent pixel are the same size, so every rectangle landed where it should.
What Chrome draws
The box goes to Chrome through one call of the DevTools protocol, Overlay.highlightRect, with the rectangle that Playwright measures for the element, in CSS pixels. To see what Chrome does with it, the same rectangle was sent in four ways on a 2x screen, and the result measured in a screenshot.
| Sent | Screen | Page zoom | Drawn at |
|---|---|---|---|
| The CSS box: 122, 124, 570 x 40 | 2x | 100% | 244, 248, 1140 x 79 |
| The box divided by 2 | 2x | 100% | On the element |
| The box divided by 2.5 | 2x | 125% | Short by the zoom |
| The box times the zoom, divided by 2 | 2x | 125% | On the element |
Chrome 158 draws the rectangle it receives multiplied by the screen's scale factor, and leaves the page zoom out. Sent as measured, a box on a 2x screen lands at twice its place and twice its size.
Headless Chrome has a screen too, described by its --screen-info flag, so the live view of a headless identity showed the same thing.
The fix
Each time a box is drawn, turno-browser now asks Chrome for the page's layout metrics and converts the box with them: times the page zoom, divided by the screen's scale factor.
export function highlightScale(m: LayoutMetrics | undefined): number {
const device = m?.layoutViewport;
const css = m?.cssLayoutViewport;
if (!device || !css) return 1;
const perCss = css.clientWidth > 0 ? device.clientWidth / css.clientWidth : device.clientHeight / css.clientHeight;
if (!Number.isFinite(perCss) || perCss <= 0) return 1;
const z = m?.cssVisualViewport?.zoom;
const zoom = typeof z === "number" && Number.isFinite(z) && z > 0 ? z : 1;
// perCss is the scale factor times the zoom: zoom / scale factor = zoom * zoom / perCss.
return (zoom * zoom) / perCss;
}The layout viewport comes back twice, once in device pixels and once in CSS pixels. Their ratio is the scale factor times the zoom, which is why the zoom appears squared: dividing the zoom by the scale factor is the same as dividing the zoom squared by that ratio.
The metrics are read on every draw, not once.
Reading them takes a moment, so a second box can be asked for while the first one waits. A box that was replaced or hidden in the meantime is not drawn:
const metrics = (await d.cdp.send("Page.getLayoutMetrics").catch(() => undefined)) as LayoutMetrics | undefined;
// Another box (or none) may have replaced this one while the metrics were read.
if (d.box !== box || d.tone !== tone) return;
await d.cdp.send("Overlay.highlightRect", {
...highlightRect(box, highlightScale(metrics)),
color: { r, g, b, a: outline ? 0 : 0.12 },
outlineColor: { r, g, b, a: 0.9 },
});The same field with the page zoomed to 125%, where the zoom has to be part of the conversion:
What was checked
A second pass, in headless Chrome 158, compared the box in a screenshot with a rectangle of known position:
- at scale factors 1 and 2, and at an emulated 3
- with the page scrolled 300 px
- inside an iframe of the same process
- with a viewport set through Playwright on a 2x screen
In each of them the box lands on its element.
What is still off
Two things remain, and the release notes say so too.
A page zoomed with a pinch is not covered. Playwright's measurement of the element ignores a pinch, so the box is drawn where the element would be without it. That was true before the fix as well.
The protocol takes whole numbers. At 2x, rounding can leave the box up to 1 CSS pixel off.
The tests that came with it
The bug lived in the one place the tests did not look: a screen where one CSS pixel is two pixels wide. The tests that came with the fix convert a box on a Retina screen, on a zoomed page, and on a plain screen or with no metrics at all, where the box must stay as it is.
Measured on an Apple M3 MacBook with macOS 27.2.1 and Chrome 158, on 2026-11-28. The change is pull request 194, with the tests that came with it.