wry icon indicating copy to clipboard operation
wry copied to clipboard

Reading an IPC request from a file url results in a panic.

Open MaxMahem opened this issue 6 months ago • 0 comments

Describe the bug When Wry receives an IPC message from a webview with a local file URL (IE, file:///C:/some/path/to/file.html), it panics due to an error decoding the URI. This is related to this bug in the http crate. It thinks the authority portion should not be empty; however, this is the proper format, and is what Chrome is populating for this value. The value the user sets for the URL in the WebView does not matter (i.e., even if they specify localhost for the authority, the issue still occurs because Chrome seems to trim it).

Steps To Reproduce Create a wry webview that points to a local file, and add an ipc handler. Whenever the webview sends an ipc message, it will panic.

fn main() -> wry::Result<()> {
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new().build(&event_loop)?;

    // using local host here does not solve the issue
    let file_uri = "file://localhost/C:/WillPanic.html";

    let _webview = WebViewBuilder::new(window)?
        .with_url(file_uri)?
        .with_ipc_handler(|_| {}) // what the handler actually does doesn't matter.
        .build()?;

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;
    });
}

WillPanic.html

<!DOCTYPE html>
<html>
  <body>
    <script>
      window.ipc.postMessage("will panic");
    </script>
  </body>
</html>

Expected behavior It should not panic, and pass through the event normally.

Platform and Versions (please complete the following information): OS: Windows 11 Rustc: 1.89.0

MaxMahem avatar Oct 06 '25 18:10 MaxMahem