fix(tauri): use CSS pixels for embedded window rect - #527
Conversation
|
|
Greptile SummaryThis PR corrects the embedded Tauri WebDriver
Confidence Score: 5/5Safe to merge — the change corrects a well-defined physical-to-logical pixel conversion bug and replaces error-prone fixed sleeps with event-driven waiting, all backed by deterministic unit tests and a native E2E run on Retina hardware. All four changed files have a clear, focused purpose: the Rust executor correctly reads scale factor, converts coordinates before any display move, and waits for native window events instead of sleeping. Error paths that previously swallowed failures now propagate them. The unit tests cover scale factors 1.0, 1.25, and 2.0 with rounding edge cases, and the E2E tests verify both the physical-to-logical mapping and the viewport-delta invariant. No logic errors, data-loss paths, or security concerns were identified. No files require special attention.
|
| Filename | Overview |
|---|---|
| packages/tauri-plugin-webdriver/src/platform/executor.rs | Core fix: get_window_rect and set_window_rect now convert Tauri physical coordinates to CSS logical pixels using the window's scale factor; chrome decoration is captured before any display move; fixed-delay sleeps replaced with tauri://move/tauri://resize event waits; errors are properly propagated instead of silently swallowed. |
| e2e/test/tauri/window.spec.ts | New 'Embedded WebDriver WindowRect CSS pixel semantics' describe block adds three E2E tests that validate the native outer rect in logical pixels, combined move+resize, and size-only change without viewport shrinkage; tests are gated on DRIVER_PROVIDER === 'embedded' and properly restore state in finally blocks. |
| fixtures/e2e-apps/tauri/src-tauri/src/main.rs | Added WindowMetrics struct (with scale_factor) replacing WindowBounds; get_window_bounds Tauri command now also returns the display scale factor so E2E tests can independently verify the physical-to-logical conversion. |
| packages/tauri-plugin-webdriver/README.md | Added a short prose note documenting that Get Window Rect / Set Window Rect operate in CSS pixels and that position changes complete before size is applied. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant WD as WebDriver Client
participant EX as PlatformExecutor
participant TW as Tauri Window
participant OS as OS / Window Manager
WD->>EX: Set Window Rect (x, y, w, h) [CSS px]
EX->>TW: is_fullscreen() / is_maximized()
alt fullscreen or maximized
EX->>TW: set_fullscreen(false) / unmaximize()
OS-->>TW: tauri://resize event
TW-->>EX: event received
end
EX->>TW: scale_factor(), outer_position(), outer_size(), inner_size()
TW-->>EX: physical metrics
EX->>EX: physical_window_rect_to_logical → current_rect (logical)
EX->>EX: physical_window_chrome_to_logical → chrome_size (logical)
alt position changed
EX->>TW: "set_position(LogicalPosition{x, y})"
OS-->>TW: tauri://move event
TW-->>EX: event received
end
alt size changed
EX->>TW: "set_size(LogicalSize{w - chrome_w, h - chrome_h})"
OS-->>TW: tauri://resize event
TW-->>EX: event received
end
EX->>TW: outer_position(), outer_size(), scale_factor()
TW-->>EX: updated physical metrics
EX->>EX: physical_window_rect_to_logical → final rect (logical)
EX-->>WD: WindowRect (CSS px)
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant WD as WebDriver Client
participant EX as PlatformExecutor
participant TW as Tauri Window
participant OS as OS / Window Manager
WD->>EX: Set Window Rect (x, y, w, h) [CSS px]
EX->>TW: is_fullscreen() / is_maximized()
alt fullscreen or maximized
EX->>TW: set_fullscreen(false) / unmaximize()
OS-->>TW: tauri://resize event
TW-->>EX: event received
end
EX->>TW: scale_factor(), outer_position(), outer_size(), inner_size()
TW-->>EX: physical metrics
EX->>EX: physical_window_rect_to_logical → current_rect (logical)
EX->>EX: physical_window_chrome_to_logical → chrome_size (logical)
alt position changed
EX->>TW: "set_position(LogicalPosition{x, y})"
OS-->>TW: tauri://move event
TW-->>EX: event received
end
alt size changed
EX->>TW: "set_size(LogicalSize{w - chrome_w, h - chrome_h})"
OS-->>TW: tauri://resize event
TW-->>EX: event received
end
EX->>TW: outer_position(), outer_size(), scale_factor()
TW-->>EX: updated physical metrics
EX->>EX: physical_window_rect_to_logical → final rect (logical)
EX-->>WD: WindowRect (CSS px)
Reviews (2): Last reviewed commit: "fix(tauri): use CSS pixels for embedded ..." | Re-trigger Greptile
2d68e18 to
b2c9cbf
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 or times out;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.