Stable Reference IDs Survive Viewport Chaos.

Liam explains why browser automation that clicks by pixel coordinate breaks when a window resizes, and shows how stamping each element with a stable reference id fixes it.

1:45 video3 min readWatch on YouTube

Browser automation that clicks by pixel coordinate ties a command to one spot in one viewport. Resize the window and the page reflows, the button moves, the coordinate does not, and the click lands somewhere else every time. This video walks through why that happens and the fix that runs before Claude ever looks at the page.

The problem with pixel coordinates

A pixel coordinate describes a spot on the screen, not the button sitting there. As long as the window stays the exact same size, clicking that spot works. The moment the viewport changes, the page reflows and everything on it shifts position, but the recorded coordinate stays frozen at its old value. The click still fires at that same spot, except the button is no longer there.

A concrete before-and-after

The video anchors this with one example. A "Confirm Order" button sits at pixel position 960, 540 on a 1920 by 1080 window. Resize that window down to 1440 by 900, and the same button is now at 720, 405. A script still aimed at 960, 540 lands on empty page, because nothing about the button changed except where the browser chose to draw it.

Stamping stable reference ids

The fix runs before Claude ever looks at the page. A script walks every clickable element and stamps it with a stable reference id, baked into the page itself as an attribute such as data-ref="confirm_order_1". Claude then targets elements by that name instead of by pixel position. The reference id is attached to the element itself, not to a screen coordinate, so a resize that moves the button's pixel position leaves the ref completely unchanged.

Why the ref survives what the coordinate cannot

After the resize in the example, the Confirm Order button's pixel position moved to 720, 405, but its ref stayed exactly confirm_order_1. Claude clicks that ref and lands on the button every time, regardless of where the layout puts it. A pixel coordinate describes a moment in one viewport; a stable ref describes the button itself. That difference is the entire reason one survives a resize and the other does not.

What this approach does not cover

The fix only reaches elements the stamping script already saw. Anything added to the page after that pass, such as a modal that opens later or content loaded dynamically, has no ref yet and needs its own re-injection pass to get one. The video is also explicit about scope: it does not get into the JavaScript injection mechanics or CSS specificity rules that affect how refs get attached, and it does not make a claim that ref-based targeting is the single right way to build browser automation. That is left as a design judgment for whoever is building the system.

Key takeaways

  • Pixel-coordinate clicks tie a command to a screen position in one specific viewport, and that position breaks the moment the window resizes and the page reflows.
  • A stable reference id, stamped onto each clickable element before Claude looks at the page, is attached to the element itself rather than to a screen position.
  • In the example, a button's pixel position moved from 960, 540 to 720, 405 after a resize, while its reference id stayed unchanged and the click still landed.
  • Reference ids only cover elements present when the stamping script ran; anything added to the page afterward needs its own pass to get a ref.
  • The video does not cover the injection mechanics or CSS specificity details, and does not claim ref-based targeting is the only valid approach to browser automation.

Who this is for

This is for anyone building or debugging browser automation or computer-use workflows with Claude who has run into clicks landing on the wrong element after a window resize.

Chapters

  1. 0:00Pixel position is a stable way to find a button, right?
  2. 0:12The wrong guess: pixel ties to one viewport
  3. 0:25The anchor: Confirm Order, before and after
  4. 0:43The fix: stamped before Claude looks
  5. 0:56The anchor returns: the ref stays, the click lands
  6. 1:15Carry-out
  7. 1:24Your turn
  8. 1:39Outro
Full transcript(auto-generated, with timestamps)

Pixel position is a stable way to find a button, right?

[0:00]Someone assumes a button's pixel position is a stable way to find it. It isn't. Resize the window and the pixel moves even though the button hasn't. So, how do you give Claude a handle that survives the resize? Browser automation that clicks by pixel

The wrong guess: pixel ties to one viewport

[0:13]Coordinate ties a command to one spot in one viewport. Resize the window and the page reflows, the button moves, the coordinate doesn't, and the click lands somewhere else every single time. Here's

The anchor: Confirm Order, before and after

[0:25]The concrete case. A confirm order button sits at 960 540 on a 1920 by 1080 window. Resize down to 1440 by 900 and that same button is now at 720 405. The old coordinate lands on empty page. The fix

The fix: stamped before Claude looks

[0:43]Runs before Claude ever looks at the page. A script walks every clickable element and stamps it with a stable reference ID, confirm order one, baked into the page itself. Claude then clicks by that name, not by a pixel.

The anchor returns: the ref stays, the click lands

[0:56]Back to the button, after the resize its pixel moved to 720 405, but its ref confirm order one never changed. It's attached to the element, not the spot. Claude clicks the ref and lands every time. But, that only covers elements the script already saw. Anything added to the page afterward needs its own pass to get a ref at all. A pixel coordinate

Carry-out

[1:15]Describes a moment in one viewport. A stable ref describes the button itself. That's why the ref survives a resize and the coordinate doesn't. Your turn.

Your turn

[1:24]Here's the prompt. Read it with me. Assign stable refs to every clickable element on this page so my automation survives a resize. See what naming scheme it picks, whether it handles iframes, whether it guards against duplicate IDs. Lay 'em in for bear.

Outro

[1:39]Stable reference ID survive viewport chaos. Lay 'em in for bear.

More from Claude Basics

Humanitarians AI Lyrical Literacy Project