[bug] macOS/iOS: Content-Disposition: attachment responses show a blank page instead of downloading
AI-assisted.
Describe the bug
On macOS (and iOS, same wkwebview backend), a main-frame response sent with Content-Disposition: attachment whose MIME type WebKit can display (PDF, images, text/plain, text/html, …) is shown as a blank page. The download handlers never run, so the file is neither displayed nor downloaded.
navigation_policy_response in src/wkwebview/navigation.rs only returns WKNavigationResponsePolicy::Download when !canShowMIMEType; otherwise it returns Allow. WebKit's Cocoa API does not handle Content-Disposition for the client: NavigationState::NavigationClient::decidePolicyForNavigationResponse looks at canShowMIMEType only, and WebKit's own MiniBrowser (Tools/MiniBrowser/mac/WK2BrowserWindowController.m) downloads when responseIsAttachment(response) || (!canShowMIMEType && forMainFrame), noting that WebKit does not turn these into downloads on the client's behalf. Allowing such a response commits an empty document ("Cannot execute JavaScript in this document").
The other backends already download attachments: WebKitGTK's default decide-policy handler downloads when isAttachment() (wry only overrides navigation actions there), and WebView2 handles it natively. The macOS behaviour dates from the original download callbacks (#530) and is unchanged on dev.
Real-world case: Moodle serves every assignment submission file with Content-Disposition: attachment, so opening a submitted PDF in a wry webview shows a white page.
Steps To Reproduce
- Serve a PDF with
Content-Type: application/pdfandContent-Disposition: attachment; filename="report.pdf"(e.g. a small Pythonhttp.serveron127.0.0.1:8767). - Run:
use tao::{event_loop::{ControlFlow, EventLoop}, window::WindowBuilder};
use wry::WebViewBuilder;
fn main() -> wry::Result<()> {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let _webview = WebViewBuilder::new()
.with_url("http://127.0.0.1:8767/report.pdf")
.with_download_started_handler(|url, _| { println!("download_started {url}"); true })
.with_on_page_load_handler(|_, url| println!("page_load {url}"))
.build(&window)?;
event_loop.run(move |_, _, control_flow| *control_flow = ControlFlow::Wait);
}
Result: page_load fires for the PDF URL, the window stays white, download_started never fires.
Expected behavior
The response is downloaded (download_started / download_completed fire), as in browsers and on the Windows and Linux backends.
Platform and Versions (please complete the following information):
OS: macOS 15.8.1 (24H32)
Rustc: rustc 1.98.1 (48a229cea 2026-09-01)
wry: 0.57.0 and current dev (6642074)
Additional context
A fix is ready: also return Download when the response is an NSHTTPURLResponse whose Content-Disposition type is attachment. PR to follow.