Skip to content

fix(app): open links in terminal output through the opener plugin - #41

Merged
arifintahu merged 2 commits into
emberterm:mainfrom
bfs2021:fix/terminal-links-opener
Oct 29, 2026
Merged

arifintahu merged 2 commits into
emberterm:mainfrom
bfs2021:fix/terminal-links-opener

Conversation

@bfs2021

@bfs2021 bfs2021 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Problem

Ctrl-clicking a URL in the terminal output goes through xterm's WebLinksAddon default handler, i.e. window.open inside the Tauri webview, instead of the system browser. Fixes #39. The app already opens external links through @tauri-apps/plugin-opener (see settings/AboutSettings.svelte).

Root cause

packages/app/src/terminal/Grid.svelte loaded new WebLinksAddon() with no handler, so the addon fell back to its built-in window.open. The opener:default permission is already granted in packages/desktop/capabilities/default.json; only the wiring was missing.

Fix

Add packages/app/src/terminal/links.ts with openExternalLink(event, uri), which forwards http(s) URLs to openUrl from @tauri-apps/plugin-opener (case-insensitive on the scheme) and ignores every other scheme, then pass it as the WebLinksAddon handler in Grid.svelte. Other schemes are dropped rather than falling back to window.open, so printed terminal output cannot trigger file:// or other webview-navigating schemes. CHANGELOG updated under [Unreleased].

Testing

  • New packages/app/src/terminal/links.test.ts (Vitest, 3 tests: http/https forwarded to openUrl, case-insensitive scheme, non-http(s) schemes ignored). It failed before the fix (module missing) and passes after.
  • pnpm exec vitest run in packages/app: 22 files / 151 tests pass.
  • svelte-check in packages/app: 0 errors (9 pre-existing warnings in ProfileEditor.svelte, untouched by this change).
  • vite build for @emberterm/ui and @emberterm/app: success.
  • Rust checks (cargo fmt/clippy/test) were not run: no Rust toolchain on this machine and the change touches no Rust file; CI will cover them.
  • The "Ctrl-click opens the system browser in a built app" checkbox still needs a visual check on a real build; I could verify the handler logic in Vitest only.

WebLinksAddon's default handler does window.open inside the webview,
where a Tauri app has no browser to fall back on. Pass a handler that
routes http(s) links through @tauri-apps/plugin-opener like the About
page does, and ignore other schemes so printed output cannot navigate
the webview.

Fixes emberterm#39

@arifintahu arifintahu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes

Thanks for the fix. The approach is right: routing http(s) links through the opener plugin and dropping other schemes. I also checked it on a dev build (pnpm dev). Ctrl-clicking https://example.com in the terminal opened it in the system browser, so the checkbox in your test plan is covered. One change is needed before merge.

1. Surface openUrl failures (required)

In packages/app/src/terminal/links.ts, openUrl(uri).catch(console.error) swallows the error. If the opener rejects (scope denies the URL, no default browser, IPC error), Ctrl-click does nothing and the user sees nothing. CLAUDE.md says: "Catch IPC errors and expose them as component state — never silently swallow."

Please show a toast on failure using the existing toast updater in stores/app.ts. Please also add a Vitest case where openUrl rejects and the toast is raised.

2. Optional, can be a follow-up

  • Parse the URI with new URL(uri) and check protocol, instead of the prefix regex. A bare https:// currently passes the check.
  • Move import { openExternalLink } from "./links.js" in Grid.svelte next to the other local imports, away from the xterm addon imports.

@bfs2021

bfs2021 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Done in 94969b3:

  1. openExternalLink now shows a toast through pushToast from stores/app.ts when openUrl rejects, including the URL and the error message. Added a Vitest case where openUrl rejects and asserts the toast text; the suite is 152 passed and svelte-check reports 0 errors.
  2. Also did both optional items: the scheme check parses with new URL() (so a bare https:// is ignored and covered by the ignore test), and the links.js import in Grid.svelte moved next to the other local imports. CHANGELOG updated.

@arifintahu arifintahu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. The earlier requests are fixed: openUrl failures now raise a toast, there is a Vitest case for the rejection path, the scheme check parses with new URL and allows only http(s), and the import order is fixed. On the PR head, Vitest passes (152 tests) and svelte-check reports 0 errors. Minor, not blocking: the toast shows the full URL, so a very long link gives a long toast.

@arifintahu

Copy link
Copy Markdown
Member

Thanks for the fixes. Merging now.

@arifintahu
arifintahu merged commit 795e5aa into emberterm:main Oct 29, 2026
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.

fix(app): open links in terminal output through the opener plugin

2 participants