fix(gui): open external links in the default browser via tauri-plugin-opener - #452
Open
zhouzhuozhzh-maker wants to merge 1 commit into
Open
Conversation
…-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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
tauri-plugin-openerwas not installed, sowindow.__TAURI__.openerwasundefinedandopenExternal()intauri.tscould only fall back towindow.open()(which also navigates the webview, not the system browser).Markdown.tsxrendered links as plain<a target="_blank">without callingopenExternal(), 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)tauri-plugin-opener = "2"toCargo.tomltauri_plugin_opener::init()inlib.rsopener:defaultpermission incapabilities/default.json2. Intercept link clicks in the frontend
Markdown.tsx, add anonClickhandler that callse.preventDefault()+openExternal(href)for external links, so the URL is handed to the opener plugin (which launches the default browser) instead of navigating the webviewwindow.open()in browser dev mode (where the opener plugin is not present)openExternal()that said "the desktop webview has no opener plugin wired yet" — it is now wired3. Tests
openExternalwith the correct URLFiles changed
surfaces/gui/src-tauri/Cargo.tomltauri-plugin-openerdependencysurfaces/gui/src-tauri/src/lib.rssurfaces/gui/src-tauri/capabilities/default.jsonopener:defaultpermissionsurfaces/gui/src/tauri.tsopenExternalcommentsurfaces/gui/src/components/Markdown.tsxopenExternal()surfaces/gui/src/components/Markdown.test.tsxVerification