fix(tauri): use CSS pixels for embedded window rect - #527
Conversation
|
|
Greptile SummaryThis PR fixes the embedded Tauri WebDriver server's
Confidence Score: 5/5Safe to merge; the physical-to-logical conversion is mathematically correct, the Tauri event listener lifecycle is properly managed, and chrome is measured before any display move. All changed code paths are well-covered by deterministic Rust unit tests and a new E2E suite. Event-based waiting replaces fragile fixed delays without introducing listener leaks. Chrome measurement happens before any position move, avoiding the stale-scale-factor issue from the previous review round. No correctness issues found. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| packages/tauri-plugin-webdriver/src/platform/executor.rs | Core logic change: physical to logical conversion helpers added, get/set_window_rect updated to use scale_factor and event-based waiting; listener lifecycle is handled correctly. |
| e2e/test/tauri/window.spec.ts | New E2E describe block with three logical-pixel semantics tests gated to embedded provider; restores original rect in finally blocks and cross-validates native metrics. |
| fixtures/e2e-apps/tauri/src-tauri/src/main.rs | Adds scale_factor to get_window_bounds response via new WindowMetrics struct; minimal and correct change. |
| packages/tauri-plugin-webdriver/README.md | Documents the CSS-pixel contract for Get/Set Window Rect; accurate and concise. |
Reviews (4): Last reviewed commit: "fix(tauri): wait for the resize event on..." | Re-trigger Greptile
2d68e18 to
b2c9cbf
Compare
8eb5acb to
7f2739b
Compare
|
Thanks for this — good catch and a well-targeted fix. Worth noting it's broader than HiDPI ergonomics: I've pushed three things to the branch: Rebased onto
Verified on the rebased branch: |
|
Thanks for this, @Clarkkkk 🙏 A heads-up on the red CI, since it's specific to this PR — not a flake, so a re-run won't clear it. Failing job: (The Symptoms are inconsistent across attempts:
Where I'd start looking:
Agreed a Tauri fix should support Linux fully, so gating the tests off Linux isn't the answer. Happy to pair on the WebKitGTK window-rect path if it's useful — maintainer edits are on, so I can push to this branch to help if you'd like. 🙂 |
Set Window Rect is best-effort under W3C: the command applies the request and returns the resulting rect, it does not require the request be honored. A window manager can clamp or ignore a move/resize — request a size above the display bounds or below a min-size constraint and the clamped result can equal the current one, so no tauri://move or tauri://resize ever fires. Failing the command there regresses callers that previously got the actual rect back. Only a failure of the native call itself stays an error. Waiting for the confirming event now degrades to a debug log, and set_window_rect falls through to reporting the rect the window actually ended up with. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CsgeivZCqduTQmWK55zqiT
maximize_window and fullscreen_window slept for a fixed 100ms and then read the rect, so they reported whatever the window looked like mid-transition — the macOS fullscreen animation alone outlasts that budget. They also dropped the native call's error on the floor. Route both through apply_window_change so they wait for tauri://resize on the same best-effort terms as set_window_rect, and surface a failure of the native call itself. minimize_window is left alone: it returns no rect, so there is nothing to stabilise. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CsgeivZCqduTQmWK55zqiT
7f2739b to
f5caf45
Compare
Description
Fixes the embedded Tauri WebDriver server's desktop
Get Window RectandSet Window Rectimplementation so the W3C values are expressed in CSS/logical pixels instead of Tauri physical pixels.On a Retina display, the existing implementation returned and accepted physical dimensions. A Tauri window reported by WebDriver as
1320x860at DPR 2 therefore exposed only a660x430DOM viewport, and setting a WebDriver size could shrink the application to half of the requested logical size.This change:
to_logical()using the current window scale factor;LogicalPositionandLogicalSizewhen applying WebDriver rects;tauri://moveandtauri://resizeevents instead of relying on fixed delays, and reports a WebDriverunknown errorif a native operation fails. A window manager may clamp or ignore a request, so an unobserved event is logged and the resulting rect is returned rather than failing the command; the same wait now also coversmaximizeandfullscreen;The behavior follows the W3C Set Window Rect command and Tauri's
PhysicalSize::to_logicalAPI.Regression evidence
The embedded E2E was first run against the previous implementation. It failed while the existing window tests passed:
With the fix, the same Retina run observed a
720x540WebDriver rect backed by1440x1080physical bounds at scale factor 2. The DOM viewport changed by the same logical delta, and all 14 window tests passed.Related Issues
None.
Type of Change
Scope
scope:electron- Electron service and CDP bridgescope:tauri- Tauri service and pluginChecklist
pnpm lint)pnpm test)pnpm typecheck)A direct root
pnpm testis not a CI-equivalent entry point on macOS: it bypassestest-package.ts, selects the official Tauri driver fixture, and fails because that provider is unsupported on macOS. The CI-equivalent unit/integration suite, repository pre-push package suite, and the relevant native E2E all pass locally. CI remains responsible for the fully provisioned cross-platform fixture and provider matrix.Testing
Passed locally:
cargo test(17 passed)rustfmt --edition 2021 --check src/platform/executor.rscargo clippy --all-targets -- -D warnings -A clippy::incompatible-msrvpnpm exec turbo run build --filter='./fixtures/package-tests/*'(27 successful)pnpm run test:unit test:integration --only --concurrency=1(19 successful)pnpm run test:coverage --concurrency=1(29 successful)TAURI_WEBDRIVER_PORT=4545 pnpm --filter @repo/e2e test:e2e:tauri-basic-embedded:window(14 passing)pnpm format:checkpnpm lintpnpm typecheck(28 successful)26 successful)Two strict Rust checks expose unrelated current-main/toolchain issues:
cargo fmt --checkwith rustfmt 1.96 reports formatting drift only in untouched Rust files; the modified Rust file passes a direct rustfmt check.cargo clippy --all-targets -- -D warningswith Rust 1.96 reports existingclippy::incompatible_msrvwarnings forcast_unsigned/cast_signedbecause the crate declares MSRV 1.77; allowing only that lint produces a clean clippy run.Screenshots/Videos
Not applicable; the regression is asserted against WebDriver rects, DOM viewport dimensions, and native Tauri physical bounds.
Additional Context
This changes desktop behavior on macOS, Windows, and Linux because all three platforms share the same
cfg(desktop)implementation. Mobile implementations and public endpoint shapes are unchanged. Clients that relied on the non-standard physical-pixel values will now receive W3C CSS-pixel values.A genuine mixed-DPI multi-display transition was not available for manual testing. Scale factors 1.0, 1.25, and 2.0, negative positions, integer rounding, decoration conversion, combined move/resize, and size-only updates are covered by deterministic Rust tests and the native embedded E2E; CI provides the remaining platform matrix.
Note: This repository does not backport changes to older versions. All changes target the current
mainbranch.