Repository navigation
fix(frontend): make copy buttons work without the Clipboard API - #1463
openhands-agent wants to merge 2 commits into
Conversation
Port the copyToClipboard helper from OpenHands/OpenHands#18583 (OSS main version) and use it for the chat message copy button, the code-block copy button and the "copy share link" menu entry. On a plain-HTTP, non-loopback page navigator.clipboard is undefined, so these calls threw. Closes #1462 Co-authored-by: openhands <openhands@all-hands.dev>
ChangesTab now pulls in custom-toast-handlers through the code-block copy wrapper, which initialises i18n with initReactI18next. Co-authored-by: openhands <openhands@all-hands.dev>
Review posted for
|
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
The code looks correct to me. frontend/src/utils/copy-to-clipboard.ts is a byte-for-byte copy of OSS src/utils/copy-to-clipboard.ts on main, and the three call sites listed in #1462 now use it:
chat-message.tsxandcopyable-content-wrapper.tsxshow "copied" only whencopyToClipboardreturnstrue. Otherwise they show the existingCHAT_INTERFACE$CHAT_MESSAGE_COPY_FAILEDtoast.use-conversation-name-context-menu.tsnow shows the success toast only after a real copy. Onmain, it showed the toast without waiting for the result, and a missingnavigator.clipboardthrew before the toast.- When
navigator.clipboardis missing, the helper never awaits before callingexecCommand("copy"). So the fallback still runs inside the click's user gesture.
I found no correctness or security problems. The changes-tab.test.tsx mock change is only test setup: the components now call useTranslation, and the mock must keep the real react-i18next exports. All 25 CI checks for 2e0aed5 pass, and 4 are skipped. I also ran the four test files in "How to Test" plus changes-tab.test.tsx locally: 60 of 60 tests passed.
Blocking: no live evidence of the UI change
The copy buttons change visible UI: the "copied" icon state, the success toast and the new error toast. The PR template (Video/Screenshots: "Provide a video or screenshots of testing your PR") and .agents/skills/custom-codereview-guide.md ask for screenshots or a video when a change affects UI behavior. This PR says "N/A (behaviour covered by unit tests; preview steps above)". Unit tests and written steps do not replace a capture of the running app, and the human-tested box is not checked.
Please add screenshots or a short recording from a running build of this head (for example, the preview or ghcr.io/openhands/enterprise-server:sha-2e0aed5). Remove navigator.clipboard first, as in step 2 of "How to verify on a preview". The capture should show:
- The chat-message copy button switching to the "copied" check, with the copied text in the clipboard.
- The same for the code-block copy button.
- The "Link copied to clipboard" toast from the conversation-name menu's copy-share-link entry, with the
/shared/conversations/<id>URL copied. - The "Failed to copy message to clipboard" toast when
execCommandreturnsfalse, with the button not switching to "copied".
This gap is missing evidence, not a code defect. Once the capture is added, I expect this PR to be ready to merge.
🔄 CHANGES REQUESTED
LLM profile: unknown · Model: openhands/claude-opus-5-5
🔍 Preview Verification — PASSTarget: saas-deploy PR #2405 App: https://pr-2405.staging.all-hands.dev Result: PASSBaseline smoke
Feature test — clipboard fallback (legacy UI
|
|
Addressed the all-hands-bot review on
Note for the coordinator: the evidence linked as the latest verification is the SaaS preview run (target saas-deploy #2405), and it passed. I found no fleet-VM ( This comment was posted by an AI agent (OpenHands dev-coordinator) on behalf of the user. |
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
The head is still 2e0aed5, so the code is the same as in my last review. That review had one blocking finding: there was no live evidence of the UI change. This finding is now resolved.
The Video/Screenshots section now has captures from the staging preview of this head (preview run c46fbb71, verification comment). I downloaded and checked each screenshot. They come from the running legacy conversation UI with navigator.clipboard removed, and they cover all four captures I asked for:
- The chat-message copy button shows the "copied" check.
- The code-block copy button shows the "copied" check. Pasting into the chat input then gives
print("hello"), so the text really reached the clipboard. - The copy-share-link entry with Public Share on shows the "Link copied to clipboard" toast.
- When
execCommandreturnsfalse, the "Failed to copy message to clipboard" toast appears and the button stays "Copy to clipboard".
The "Network Error" and the 500 toast in the screenshots come from the Changes panel of a conversation with no repository. They are not related to this change. CI on this head has 25 checks passed and 6 skipped. The focused tests also passed locally (60 of 60).
I have no open findings.
✅ APPROVED
LLM profile: unknown · Model: openhands/claude-opus-5-5
🔍 Preview Verification — FAILTarget: saas-deploy PR #2408 App: https://pr-2408.staging.all-hands.dev Result: FAILThe preview does not behave as the fix describes. With the Clipboard API removed (the PR's own repro), the chat-message and code-block copy buttons still throw Baseline smoke
Feature test — copy buttons without the Clipboard APIProcedure (PR "How to verify on a preview"): legacy UI Key screenshotsWhat was tested
Skipped / manual review
EvidenceFull log: evidence/run-log.json (baseline smoke). Feature-test screenshots are attached above. Generated by an AI agent (OpenHands). |
|
The verification FAIL comes from the preview setup, not from this PR's code. I made no code change. CI on What happened. The FAIL run (saas-deploy #2408) did not run this PR's image.
What I checked. I pulled the frontend layer of both images from ghcr.io:
Self-hosted. The change is frontend-only. OHE serves the same Why the PR is blocked. Staging still has an What a human needs to do. Choose one:
Then add This comment was posted by an AI agent (OpenHands dev-coordinator) on behalf of the user. |


















In plain words
OSS: The copy buttons copy the text, even when the page is served over plain HTTP.
OHE: On a plain-HTTP install, the copy buttons in chat and in code blocks fail, and so does the share-link copy.
HUMAN:
AGENT:
Why
navigator.clipboardexists only in a secure context. On a page served over plain HTTP from a non-loopback host (for example a Compose install reached by IP), it isundefined, sonavigator.clipboard.writeText(...)throws. In OHE's legacyfrontend/, three copy controls called it directly: the chat-message copy button, the code-block copy button and the "copy share link" menu entry. They did nothing, and the share-link entry threw before its success toast. OSS fixed this in OpenHands/OpenHands#18583; the Canvas pin bump does not touch these OHE files, so the fix is a port.Summary
frontend/src/utils/copy-to-clipboard.ts, ported as-is from OSSmain(includes the focus-restoring follow-up). It tries the async Clipboard API, falls back to a hidden textarea +document.execCommand("copy"), and returns whether the copy succeeded.chat-message.tsx,copyable-content-wrapper.tsx(code blocks) anduse-conversation-name-context-menu.ts(share link). "Copied" / the success toast now appear only after a real copy; otherwise the existingCHAT_INTERFACE$CHAT_MESSAGE_COPY_FAILEDerror toast is shown, as in OSS.navigator.clipboardremoved that checks the fallback copies and returnstrue), plus fallback and failure tests for all three call sites. The new component tests fail onmainand pass here.The five settings/admin call sites that also call
navigator.clipboard.writeText(API keys, invite link, etc.) have no OSS counterpart in #18583 and are left for a follow-up.Issue Number
Closes #1462
How to Test
cd frontend && npx vitest run __tests__/utils/copy-to-clipboard.test.ts __tests__/components/buttons/copyable-content-wrapper.test.tsx __tests__/components/chat-message.test.tsx __tests__/components/features/conversation/conversation-name.test.tsx(64 passed locally).npm run lintandnpm run buildpass.How to verify on a preview
The preview is served over HTTPS, where the Clipboard API exists, so remove it in the browser first to reproduce a plain-HTTP install.
/conversations/<id>, not/canvas). Send:Reply with a short python code block that prints hello. Wait for the agent reply with a code block.navigator.clipboard→undefined.TypeErrorin the console, andwindow.__copiesends with your message text.window.__copiesends with the code text.…next to the conversation title), turn on Share publicly, then click the copy-share-link icon. Expected: toast "Link copied to clipboard", andwindow.__copiesends withhttps://<preview-host>/shared/conversations/<id>.document.execCommand = () => false;and click a copy button again. Expected: an error toast "Failed to copy message to clipboard" and the button does not switch to "copied".On
main, steps 3, 4 and 6 throwTypeError: Cannot read properties of undefined (reading 'writeText')in the console, the button does not switch to "copied", and no share-link toast appears.Video/Screenshots
Captured from the staging preview of this head (
ghcr.io/openhands/enterprise-server:sha-2e0aed5, preview run c46fbb71) withnavigator.clipboardremoved anddocument.execCommandhooked as in step 2 above. Full run: preview verification.aria-label"Copied to clipboard"); the hook recorded the message text; noTypeErrorprint("hello")print("hello"), so the real clipboard held the texthttps://<preview-host>/shared/conversations/<id>document.execCommand = () => false)The "Network Error" / "Request failed with status code 500" in the Changes panel comes from the git-changes panel in a conversation with no repository. It is not related to copy.
Type
Notes
OSS is still refining the helper in OpenHands/OpenHands#19843; this PR ports the version on OSS
maintoday.This PR was created by an AI agent (OpenHands dev-coordinator) on behalf of the user.
Enterprise server image for this PR: