Open idootop opened 6 months ago
Seems like this is the cause of #1142?
Do you have an idea on how to fix this issue?
any update? this bug prevents me from developing on a Mac and requires me to develop in a Windows virtual machine
@darkskygit Would you happen to have a minimal reproduction example (or any kind of reproduction)?
@darkskygit Would you happen to have a minimal reproduction example (or any kind of reproduction)?
https://github.com/darkskygit/tauri-custom-uri-schema-crash
the latest commit will make tauri crash in mac
Does this only happen with http
/ https
and other known/native schemes? WKWebView does not allow registering schemes that it already handles by default so it makes sense if it crashes then.
Does this only happen with
http
/https
and other known/native schemes? WKWebView does not allow registering schemes that it already handles by default so it makes sense if it crashes then.
i tried to register a custom schema, and it indeed no longer causes a crash
Is there any other way to forward requests under certain paths (e.g., /api/*
) to Rust? Using custom paths or invoke requires a lot of changes to the front-end code, and registering http://
works well on windows
Not that i know of. Windows also only works by accident here. Once we drop win7 support tauri will use a different api for the custom protocol which would break your implementation.
After that you could use the request intercept api we currently use on windows for the custom protocol of course (example) but there's no equivalent on linux/macos as long as we're stuck with the current webviews.
Not that i know of. Windows also only works by accident here. Once we drop win7 support tauri will use a different api for the custom protocol which would break your implementation.
After that you could use the request intercept api we currently use on windows for the custom protocol of course (example) but there's no equivalent on linux/macos as long as we're stuck with the current webviews.
if it is not possible to register a custom protocol for http under linux/macos, how does tauri respond to static files?
can I use the same method to register a custom handler?
my current implementation can also return frontend static assets, so it is acceptable for my custom handler to respond to all requests but not only /api/*
Tauri serves the frontend via the tauri://
scheme via the custom protocol webview apis (the same ones that do not allow overwriting existing schemes). Requests to those schemes can be handled just fine.
my current implementation can also return frontend static assets, so it is acceptable for my custom handler to respond to all requests but not only /api/*
Then you'd have to change the url of the window to your custom scheme.
Tauri serves the frontend via the
tauri://
scheme via the custom protocol webview apis (the same ones that do not allow overwriting existing schemes). Requests to those schemes can be handled just fine.my current implementation can also return frontend static assets, so it is acceptable for my custom handler to respond to all requests but not only /api/*
Then you'd have to change the url of the window to your custom scheme.
Thank you for your prompt response. To help others quickly understand this problem, I write a summary of the above discussion:
http
, https
), this will make webview crash in macospub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.register_asynchronous_uri_scheme_protocol("custom_schema", |app, req, resp| {
let path = req.uri().path();
// response static files or api response here
resp.respond(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(CONTENT_TYPE, TEXT_PLAIN.essence_str())
.body("failed to generate response".as_bytes().to_vec())
.unwrap(),
);
})
.invoke_handler(tauri::generate_handler![])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
tauri.conf.json
:
{
"build": {
"frontendDist": "custom_protocol://localhost"
}
}
Describe the bug
When initiating a
register_uri_scheme_protocol
request from the web side, if the web aborts the request before or during the response, the macOS APP crashes.Reproduction
register_asynchronous_uri_scheme_protocol
.Expected behavior
responder
should check if the request has been canceled. If the request has been canceled, do not send the response.Full
tauri info
outputStack trace
Additional context
Related code: https://github.com/tauri-apps/wry/blob/5789bf759ce94e4dad5ff26a08fe81521658a4e4/src/wkwebview/mod.rs#L272
Related issue: https://github.com/tauri-apps/tauri/issues/9177