File uri causes panic in `attach_ipc_handler`
andrewbaxter opened this issue · 5 comments
Describe the bug
I'm using a file://
uri for the webview, and attach an IPC handler. When I run the app it panics at
thread 'main' panicked at /home/.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.39.4/src/webkitgtk/mod.rs:531:16:
called `Result::unwrap()` on an `Err` value: http::Error(InvalidUri(InvalidFormat))
stack backtrace:
0: rust_begin_unwind
at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
1: core::panicking::panic_fmt
at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
2: core::result::unwrap_failed
at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1649:5
3: core::result::Result<T,E>::unwrap
at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1073:23
4: wry::webkitgtk::InnerWebView::attach_ipc_handler::{{closure}}
at /home/.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.39.4/src/webkitgtk/mod.rs:528:13
which is
Request::builder()
.uri(webview.uri().unwrap().to_string())
.body(js.to_string())
.unwrap(),
Steps To Reproduce
Expected behavior
- I'd expect the request to be built successfully. Seems like an
http
issue hyperium/http#323 - Failing that, I'd be happy with a fake/standin/override url. I'm only using the body of the IPC request (how common is needing the URL?)
Screenshots
Platform and Versions (please complete the following information):
OS: Arch
Rustc: 1.76.0
Additional context
Looks like they're open to PRs... I'll try to take a look, but one more item in my growing backlog.
Can you please show a full reproduction example?
use tao::{
event::{
Event,
WindowEvent,
},
event_loop::{
ControlFlow,
EventLoop,
},
platform::unix::WindowExtUnix,
window::WindowBuilder,
};
use wry::{
WebViewBuilder,
WebViewBuilderExtUnix,
};
fn main() -> wry::Result<()> {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let _webview =
WebViewBuilder::new_gtk(window.default_vbox().unwrap())
.with_url(format!("file://{}/examples/test.html", env!("CARGO_MANIFEST_DIR")))
.with_ipc_handler(|_r| { })
.build()?;
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
if let Event::WindowEvent { event: WindowEvent::CloseRequested, .. } = event {
*control_flow = ControlFlow::Exit
}
});
}
with html
<html>
<body>
<script>
window.ipc.postMessage("");
</script>
</body>
</html>
I guess we need to fix this panic and reduce the number of .unwrap()
calls we have.
anyways, iirc file://
is not supported on all webviews and I'd recommend using a custom protocol to serve your asserts, see https://github.com/tauri-apps/wry/blob/dev/examples/custom_protocol.rs example
Yeah, and for error logging... in my case I only need Linux though and even with a custom protocol (can I use file://
as a custom protocol?) I'd want the sorts of uris that cause the panic here. I'm working on a fix for the http issue.