Skip to content

feat(desktop): expose navigation_handler in Config#5390

Open
FreeSynergy wants to merge 3 commits intoDioxusLabs:v0.6from
FreeSynergy:feat/configurable-navigation-handler
Open

feat(desktop): expose navigation_handler in Config#5390
FreeSynergy wants to merge 3 commits intoDioxusLabs:v0.6from
FreeSynergy:feat/configurable-navigation-handler

Conversation

@FreeSynergy
Copy link
Copy Markdown

Summary

The navigation handler in dioxus-desktop is currently hardcoded in webview.rs:

.with_navigation_handler(|var| {
    if var.starts_with("dioxus://") || var.starts_with("http://dioxus.") {
        true
    } else {
        if var.starts_with("http://") || var.starts_with("https://") {
            _ = webbrowser::open(&var);
        }
        false
    }
})

This unconditionally opens every external http/https URL in the system browser and blocks it in the WebView. Apps that intentionally embed web content (e.g. via <iframe>) have no way to opt out of this behavior or to allow specific URLs.

Changes

  • config.rs: adds navigation_handler: Option<Box<dyn Fn(String) -> bool + 'static>> field to Config, initialized to None.
  • config.rs: adds pub fn with_navigation_handler(mut self, handler: impl Fn(String) -> bool + 'static) -> Self builder method with full doc-comment and example.
  • webview.rs: if cfg.navigation_handler is Some, the closure delegates entirely to the user-supplied handler; otherwise the existing hardcoded behavior is preserved exactly.

Non-breaking

When with_navigation_handler is not called (the default), behavior is identical to before — no existing apps are affected.

Example

let cfg = Config::new()
    .with_navigation_handler(|url| {
        // Allow dioxus internal URLs and a trusted external origin
        url.starts_with("dioxus://") || url.starts_with("https://trusted.example.com")
    });

@FreeSynergy FreeSynergy requested a review from a team as a code owner March 19, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant