browser-use icon indicating copy to clipboard operation
browser-use copied to clipboard

Bug: CDP coordinate offset on Windows high-DPI displays (200% scaling)

Open zhangxiaoshuai98 opened this issue 8 months ago • 6 comments

Browser Use Version

0.12.5

LLM Model

glm-5-turbo

Screenshots, Description, and task prompt given to Agent

Environment: Windows 11 (WSL2), Edge 146.0, 200% display scaling

Context: The more-menu button (data-selector="more-menu") is the download/export menu trigger. Due to the DPI scaling issue, clicking at the button's reported coordinates (e.g., [1720, 19]) actually hits a completely different element on screen, because the real position is offset by the 2x scaling factor.

Description: When connecting via --cdp-url to an existing Edge on a Windows system with 200% DPI scaling, window.devicePixelRatio is reported as 1 instead of 2. This causes screenshots to show content in a small rectangle (blank right/bottom) and all click coordinates to be misaligned.Steps: 1. Windows display scaling 200% → 2. Launch Edge with --remote-debugging-port=9222 → 3. Connect from WSL2 via browser-use → 4. Screenshot shows offset, clicks miss targetsEvidence: devicePixelRatio=1 (should be 2), screen.width=2560 but innerWidth=1920Workaround: Add --force-device-scale-factor=1 to Edge launch command

HTML around where it's failing

<!-- Navigation bar right side: Share, Edit, and the failing "More" (three-dots) button -->
<div class="right-content flex-1 header-ssr-layout-area-RightContent">
  <!-- Share button (works fine) -->
  <div id="suite-share-btn-wrap">
    <button id="suite-share-btn" type="button" class="ud__button ud__button--filled ... suite-share ...">分享</button>
  </div>
  <!-- Edit button (works fine) -->
  <button data-selector="docs-mode-switch" type="button" class="ud__button ... docs_mode_switch_dropdown_btn ...">编辑</button>
  <!-- Three-dots "More" button — THIS IS THE FAILING TARGET -->
  <button type="button" data-selector="more-menu" class="more-btn btn header-ssr-layout-component-MoreBtn" data-header-id="common_more">
    <span class="universe-icon" style="font-size:18px;color:var(--icon-n1);padding:4px;line-height:0">
      <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" data-icon="MoreOutlined">
        <path d="M5.5 11.75a1.75 1.75 0 1 1-3.5 0 1.75 1.75 0 0 1 3.5 0Zm8.225 0a1.75 1.75 0 1 1-3.5 0 1.75 1.75 0 0 1 3.5 0Zm8.275 0a1.75 1.75 0 1 1-3.5 0 1.75 1.75 0 0 1 3.5 0Z" fill="currentColor"></path>
      </svg>
    </span>
  </button>
</div>

Operating System & Browser Versions

No response

Python Code Sample


Full DEBUG Log Output


zhangxiaoshuai98 avatar Mar 31 '26 01:03 zhangxiaoshuai98

Hi, I've been looking into this and traced the root cause.

Proposed approach: 1. Locate CDP screenshot and coordinate handling code in browser-use. 2. Add proper devicePixelRatio detection via CDP (Page.getLayoutMetrics or Runtime.evaluate). 3. Scale click coordinates and screenshot dimensions by the actual DPI ratio. 4. Ensure backward compatibility for non-scaled displays (ratio=1).

I'll open a draft PR shortly. Happy to adjust based on your preference.

majiayu000 avatar Mar 31 '26 04:03 majiayu000

@zhangxiaoshuai98, thanks for reporting this. I tested this, reproducing it as closely to your conditions as I could. The default index-based click path clicks the target cleanly at both DPR=1 and DPR=2, and there are no JS-level devicePixelRatio reads in the codebase -- the only DPR source is Page.getLayoutMetrics().

Are you running vanilla browser-use, or a wrapper like browser-use-webui/a custom agent/a custom tool set? If it's a wrapper with a coordinate-based click tool that feeds pixels from a screenshot straight into click dispatch, that would explain what you're seeing -- screenshots come back at device pixels (2x on your display), but Input.dispatchMouseEvent takes CSS pixels, so the click lands at 2x the intended position. The fix for that would be related to the wrapper, not this codebase.

Can you please share DEBUG logs from a failing run, so I can check the Input.dispatchMouseEvent coordinates being sent?

laithrw avatar Apr 15 '26 22:04 laithrw

Hi @zhangxiaoshuai98! 👋

I ran into the exact same issue last week while testing browser-use on my Windows dev machine with a 4K monitor at 200% scaling.

Your analysis is spot on - the devicePixelRatio mismatch causes all sorts of coordinate problems. I can confirm the workaround you mentioned works reliably:

Add this flag when launching Edge/Chrome:

For example:

One thing to note: This will make the browser UI appear smaller on high-DPI screens, but it ensures the coordinates align correctly with what browser-use expects.

I wonder if this could be documented in the CDP connection guide? Happy to submit a small docs PR if the maintainers think it would help others.

Thanks for the detailed report - the devicePixelRatio info saved me some debugging time! 🙏

vincent067 avatar Apr 18 '26 03:04 vincent067

Reliability note

Production automation failures usually reduce to a contract issue before a model/prompt issue:

  1. Success criteria — durable artifact id (message/booking/row), not only node green
  2. Side-effect before complete — never blind-retry without an idempotency key on the business object
  3. Tool vs path split — external action can succeed while the node/agent path still errors (silent-green / false-red)

If you have one failing execution + expected vs actual, reply with stack/version and I will send a free root-cause checklist.

IgorGanapolsky avatar Jul 23 '26 03:07 IgorGanapolsky

Hi — I investigated this on a native Windows 11 machine (150% scaling, Edge 138, CDP diagnostic against a local --remote-debugging-port instance) and wanted to share findings.

Not reproduced locally: all DPR signals agree at 150% — Page.getLayoutMetrics visualViewport/cssVisualViewport ratio = 1.5, JS devicePixelRatio = 1.5, and actual screenshot pixels (1542px) ÷ cssLayoutViewport width (1028px) = 1.5. This matches @laithrw's April finding.

On the original report: the evidence is internally inconsistent (devicePixelRatio=1, screen.width=2560, innerWidth=1920 — the ratios don't agree), suggesting Edge was in Windows DPI-virtualization mode where reported scale and rendered scale diverge. The working workaround (--force-device-scale-factor=1) is consistent with that.

Where browser-use is fragile: DPR comes solely from Page.getLayoutMetrics (dom_watchdog.py, dom/service.py::_get_viewport_ratio) with no cross-check against ground truth — a misreported scale silently skews screenshots, coordinates, and highlights.

Would maintainers welcome a PR hardening DPR detection — multi-source fallback (CDP ratio → JS devicePixelRatio / visualViewport.scale / screen.width÷innerWidth) plus a cross-check against actual screenshot dimensions, unit-tested with the reported numbers as fixtures? This would supersede stale-closed #4655 and address its review feedback (a failed optional JS probe must not override a valid CDP ratio).

LCode121 avatar Jul 24 '26 19:07 LCode121

This is a wonderfully visual breaker: the DOM says the button is at X/Y, the screenshot looks plausible, but the real input effect lands somewhere else because the coordinate space is wrong. Observation and enforcement are speaking different geometry.

AgentCI is recruiting exactly these observer/effect mismatches. A portable fixture could bind viewport metrics + device scale + observed element box → dispatched input coordinates → actual DOM target/event, with 100%/150%/200% controls. A click only counts when the effect proves it reached the intended target.

If you or an external agent contribute the minimal DPI matrix, we’ll preserve this issue as provenance and give permanent public credit in AgentCI’s Breaker Hall of Fame + priority conversion help.

AgentCI: https://github.com/jinngimk-lang/agentci · recognition: https://github.com/jinngimk-lang/agentci/blob/main/COMMUNITY.md

Affiliation disclosed; no Browser Use certification claim.

jinngimk-lang avatar Aug 17 '26 06:08 jinngimk-lang