Skip to content

fix(gui): open external links in the default browser via tauri-plugin-opener - #452

Open
zhouzhuozhzh-maker wants to merge 1 commit into
andrewyng:mainfrom
zhouzhuozhzh-maker:fix/external-links-open-default-browser
Open

fix(gui): open external links in the default browser via tauri-plugin-opener#452
zhouzhuozhzh-maker wants to merge 1 commit into
andrewyng:mainfrom
zhouzhuozhzh-maker:fix/external-links-open-default-browser

Conversation

@zhouzhuozhzh-maker

Copy link
Copy Markdown

Problem

In the Tauri desktop shell, clicking a link in an assistant message (rendered as markdown) does not open the user's default browser. Instead, the anchor tag's target="_blank" attempts to navigate the webview itself, which either does nothing or opens inside the app window — not the system browser.

The root cause was two-fold:

  1. No opener plugin: tauri-plugin-opener was not installed, so window.__TAURI__.opener was undefined and openExternal() in tauri.ts could only fall back to window.open() (which also navigates the webview, not the system browser).
  2. No click interception: Markdown.tsx rendered links as plain <a target="_blank"> without calling openExternal(), so even if the opener plugin had been present, the links wouldn't have used it.

Fix

1. Wire up tauri-plugin-opener (Rust shell)

  • Add tauri-plugin-opener = "2" to Cargo.toml
  • Register tauri_plugin_opener::init() in lib.rs
  • Grant opener:default permission in capabilities/default.json

2. Intercept link clicks in the frontend

  • In Markdown.tsx, add an onClick handler that calls e.preventDefault() + openExternal(href) for external links, so the URL is handed to the opener plugin (which launches the default browser) instead of navigating the webview
  • Falls back to window.open() in browser dev mode (where the opener plugin is not present)
  • Updated the comment on openExternal() that said "the desktop webview has no opener plugin wired yet" — it is now wired

3. Tests

  • Added a test verifying that clicking an ordinary markdown link calls openExternal with the correct URL
  • All 109 existing frontend tests continue to pass

Files changed

File Change
surfaces/gui/src-tauri/Cargo.toml Add tauri-plugin-opener dependency
surfaces/gui/src-tauri/src/lib.rs Register opener plugin
surfaces/gui/src-tauri/capabilities/default.json Grant opener:default permission
surfaces/gui/src/tauri.ts Update openExternal comment
surfaces/gui/src/components/Markdown.tsx Intercept clicks → openExternal()
surfaces/gui/src/components/Markdown.test.tsx Add click→openExternal test

Verification

✓ src/components/Markdown.test.tsx (4 tests) — 27ms
✓ 18 test files, 109 tests passed (2.53s)
``

…-opener

In the Tauri desktop shell, anchor tags with target="_blank" navigate the
webview instead of launching the system browser, so clicking links in
assistant messages (rendered as markdown) does nothing useful.

- Add tauri-plugin-opener to Cargo.toml and register it in lib.rs
- Grant the opener:default permission in capabilities/default.json
- Intercept link clicks in Markdown.tsx and hand the URL to openExternal(),
  which uses the opener plugin to launch the default browser (falls back to
  window.open in browser dev mode)
- Update the existing openExternal() comment that said the opener plugin was
  not wired yet
- Add a test verifying that clicking a link calls openExternal with the URL
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