The cursor clicked before it arrived: syncing headless screen recordings
In my proposal videos the UI reacted before the fake cursor reached the button. The fix: move the cursor with requestAnimationFrame and click after paint.
For Upwork proposals I make a short video for each job: the client’s post with the key lines marked, a small clickable demo built for their job, a plan board, and two questions. The screen parts are recorded by a headless browser (Playwright), and the cursor you see is fake: the recorded video has no real pointer, so the page draws one.
Watching the first videos, I saw the same bug again and again. A tab opened, a card got selected, a line of text turned yellow, and only then did the cursor arrive. It looked like a robot, which is exactly what the video is meant not to look like.
Why it happened
The cursor moved with a CSS transition, and the click fired from a JavaScript timer set to the same duration. In a normal browser those two finish together. In a headless browser that is also encoding video, the compositor drops frames under load, so the transition runs late while the timer fires on time. The click wins the race.
The marker on the job post had a second problem. The yellow highlight was one CSS background on a <mark> that wraps onto two lines. With box-decoration-break: clone, both lines fill at the same time, while the cursor travels diagonally from the start of line one to the end of line two.
The fix
One clock for everything that has to look connected:
- The cursor moves frame by frame with
requestAnimationFrame, re-reading the target’s position every frame, so it follows a button that shifts while it travels. - A click fires only after two animation frames have passed with the cursor on the target, so the frame showing it there has really been painted.
- The highlight is drawn line by line in the same frame loop as the cursor: the yellow grows exactly under the pointer, then the cursor hops to the start of the next line. When the sweep ends, the normal highlight takes over so it scrolls with the page.
I checked it frame by frame instead of trusting the code: cursor arrives at 0.6 s, the click ring shows at 0.9 s, the card is selected at 1.1 s.
Making it less robotic
While I was in there: the cursor now travels on a slight arc, takes longer for longer trips, pauses 0.2 to 0.4 s before a click like a hand taking aim, and lands a few pixels off-centre each time. The demo plays once from start to finish instead of being cut into pieces, and the parts of the video dissolve into each other in 0.4 s instead of hard cuts.
Worth stealing
If you record UI with a fake cursor, never let a CSS transition and a timer share responsibility for one gesture. Drive both from the same requestAnimationFrame loop, and wait for a paint before the click.