wry icon indicating copy to clipboard operation
wry copied to clipboard

Is the proxy_url unavailable on Android?

Open Borber opened this issue 10 months ago • 2 comments

Describe the bug The proxy setup code for the Android WebView is not functioning correctly

Steps To Reproduce

pub async fn run() {
    common::init().await;

    tauri::Builder::default()
        .setup(|app| {
            let win_builder = tauri::WebviewWindowBuilder::new(
                app,
                "main",
                tauri::WebviewUrl::External(Url::parse("http://test1.genmeta.net")?),
            )
            .proxy_url(Url::parse("http://192.168.31.86:5379")?);

            #[cfg(target_os = "macos")]
            let win_builder = win_builder
                .title("Gapp")
                .inner_size(1000.0, 800.0)
                .title_bar_style(tauri::TitleBarStyle::Transparent)
                .center();

            let main_window = win_builder.build().expect("failed to build window");

            info!("window created");

            Ok(())
        })
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Since test1.genmeta.net is our local network domain, it is currently not accessible.

Expected behavior

Android webview can use proxy

Screenshots

Image

But: MacOS

Image

Platform and Versions (please complete the following information): [✔] Environment - OS: Mac OS 15.3.0 arm64 (X64) ✔ Xcode Command Line Tools: installed ✔ rustc: 1.86.0-nightly (bef3c3b01 2025-02-04) ✔ cargo: 1.86.0-nightly (0e3d73849 2025-02-01) ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24) ✔ Rust toolchain: nightly-aarch64-apple-darwin (default) - node: 20.16.0 - pnpm: 9.14.2 - npm: 10.8.1 - bun: 1.2.2 - deno: deno 2.1.9

[-] Packages - tauri 🦀: 2.2.5 - tauri-build 🦀: 2.0.5 - wry 🦀: 0.48.1 - tao 🦀: 0.31.1 - @tauri-apps/api : 2.2.0 - @tauri-apps/cli : 2.2.7

[-] Plugins - tauri-plugin-opener 🦀: 2.2.5 - @tauri-apps/plugin-opener : 2.2.5

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

Borber avatar Feb 12 '25 09:02 Borber

correct: https://docs.rs/wry/latest/wry/struct.WebViewBuilder.html#method.with_proxy_config - i do not know if there are reasons for that or if we just didn't get to it so i'll leave this open for now.

FabianLars avatar Feb 12 '25 21:02 FabianLars

I ultimately chose to manually add a proxy to the Android code. The code is as follows::

import android.util.Log
import androidx.webkit.ProxyConfig
import androidx.webkit.ProxyController
import androidx.webkit.WebViewFeature
import java.util.concurrent.Executor


class MainActivity : TauriActivity() {
  override fun onStart() {
    super.onStart()

    if (WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE)) {
      val proxyConfig = ProxyConfig.Builder()
        .addProxyRule("http://127.0.0.1:5380")
        .addDirect()
        .build()

      ProxyController.getInstance().setProxyOverride(
        proxyConfig,
        Executor {
          //do nothing
        }
      ) {}
    }
  }
}

But I still hope to support Android to set up directly through proxy_url

Borber avatar Mar 23 '25 11:03 Borber