Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: tell websites the macOS browser panel is Safari (#14797)

Nilay96ccc9a256a0
diff --git a/studio/src-tauri/Cargo.toml b/studio/src-tauri/Cargo.toml
index 45e9d2581a7..0ae5f28a706 100644
--- a/studio/src-tauri/Cargo.toml
+++ b/studio/src-tauri/Cargo.toml
@@ -66,7 +66,7 @@ tokio = { version = "1", features = ["test-util"] }
objc2 = { version = "0.6", features = ["exception"] }
objc2-app-kit = { version = "0.3.2", default-features = false, features = ["std", "NSAppearance", "NSButton", "NSControl", "NSResponder", "NSStatusBarButton", "NSStatusItem", "NSView", "NSBitmapImageRep", "NSImage", "NSImageRep", "NSPrintInfo", "NSPrintOperation", "NSWindow", "NSWorkspace", "NSGraphics"] }
-objc2-foundation = { version = "0.3.2", default-features = false, features = ["std", "NSArray", "NSError", "NSDictionary", "NSKeyValueCoding", "NSValue", "NSKeyValueObserving", "NSObject", "NSProcessInfo", "NSString", "NSURL", "NSURLRequest", "NSURLResponse", "NSData", "NSGeometry"] }
+objc2-foundation = { version = "0.3.2", default-features = false, features = ["std", "NSArray", "NSBundle", "NSError", "NSDictionary", "NSKeyValueCoding", "NSValue", "NSKeyValueObserving", "NSObject", "NSProcessInfo", "NSString", "NSURL", "NSURLRequest", "NSURLResponse", "NSData", "NSGeometry"] }
# The browser panel's content rules (browser_webview.rs), snapshots and printing
# (browser_capture.rs) and context menu downloads (browser_context_downloads.rs); wry already
# builds this crate.
diff --git a/studio/src-tauri/src/browser_webview.rs b/studio/src-tauri/src/browser_webview.rs
index b8ce7674e9b..1467b74aebe 100644
--- a/studio/src-tauri/src/browser_webview.rs
+++ b/studio/src-tauri/src/browser_webview.rs
@@ -991,6 +991,20 @@ fn macos_at_least(major: isize) -> bool {
})
}
+/// WebKit's default names no browser version, which sites such as Gmail refuse as outdated.
+#[cfg(target_os = "macos")]
+fn page_user_agent() -> Option<String> {
+ use objc2_foundation::{ns_string, NSBundle, NSString};
+ let safari = NSBundle::bundleWithPath(ns_string!("/Applications/Safari.app"))?;
+ let version = safari
+ .objectForInfoDictionaryKey(ns_string!("CFBundleShortVersionString"))?
+ .downcast::<NSString>()
+ .ok()?;
+ Some(format!(
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/{version} Safari/605.1.15"
+ ))
+}
+
/// Pages ask before using a capture device. With no handler wry grants every WKWebView capture
/// request on macOS without a prompt, so any page could open the microphone the app holds for
/// dictation. `Default` is WebKit's own per-site prompt there and the platform default elsewhere
@@ -1018,10 +1032,14 @@ fn with_page_profile<R: Runtime>(
if !browser_view_supported() {
return Err("native pages need macOS 14".into());
}
- Ok(if local.is_some() {
+ let builder = if local.is_some() {
builder.incognito(true)
} else {
builder.data_store_identifier(PAGE_DATA_STORE)
+ };
+ Ok(match page_user_agent() {
+ Some(agent) => builder.user_agent(&agent),
+ None => builder,
})
}
#[cfg(not(target_os = "macos"))]
@@ -2867,6 +2885,27 @@ mod tests {
assert!(args.contains("--proxy-bypass-list=<-loopback>"), "{args}");
}
+ #[cfg(target_os = "macos")]
+ #[test]
+ fn mac_pages_send_the_installed_safaris_user_agent() {
+ // plutil reads binary and XML plists alike.
+ let out = std::process::Command::new("/usr/bin/plutil")
+ .args(["-extract", "CFBundleShortVersionString", "raw", "-o", "-"])
+ .arg("/Applications/Safari.app/Contents/Info.plist")
+ .output()
+ .unwrap();
+ assert!(out.status.success(), "{out:?}");
+ let version = String::from_utf8(out.stdout).unwrap();
+ let version = version.trim();
+ assert!(!version.is_empty());
+ assert_eq!(
+ page_user_agent().unwrap(),
+ format!(
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/{version} Safari/605.1.15"
+ )
+ );
+ }
+
#[test]
fn only_public_web_pages_load() {
for url in [