Skip to content

Commit 6dcdb98

Browse files
committed
fix(desktop): open external links in default browser
Intercept navigation events in the Tauri webview and open external URLs (http/https) in the system's default browser instead of navigating internally. This prevents users from getting stuck on a "dead end" page when clicking links in AI-generated content. Fixes anomalyco#6484
1 parent fb3ca89 commit 6dcdb98

File tree

1 file changed

+19
-0
lines changed
  • packages/desktop/src-tauri/src

1 file changed

+19
-0
lines changed

packages/desktop/src-tauri/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,32 @@ pub fn run() {
236236
.unwrap_or(LogicalSize::new(1920, 1080));
237237

238238
// Create window immediately with serverReady = false
239+
let app_for_nav = app.clone();
239240
let mut window_builder =
240241
WebviewWindow::builder(&app, "main", WebviewUrl::App("/".into()))
241242
.title("OpenCode")
242243
.inner_size(size.width as f64, size.height as f64)
243244
.decorations(true)
244245
.zoom_hotkeys_enabled(true)
245246
.disable_drag_drop_handler()
247+
.on_navigation(move |url| {
248+
// Allow internal navigation (tauri:// scheme)
249+
if url.scheme() == "tauri" {
250+
return true;
251+
}
252+
// Allow localhost (the app's own server)
253+
if let Some(host) = url.host_str() {
254+
if host == "localhost" || host == "127.0.0.1" {
255+
return true;
256+
}
257+
}
258+
// Open external http/https URLs in default browser
259+
if url.scheme() == "http" || url.scheme() == "https" {
260+
let _ = app_for_nav.shell().open(url.as_str(), None);
261+
return false; // Cancel internal navigation
262+
}
263+
true
264+
})
246265
.initialization_script(format!(
247266
r#"
248267
window.__OPENCODE__ ??= {{}};

0 commit comments

Comments
 (0)