tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
83.63k stars 2.51k forks source link

[bug] Tauri v2 on Ubuntu does not automatically use system proxy, unlike v1 #11251

Open lanyeeee opened 1 week ago

lanyeeee commented 1 week ago

Describe the bug

In Tauri v2 running on Ubuntu, the system proxy is not automatically detected or used, while Tauri v1 automatically uses the system proxy under the same conditions.

Additionally, both Tauri v1 and v2 work as expected on Windows, the system proxy is automatically used.

I found the workaround for Tauri v2 by setting the proxyUrl in the tauri.conf.json to the system proxy address. https://v2.tauri.app/reference/config/#proxyurl This allowed the application to use the proxy. However, there are several downsides to this manual configuration:

  1. If the system proxy changes during the runtime of the application, the proxy does not switch automatically, causing potential network issues.
  2. It requires the user to know their system's proxy address and configure it manually, which raises the barrier for non-technical users.

When proxyUrl is set to null, the application in Tauri v2 on Ubuntu does not use any proxy at all. There is no option for Tauri v2 on Ubuntu to automatically detect and use the system proxy without manual configuration.

This issue was discovered when I was trying to solve #11238

Reproduction

Follow these steps to reproduce the issue on Ubuntu 22.04:

  1. Create a new Tauri project:
pnpm create tauri-app@latest
✔ Project name · tauri-app
✔ Identifier · com.tauri-app.app
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun)
✔ Choose your package manager · pnpm
✔ Choose your UI template · Vanilla
✔ Choose your UI flavor · TypeScript
  1. Install dependencies:
cd tauri-app
pnpm install
  1. Modify the lib.rs
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet])
        .setup(|app| {
            let window = app.get_webview_window("main").unwrap();
            window.open_devtools();
            window.eval("window.location.replace('https://tauri.app/')")?;
            Ok(())
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
  1. Set your system proxy. In my case, I used the proxy http://127.0.0.1:7890.

image

  1. Run the application:
pnpm tauri dev
  1. You will encounter the following error:

image

  1. To resolve the issue, set the proxyUrl in tauri.conf.json as follows:
"app": {
  "withGlobalTauri": true,
  "windows": [
    {
      "title": "tauri-app",
      "width": 800,
      "height": 600,
      "proxyUrl": "http://127.0.0.1:7890"
    }
  ],
  "security": {
    "csp": null
  }
},

Expected behavior

Tauri v2 on Ubuntu should automatically use the system proxy, just like Tauri v1 do on Ubuntu, and how both Tauri v1 and v2 do on Windows. The main problem is that there is currently no way for Tauri v2 on Ubuntu to automatically detect and use the system proxy. Instead, Tauri v2 on Ubuntu either completely ignores the proxy or requires manual configuration, which is not ideal.

Full tauri info output

[✔] Environment
    - OS: Linux Mint 21.2.0 x86_64 (X64)
    ✔ webkit2gtk-4.1: 2.44.2
    ✔ rsvg2: 2.52.5
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 18.18.0
    - pnpm: 9.9.0
    - yarn: 1.22.19
    - npm: 9.8.1

[-] Packages
    - tauri 🦀: 2.0.1
    - tauri-build 🦀: 2.0.1
    - wry 🦀: 0.44.1
    - tao 🦀: 0.30.3
    - @tauri-apps/api : 2.0.1
    - @tauri-apps/cli : 2.0.1

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.1
    - @tauri-apps/plugin-shell : 2.0.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - bundler: Vite

Stack trace

No response

Additional context

No response

lanyeeee commented 1 week ago

It seems that this issue is caused by Tauri v2 using webkit2gtk 4.1, while Tauri v1 uses webkit2gtk 4.0, so it doesn't have this problem. Perhaps I should open another issue over at wry regarding this.

epietrocola commented 1 week ago

Experiencing the same, apparently

altunenes commented 1 week ago

I think I'm having a similar issue in MacOS, though I'm not exactly sure.

in dev mode, when I try to reach a video, I get the following error:

"Failed to load resource: the server responded with a status of 500 (Internal Server Error) blablavideodress.mp4"

But this is not the case in the production app! When I try to open the app in production mode, apple asks me "do you trust this app bla bla" and the video appears on the front end in the end.

Note that, this never happens on the Windows side. in Windows, everything is working very well both in production/dev mode.

Note 2: I m in v2.0

this is my permissions:

{
  "identifier": "migrated",
  "description": "Permissions that were migrated from v1 and additional required permissions",
  "local": true,
  "windows": [
    "main"
  ],
  "permissions": [
    "core:default",
    "os:default",
    "dialog:default",
    "dialog:allow-open",
    "dialog:allow-save",
    "dialog:allow-ask",
    "dialog:allow-message",
    "fs:allow-remove",
    "fs:allow-read-dir",
    "fs:allow-read-text-file",
    "fs:allow-app-write",
    "process:default",
    "shell:default",
    "log:default"
  ]
}

edit: my problem was not related to this topic sorry.

my problem was the mismatch between the frontend's use of the built-in asset:// protocol () and the backend's custom protocol handler. By aligning the frontend to utilize the custom protocol, I ensured that external video files were correctly served during development on macOS, thereby resolving the 500 Internal Server Error. (now I don't use convertFileSrc)

doroved commented 1 week ago

Was glad when I saw the option to set a proxy on the window, but it seems proxies with authentication don't work?( .proxy_url(Url::parse("http://user:pass@IP:PORT").unwrap())

It seems even without authentication it doesn't work, not even a request comes to the proxy .proxy_url(Url::parse("http://127.0.0.1:58846").unwrap())

[✔] Environment

[-] Packages

[-] Plugins

[-] App