Skip to content

fix(web): clipboard fallback for non-secure contexts (e.g. port-forwarding)#1448

Draft
zhiyuan1i wants to merge 1 commit intoMoonshotAI:mainfrom
zhiyuan1i:lzy/fix-copy-clipboard
Draft

fix(web): clipboard fallback for non-secure contexts (e.g. port-forwarding)#1448
zhiyuan1i wants to merge 1 commit intoMoonshotAI:mainfrom
zhiyuan1i:lzy/fix-copy-clipboard

Conversation

@zhiyuan1i
Copy link
Contributor

@zhiyuan1i zhiyuan1i commented Mar 16, 2026

Related Issue

Description

Bug: The copy buttons throughout the web UI silently fail when accessed via VS Code remote port-forwarding (or similar tunnels), because navigator.clipboard.writeText() requires a secure context (HTTPS or localhost).

Fix: Add a shared copyToClipboard() utility (web/src/lib/clipboard.ts) that:

  1. Tries navigator.clipboard.writeText() first (modern API).
  2. Falls back to document.execCommand("copy") with a hidden textarea when the modern API is unavailable or rejected.

All 6 direct navigator.clipboard.writeText() call sites are replaced with the new utility:

  • code-block.tsx — code block copy button
  • message.tsx — message copy button
  • error-boundary.tsx — error copy button
  • session-info-popover.tsx — session info copy
  • open-in-button.tsx — path copy
  • open-in-menu.tsx — working dir copy

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@zhiyuan1i zhiyuan1i force-pushed the lzy/fix-copy-clipboard branch from e1c2bf6 to acefd46 Compare March 16, 2026 05:27
…rding)

navigator.clipboard.writeText requires a secure context (HTTPS or
localhost). When the web UI is accessed via VS Code port-forwarding or
similar tunnels, the browser may block the Clipboard API silently.

Add a shared copyToClipboard() utility that tries the modern API first
and falls back to document.execCommand("copy") with a hidden textarea.
Replace all 6 direct navigator.clipboard.writeText calls with it.
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.

1 participant