Skip to content

[bug] Tauri window theme is not propagated to webview (prefers-color-scheme) #5802

@CrendKing

Description

@CrendKing

Describe the bug

No matter which theme I set in the Tauri config file, the WebView always answers CSS media query prefers-color-scheme with OS color theme. According to the doc, it should only be the behavior is the theme field is None.

There is a similar issue in Electron, and they managed to fix it by "propagate preferred color scheme to the renderer".

Reproduction

  1. Set Windows color mode in Personalization to "Dark".
  2. In tauri.conf.json, set windows[0].theme to "Light".
  3. In Rust main(), call main window's theme() to make sure it is tauri::Theme::Light.
  4. In CSS, have different style for of both @media (prefers-color-scheme: light) and @media (prefers-color-scheme: dark).
  5. Observe that the section in @media (prefers-color-scheme: dark) is used.

Expected behavior

If theme() returns Light, styles in @media (prefers-color-scheme: light) should be used.

Platform and versions

Environment
  › OS: Windows 10.0.22621 X64
  › Webview2: 108.0.1462.44
  › MSVC: 
      - Visual Studio Community 2022
  › Node.js: 18.12.1
  › npm: 8.19.2
  › pnpm: 7.18.1
  › yarn: Not installed!
  › rustup: 1.25.1
  › rustc: 1.65.0
  › cargo: 1.65.0
  › Rust toolchain: stable-x86_64-pc-windows-msvc 

Packages
  › @tauri-apps/cli [NPM]: 1.2.2
  › @tauri-apps/api [NPM]: 1.2.0
  › tauri [RUST]: 1.2.2,
  › tauri-build [RUST]: 1.2.1,
  › tao [RUST]: 0.15.6,
  › wry [RUST]: 0.23.2,

App
  › build-type: build
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:1420/
  › framework: Svelte
  › bundler: Vite

App directory structure
  ├─ .git
  ├─ dist
  ├─ node_modules
  ├─ src
  └─ src-tauri

Stack trace

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions