Skip to content

[bug] WebviewBuilder options on the JS api other than the file drop handler gets discarded #6794

@Hyphrio

Description

@Hyphrio

Describe the bug

It seems like that looking at the associated Rust code, defined on the tauri::window::WindowBuilder::from_config, Webview options other than the file drop handler, gets discarded.

The code:

pub fn from_config<M: Manager<R>>(manager: &'a M, config: WindowConfig) -> Self {
    let runtime = manager.runtime();
    let app_handle = manager.app_handle();
    let url = config.url.clone();
    let file_drop_enabled = config.file_drop_enabled;
    let mut builder = Self {
      manager: manager.manager().clone(),
      runtime,
      app_handle,
      label: config.label.clone(),
      window_builder: <R::Dispatcher as Dispatch<EventLoopMessage>>::WindowBuilder::with_config(
        config,
      ),
      webview_attributes: WebviewAttributes::new(url),
      web_resource_request_handler: None,
      navigation_handler: None,
    };

    if !file_drop_enabled {
      builder = builder.disable_file_drop_handler();
    }

    builder
  }

Looking at webview_attributes, it looks like it never sees the config, and just resorts to the default one.

Reproduction

First, use WebviewBuilder to create a window, passing anything other than url and fileDropEnabled.
Minimal reproduction example:

async function createWindow() {
    new WebviewBuilder("example", {url: "https://www.whatsmyua.info", userAgent: "tauri/1.0"});
}

Expected behavior

In this User-Agent example, the user agent should be tauri/1.0.

However, what appears is the default user agent of the browsers used in each platform.

Any other configs should be affected as I discovered it while doing #6767.

Platform and versions

While my development platform is as follows:
[✔] Environment
    - OS: Windows 10.0.22621 X64
    ✔ WebView2: 112.0.1722.58
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.67.1 (d5a82bbd2 2023-02-07)
    ✔ Cargo: 1.67.1 (8ecd4f20a 2023-01-10)
    ✔ rustup: 1.25.2 (17db695f1 2023-02-01)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 18.15.0
    - pnpm: 8.1.1
    - yarn: 1.22.19
    - npm: 9.5.0

[-] Packages
    - tauri [RUST]: git+https://github.com/Hyphrio/tauri?branch=incognito#e0866b5920fed0e91a5a308c6d152093b57006c2 (2.0.0-alpha.8)
    - tauri-build [RUST]: git+https://github.com/Hyphrio/tauri?branch=incognito#e0866b5920fed0e91a5a308c6d152093b57006c2 (2.0.0-alpha.4)
    - wry [RUST]: 0.27.3
    - tao [RUST]: 0.18.3
    - @tauri-apps/api [NPM]: not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-alpha.8

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:7000/
    - framework: React
    - bundler: Vite

All platforms should be affected including Tauri 1.0 as that also uses the same code.

Stack trace

No response

Additional context

Building the Webview using WindowBuilder::from_config would be also affected by this issue, however most users would probably not be affected as they use WindowBuilder::new instead.

This code should probably be refactored to fix this issue.

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