Skip to content

Conversation

@tang-vu
Copy link

@tang-vu tang-vu commented Jan 14, 2026

Summary

Fixes #8361

This PR fixes the issue where clicking links in AI responses navigates inside the Tauri webview instead of opening in the system browser.

What makes this PR different from #8520 and #7360:

  • User toggle setting - Users can choose between external browser or in-app navigation
  • Command palette integration - Quick toggle via Mod+Shift+P
  • UI toggle button - Visible in sidebar footer (desktop only)
  • Persisted preference - Setting survives app restarts

Changes

  • Global click handler: Intercepts all <a> tag clicks with http:// or https:// URLs and opens them via shellOpen() in the system browser
  • User setting: Added links.openExternally to Layout context (persisted) so users can toggle between external browser and in-app navigation
  • Command palette: Added "Open links in browser/app" command for quick toggling
  • UI toggle: Added a toggle button in the sidebar footer (only visible on desktop)

Problem

In Tauri webview, target="_blank" on <a> tags does NOT automatically open links in the system browser. When users click links from:

  • Markdown rendered AI responses
  • Native <a> tags (like the feedback button)

...the webview navigates to that URL, and users get "stuck" with no obvious way to return.

Solution

Added a global click handler that:

  1. Intercepts clicks on <a> tags with external URLs
  2. Checks user preference (window.__OPENCODE__.openLinksExternally)
  3. If enabled (default: true), prevents default navigation and opens via shellOpen()

Testing

  1. Run bun dev in packages/opencode
  2. Open desktop app
  3. Ask the AI to respond with a link (e.g., "give me a link to github")
  4. Click the link → should open in system browser
  5. Toggle the setting in sidebar → links should now navigate in-app

Files Changed

File Change
packages/desktop/src/index.tsx Global click handler
packages/app/src/context/layout.tsx Persisted setting + sync to window.__OPENCODE__
packages/app/src/app.tsx Type definition for window.__OPENCODE__
packages/app/src/pages/layout.tsx Command palette + UI toggle button

Default Behavior

Opens links in external browser (most users expect this behavior)

Users who prefer in-app browsing can toggle the setting.


Note: This PR is aware of #8520 and #7360 which address the same core issue. This PR adds additional user-facing features (toggle setting, command palette, UI button) that those PRs don't include. Happy to collaborate or consolidate if needed!

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicates Found

1. PR #8520 - fix(desktop): open external links in default browser

2. PR #7360 - fix(desktop): open external links in system browser instead of webview

You should review these PRs to determine if they're already merged, closed, or if they're addressing the same problem in a different way.

- Add global click handler to intercept all <a> tag clicks with http/https URLs
- Add user setting to toggle between external browser and in-app navigation
- Add command palette entry for quick toggling
- Add UI toggle button in sidebar (desktop only)
- Default behavior opens links in system browser for better UX

This fixes the issue where clicking links in AI responses would navigate
inside the Tauri webview, making it difficult for users to return to the app.
@tang-vu tang-vu force-pushed the fix/desktop-external-links branch from 3a44e4d to 3d3114a Compare January 15, 2026 09:57
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.

when click on a link ,in opencode desktop , it opens the link in the same window , not external browser

1 participant