Skip to content

fix(ui): fallback to execCommand for clipboard copy when navigator.clipboard fails - #27993

Merged
Brendonovich merged 1 commit into
anomalyco:devfrom
SpiritChen51:fix/web-copy-message
May 18, 2026
Merged

Brendonovich merged 1 commit into
anomalyco:devfrom
SpiritChen51:fix/web-copy-message

Conversation

@SpiritChen51

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #27992

Type of change

  • Bug fix

What does this PR do?

navigator.clipboard.writeText() can silently fail in:

  • Non-HTTPS contexts (e.g., localhost during development)
  • Environments where the Clipboard API is blocked by browser permissions

This PR adds a writeClipboard() helper that:

  1. First attempts to copy via document.execCommand("copy") using a temporary textarea (works in all browser contexts)
  2. Falls back to navigator.clipboard.writeText() if the execCommand approach fails
  3. Only updates the "copied" visual state when the copy actually succeeds

This fixes the copy button appearing to do nothing on the web UI.

How did you verify your code works?

Tested manually on the web interface by verifying copy works. The execCommand fallback is a well-known pattern for clipboard operations in web applications.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ipboard fails

On the web interface, navigator.clipboard.writeText() can silently fail in
non-HTTPS contexts (localhost) or when the Clipboard API is blocked. Added a
writeClipboard() helper that falls back to document.execCommand('copy') via a
temporary textarea, which works in all browser contexts. Also gate the 'copied'
state update on the actual copy result.

Fixes anomalyco#27992
@Brendonovich
Brendonovich merged commit fe143df into anomalyco:dev May 18, 2026
3 of 4 checks passed
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
isaacfinnegan pushed a commit to isaacfinnegan/whispercode that referenced this pull request Jun 15, 2026
MarsQiu007 referenced this pull request in MarsQiu007/openNovel Jul 31, 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.

[bug] Copy message button does not work on web interface

2 participants