Mirroring looks right but clicks land wrong: check coordinate mapping

Separate touch-position errors from latency, account for image margins and browser zoom, and collect useful evidence after resizing or rotation.

A visible phone screen does not prove that mouse positions are mapped correctly to touch positions. If errors grow toward the edges, or appear after resizing, browser zoom or rotation, inspect coordinate mapping before increasing the frame rate.

This is a troubleshooting guide for browser-based mirroring and control, based on documentation checked on September 16, 2026. It provides analysis and a suggested test method, not device-test results for a particular product.

Compare positions without performing business actions

On an authorized test device, choose a harmless screen that cannot submit, delete or pay. Compare positions near the center and corners. Change only one condition at a time: window size, browser zoom or phone orientation. Record the intended and actual locations.

Pattern Investigate first
Similar offset everywhere Image origin, borders, toolbar or empty margins
Small error in the center, larger at edges Display-to-input scaling
Error appears after page scrolling Stale position measurements
Rotation causes errors that reopening clears Frame dimensions, orientation and input mapping

These are diagnostic clues, not confirmed causes. If touches land correctly but appear late, investigate mirroring latency and RTT instead.

Empty margins are not part of the phone

With object-fit: contain, the whole image keeps its aspect ratio and may leave margins. With cover, some content may be cropped. A device card's bounds therefore need not equal the visible phone image. MDN image fitting

Here is a worked geometry example, not a measured device result. A 1080×2400 frame is centered in a 300×600 area with no padding or border. Its scale is min(300/1080,600/2400)=0.25; the displayed image measures 270×600, leaving 15 on each side. The area's point (150,300) maps to frame point (540,1200). A click in the left margin should be rejected, not converted into an edge touch.

For this layout:

s = min(boxWidth/frameWidth, boxHeight/frameHeight)
leftGap = (boxWidth-frameWidth*s)/2
topGap = (boxHeight-frameHeight*s)/2
frameX = (localX-leftGap)/s
frameY = (localY-topGap)/s

This assumes centered, uncropped, proportional display without additional rotation or perspective transforms. Reject points outside the image first. If the control protocol uses different logical dimensions, another mapping is required. Cropped, off-center or rotated displays need their own transformation.

Do not hard-code a zoom correction

clientX is viewport-relative, as is the rectangle from getBoundingClientRect(). Subtracting positions in that shared coordinate system is useful, but the rectangle includes borders and padding: measure the actual image area. Event coordinates, element bounds.

devicePixelRatio expresses physical pixels relative to CSS pixels and can change with page zoom. It is not a universal multiplier for correcting touch coordinates. MDN pixel ratio

Our implementation advice is to share geometry between rendering, hit testing and control messages, refreshing it after layout, scroll, frame-size or orientation changes. A correction tailored to 90% zoom is not a general fix. For rotation, establish whether the receiver expects pre-rotation or post-rotation coordinates; do not rotate twice.

Send evidence that isolates the mismatch

Include browser version, zoom, phone orientation, visible margins and one redacted intended-versus-actual position example. Note whether resizing changes the error or reopening clears it. Developers can add frame dimensions, displayed bounds, normalized coordinates and the final transmitted values.

Debugging endpoints, accounts and unredacted business screens are unnecessary. Distinguishing spatial error from delayed feedback helps identify whether the next investigation belongs in layout, coordinate conversion or the control path.

参考来源