fix(ui): add clipboard fallback for non-secure HTTP contexts#20983
Open
zsxink wants to merge 3 commits intoanomalyco:devfrom
Open
fix(ui): add clipboard fallback for non-secure HTTP contexts#20983zsxink wants to merge 3 commits intoanomalyco:devfrom
zsxink wants to merge 3 commits intoanomalyco:devfrom
Conversation
…contexts - Fix copy button not working when accessing opencode over HTTP - Add try/catch error handling to prevent silent failures - Fallback to document.execCommand when navigator.clipboard is unavailable - Hide temporary textarea element to avoid UI glitches Fixes anomalyco#14803
navigator.clipboard is undefined in non-secure HTTP contexts, causing copy buttons to throw TypeError. Add a shared copyToClipboard utility with document.execCommand fallback and replace all direct clipboard calls across message-part, text-field, tool-error-card, markdown, and session-header components.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
Why it's related: Both PRs address the exact same issue — adding clipboard fallback functionality for non-secure HTTP contexts where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #14803
Type of change
What does this PR do?
navigator.clipboardis only available in secure contexts (HTTPS or localhost). When accessing the web UI over HTTP on a LAN, the clipboard API isundefined, causing copy buttons to throwTypeError: Cannot read properties of undefined (reading 'writeText').This PR adds a shared
copyToClipboardutility inpackages/ui/src/components/clipboard.tsxthat:navigator.clipboard.writeTextin secure contextsdocument.execCommand("copy")for non-secure HTTP contextsReplaced all direct
navigator.clipboard.writeTextcalls inmessage-part.tsx,text-field.tsx,tool-error-card.tsx,markdown.tsx, andsession-header.tsxto use this utility.How did you verify your code works?
Built the app with
bun run --cwd packages/app build, started the server withbun run --cwd packages/opencode src/index.ts web --hostname 0.0.0.0, and verified copy buttons work over HTTP on a LAN. Also verified the modern clipboard API still works correctly on localhost/HTTPS.Screenshots / recordings
N/A — behavioral fix, no visual changes.
Checklist