[bug] Unable to load custom URI scheme
Describe the bug
Hi,
I would like to process images in Rust, then send them to the front to display them. From the example, it seems that a custom scheme protocol would be a good solution.
The problem, is that I'm completly unable to use it. I've looked at the streaming example in this repository, but I still can't make it work.
I'm using an that contains the URI photo://localhost/ and the image does not load and there is an error inside the console :
Reproduction
fn main() {
tauri::Builder::default()
.register_uri_scheme_protocol("photo", move |app, request| {
println!("request: {:?}", request);
ResponseBuilder::new()
.mimetype("image/jpeg")
.body(Vec::new())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
<script setup>
import {ref} from 'vue'
const src = ref("photo://localhost/");
</script>
<template>
<img :src="src"/>
</template>
<style scoped>
</style>
Expected behavior
No error in the console
Full tauri info output
cargo tauri info
[✔] Environment
- OS: Windows 10.0.22631 X64
✔ WebView2: 124.0.2478.97
✔ MSVC:
- Visual Studio Build Tools�2019
- Visual Studio Community 2022
✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-x86_64-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)
- node: 21.7.3
- yarn: 1.22.22
- npm: 10.5.0
[-] Packages
- tauri [RUST]: 1.6.7
- tauri-build [RUST]: 1.5.2
- wry [RUST]: 0.24.10
- tao [RUST]: 0.16.9
- tauri-cli [RUST]: 1.5.11
- @tauri-apps/api [NPM]: 1.5.3
- @tauri-apps/cli [NPM]: 1.5.11
[-] App
- build-type: bundle
- CSP: unset
- distDir: ../dist
- devPath: http://localhost:1420/
- framework: Vue.js
- bundler: Vite
Stack trace
Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME
Additional context
I even installed Pisano, as it was linked in a previous issue, but when running it I have the same issue.
Using register_asynchronous_uri_scheme_protocol and on font side Axios and got this error
On macOS work but if I select the request on the network panel from the debugger the app crashes with a : thread 'tokio-runtime-worker' panicked similar to #9177
@SauvageThomas the issue is that you're using the wrong url. On Windows it will be http://photo.localhost/ (https in v1). You may want to use tauri's convertFileSrc method to handle this and the url encoding.
@amaury-tobias I just assume it's the same issue and this is just another instance of chromium being confused and sending a generic cors error because it doesn't know better (though tbf in this case the cors error isn't even completely incorrect)
Thanks a lot for the quick answer, it works like a charm now