tauri-apps / tauri

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

[bug]mobile alpha ERR_UNKNOWN_URL_SCHEME #7312

Open 1192724521 opened 1 year ago

1192724521 commented 1 year ago

Describe the bug

mobile android

window.TAURI.tauri.convertFileSrc() <'asset://localhost/undefined'

GET asset://localhost/%2Fdata%2Fuser%2F0%2Fcom.tauri.tauriv2%2Fcache%2Ffilename.js net::ERR_UNKNOWN_URL_SCHEME Excuse me How to open local asset resource/**

Reproduction

No response

Expected behavior

No response

Platform and versions

[✔] Environment
    - OS: Windows 10.0.19045 X64
    ✔ WebView2: 105.0.1343.27
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.70.0 (90c541806 2023-05-31)
    ✔ Cargo: 1.70.0 (ec8a8a0ca 2023-04-25)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 18.16.0
    - npm: 9.5.1

[-] Packages
    - tauri [RUST]: 2.0.0-alpha.10
    - tauri-build [RUST]: 2.0.0-alpha.6    
    - wry [RUST]: 0.28.3
    - tao [RUST]: 0.19.1
    - @tauri-apps/api [NPM]: 2.0.0-alpha.5 
    - @tauri-apps/cli [NPM]: 2.0.0-alpha.10

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

Stack trace

No response

Additional context

No response

FabianLars commented 1 year ago

Now i don't know if the asset protocol itself even works on android but to fix convertFileSrc you could do something like this, using the os plugin from here https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/os

let path = convertFileSrc(yourPathHere);
if (await os.type() === 'android' {
  path = path.replace("asset://localhost/", "https://asset.localhost/");
}
1192724521 commented 1 year ago

Is it better to use this method? tauri.cjs

function y(n, e = "asset") {
    let r = encodeURIComponent(n);
    //return navigator.userAgent.includes("Windows") ? `https : //${e}.localhost/${r}` : `${e}://localhost/${r}`
    return navigator.userAgent.includes("Windows") || navigator.userAgent.includes("Android")? `https://${e}.localhost/${r}` : `${e}://localhost/${r}`
}
FabianLars commented 1 year ago

last time i checked the useragent didn't include Android i think. But if it does work then yeah, ig it would be better.

lucasfernog commented 1 year ago

Yeah it's being updated on the IPC refactor PR.

1192724521 commented 1 year ago

I got a new problem when I switched to https://asset.localhost/ emmm

 GET https://asset.localhost/%2Fdata%2Fuser%2F0%2Fcom.tauri.tauriv2%2Fcache%2Fmap_load.js 
  net::ERR_CONNECTION_REFUSED

How do I use convertFileSrcassetreadBinaryFile in android