2code icon indicating copy to clipboard operation
2code copied to clipboard

in app browser

Open AkaraChen opened this issue 6 months ago • 1 comments

Feature Description

Add first-class in-app browser tabs to 2code, so links discovered during a coding session can stay inside the same project/profile workspace instead of always jumping out to the system browser.

Motivation

2code already keeps terminal sessions, file tabs, git state, and worktree profiles together. Terminal output often contains URLs (preview servers, OAuth/login links, docs, CI pages, API dashboards). Today terminal links are handled by @xterm/addon-web-links in src/features/terminal/Terminal.tsx and confirmed via TerminalLinkConfirmDialog, then opened externally with @tauri-apps/plugin-shell.open.

For focused work, it would be useful to decide per link whether to:

  1. open inside 2code as a browser tab,
  2. open in the default system browser, or
  3. open in a specific installed browser.

Proposed Solution

1. Browser tabs scoped to the current profile

  • Add a browser tab type alongside the existing terminal/file tab groups in the current profile workspace.
  • Browser tabs should be created under the active profile, similar to how terminal/file tabs are profile-scoped today.
  • A browser tab should render an embedded webview/browser surface for the URL.
  • The tab title can initially be the URL/hostname, and ideally update to the document title when available.

2. Reuse already-open browser tabs by default

When opening a URL inside 2code:

  • If the current profile already has a browser tab with the same URL (or normalized URL), focus/switch to that existing tab instead of creating a duplicate.
  • If no matching tab exists, create a new browser tab in the current profile.
  • This default reuse behavior should apply especially when clicking terminal links.

3. Terminal link open choices

Extend the existing terminal link confirmation flow (Terminal.tsx + TerminalLinkConfirmDialog.tsx) so clicking a detected link can choose between:

  • Open in 2code / Open in app: create or focus the profile-scoped browser tab.
  • Open in default browser: current open(uri) behavior.
  • Open in another browser…: choose from installed browsers if available.

It would be nice if modifier-click behavior still works, but the default click should offer these choices rather than only asking whether to open externally.

4. Detect installed browsers and let the user choose

Add a backend command/service that can scan known installed browsers and return a list to the frontend.

Suggested behavior:

  • macOS first, since 2code primarily supports macOS.
  • Include common browsers like Safari, Chrome, Chrome Canary, Edge, Firefox, Arc, Brave, Vivaldi, etc. when present.
  • Later expand to Windows/Linux.
  • Let the user choose which browser to open with from the link dialog and/or from browser-tab actions.

5. Browser tab actions

Inside an in-app browser tab, provide an action to open the current URL externally:

  • Open in default browser.
  • Optionally open in a selected installed browser.

Suggested Implementation Notes

  • Frontend tab state likely needs a generalized tab model or a new browser tab store that composes with the current tab strip in src/features/terminal/TerminalTabs.tsx, which already combines terminal tabs and file tabs.
  • The existing terminal link entry point is src/features/terminal/Terminal.tsx:
    • WebLinksAddon(handleTerminalLinkOpen)
    • TerminalLinkConfirmDialog
    • current external open via @tauri-apps/plugin-shell.open
  • Browser tabs should follow the same persistence principle used for terminals: avoid losing browsing state unnecessarily when switching tabs. If embedded webviews are expensive or hard to persist, at minimum keep URL/title/navigation state and avoid duplicate tabs.
  • Backend browser discovery/open-with-specific-browser probably belongs behind Tauri commands in src-tauri/src/handler/*, then generated into src/generated/ via cargo tauri-typegen generate.
  • Keep i18n strings in messages/en.json and messages/zh.json.

Acceptance Criteria

  • [ ] Users can create/open a browser tab inside the active profile from a URL.
  • [ ] Clicking a terminal link lets users choose between opening in 2code, the default browser, or another installed browser where supported.
  • [ ] Opening the same URL again in the same profile focuses the existing browser tab by default instead of creating a duplicate.
  • [ ] Browser tabs include an action to open their current URL in an external browser.
  • [ ] Installed browser discovery works at least on macOS, with graceful fallback when no specific browser list is available.
  • [ ] Browser tab labels are readable (URL hostname/title) and update when practical.
  • [ ] Relevant UI strings are localized.

AkaraChen avatar May 23 '26 03:05 AkaraChen

@copilot please implement this feature and open a PR. Please follow the existing 2code architecture: keep browser tabs scoped to the current profile, reuse existing browser tabs for the same URL in the same profile, extend the terminal link dialog with in-app/default/specific-browser choices, add macOS browser discovery with graceful fallback, and include i18n strings/tests where appropriate.

AkaraChen avatar May 23 '26 03:05 AkaraChen