Skip to content

fix: add clipboard fallback for code block copy in web UI#1472

Open
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/web-codeblock-copy
Open

fix: add clipboard fallback for code block copy in web UI#1472
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/web-codeblock-copy

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 17, 2026

Problem

The navigator.clipboard.writeText API requires a secure context (HTTPS or localhost). When the web UI is accessed over plain HTTP or on platforms without clipboard support (e.g., Termux), the copy button fails silently.

Fix

Add a fallback using document.execCommand('copy') with a temporary textarea element when the Clipboard API is unavailable.

Fixes #1340


Open with Devin

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 804c13be09

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 412 to 415
document.execCommand("copy");
document.body.removeChild(textarea);
}
setIsCopied(true);

Choose a reason for hiding this comment

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

P1 Badge Check execCommand result before reporting copy success

In the fallback path, document.execCommand("copy") can return false when copy is blocked or unsupported (common in the same older/non-secure environments this branch targets), but the code unconditionally marks the action as successful and triggers onCopy. That gives users a false “copied” state and suppresses onError even though nothing reached the clipboard.

Useful? React with 👍 / 👎.

@Br1an67 Br1an67 force-pushed the fix/web-codeblock-copy branch from 804c13b to 1cc5ce1 Compare March 17, 2026 07:19
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1cc5ce1d93

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +527 to +528
const success = document.execCommand("copy");
document.body.removeChild(textarea);

Choose a reason for hiding this comment

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

P2 Badge Ensure fallback textarea is removed when copy throws

In the fallback path, document.body.removeChild(textarea) runs only after document.execCommand("copy") returns; if execCommand is missing or throws (a realistic case in the older/non-secure environments this branch targets), the catch handler runs but the temporary textarea is never removed. Repeated copy attempts then keep appending hidden nodes to the DOM. Wrap the fallback in try/finally so cleanup always runs.

Useful? React with 👍 / 👎.

devin-ai-integration[bot]

This comment was marked as resolved.

The Clipboard API (navigator.clipboard.writeText) requires a
secure context (HTTPS or localhost). When the web UI is accessed
over plain HTTP or on platforms without clipboard support (e.g.,
Termux), the copy button silently fails.

Add a fallback using document.execCommand('copy') with a
temporary textarea element for non-secure contexts.

Fixes MoonshotAI#1340
@Br1an67 Br1an67 force-pushed the fix/web-codeblock-copy branch from 1cc5ce1 to 57b5a1e Compare March 17, 2026 07:59
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.

Web ui codeblock copy not function

1 participant