fix: add clipboard fallback for code block copy in web UI#1472
fix: add clipboard fallback for code block copy in web UI#1472Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
There was a problem hiding this comment.
💡 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".
| document.execCommand("copy"); | ||
| document.body.removeChild(textarea); | ||
| } | ||
| setIsCopied(true); |
There was a problem hiding this comment.
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 👍 / 👎.
804c13b to
1cc5ce1
Compare
There was a problem hiding this comment.
💡 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".
| const success = document.execCommand("copy"); | ||
| document.body.removeChild(textarea); |
There was a problem hiding this comment.
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 👍 / 👎.
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
1cc5ce1 to
57b5a1e
Compare
Problem
The
navigator.clipboard.writeTextAPI 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