Skip to content

fix(gui): open external links in system browser (fixes #270) - #271

Open
EvanProgramming wants to merge 1 commit into
andrewyng:mainfrom
EvanProgramming:fix/external-links-issue-270
Open

fix(gui): open external links in system browser (fixes #270)#271
EvanProgramming wants to merge 1 commit into
andrewyng:mainfrom
EvanProgramming:fix/external-links-issue-270

Conversation

@EvanProgramming

Copy link
Copy Markdown

Fixes #270 — links reported by OpenWorker could not be opened by left-click or right-click "Open Link"; nothing happened and no permission dialog appeared (v0.1.6, macOS).

Root cause

  • The desktop shell never wired up an opener: tauri-plugin-opener was not a dependency, not registered in lib.rs, and no opener permission existed in capabilities/default.json. src/tauri.ts even noted it: "the desktop webview has no opener plugin wired yet".
  • openExternal() therefore fell back to window.open(), and markdown links rely on <a target="_blank"> — both are silently dropped by the Tauri v2 webview (no popup, no error), which matches the "nothing happens" report.
  • Right-click "Open Link" issues a native full-page navigation; with no on_navigation handler it was dropped as well.

Fix

Rust shell (surfaces/gui/src-tauri/)

  • Add tauri-plugin-opener = "2", register tauri_plugin_opener::init(), and grant opener:default.
  • Add an on_navigation handler on the main window: the SPA's own origins (tauri://, http://tauri.localhost, the Vite devUrl in dev builds) stay in-app; any other http/https/mailto navigation is handed to the system browser via open_url and blocked in the webview — this fixes right-click "Open Link".

Frontend (surfaces/gui/src/)

  • Markdown.tsx: external links now preventDefault() and go through openExternal(href) — this fixes left-click. Browser builds keep the same behavior via window.open.
  • main.tsx: capture-phase click fallback (desktop only) so links rendered outside Markdown (connector cards, future surfaces) also open externally.
  • tauri.ts: updated the now-stale comment.

Behavior before / after

Action (desktop app) Before After
Left-click a web link silently ignored opens in system browser
Right-click → Open Link silently ignored opens in system browser
Browser (dev) build opens new tab unchanged
artifact: chips opens artifact viewer unchanged

Note on the screenshot guideline: the broken state renders identically to the fixed state (the bug is that clicking produces no visible response at all), so a static screenshot cannot show the difference. Happy to attach a short screen recording if that helps review.

Tests

  • npx tsc --noEmit — clean
  • npx vitest run — 69/69 passing, including a new Markdown.test.tsx case asserting link clicks are prevented and routed through openExternal
  • cargo check — clean

Left-click and right-click 'Open Link' on web links did nothing in the desktop app: the webview silently drops target=_blank popups and no opener plugin was wired up.

- Add tauri-plugin-opener (Cargo.toml, lib.rs, opener:default capability)
- Intercept full-page navigations (on_navigation) so context-menu 'Open Link' hands external URLs to the system browser instead of being dropped
- Route markdown link clicks through openExternal(); add a capture-phase fallback in main.tsx for links rendered outside Markdown
- Test: clicking an ordinary markdown link is prevented and goes through openExternal
SerienYang added a commit to SerienYang/Openworker that referenced this pull request Aug 3, 2026
The macOS/Linux webview silently drops target=_blank popups, so links in
agent replies (rendered as <a target=_blank> by Markdown.tsx) did nothing
when clicked in the packaged app, while the browser dev build worked.

Root cause (upstream issue andrewyng#227/andrewyng#270): the shell never registered an
opener — no on_new_window handler, no opener plugin, no shell plugin — so
the webview's open-new-window request vanished.

Fix (port of upstream PRs andrewyng#241/andrewyng#271 + guard):
- src-tauri: add tauri-plugin-opener, register it, and add on_navigation
  that forwards http(s)/mailto to the system browser while letting the
  SPA itself (tauri://, tauri.localhost, Vite devUrl:1420) load. This also
  fixes the webview context-menu "Open Link" (issue andrewyng#270).
- capabilities: grant opener:allow-default-urls (scoped to mailto:/tel:/http(s)).
- tauri.ts: openExternal() now calls __TAURI__.opener.openUrl() in the shell.
- Markdown.tsx: route <a> clicks through openExternal() (artifact: chips
  keep the in-app viewer).
- main.tsx: capture-phase fallback for any other <a href> http(s) link
  (connector cards, dangerouslySetInnerHTML, future surfaces).

Verified: tsc --noEmit clean, vitest 7/7, cargo check clean.
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.

无法通过右键open link打开网页

1 participant