fix: add clipboard fallback for non-secure contexts (HTTP)#189
Open
ptlzc wants to merge 1 commit into
Open
Conversation
The Clipboard API (navigator.clipboard.writeText) is only available in
secure contexts (HTTPS or localhost). When agentation is used over HTTP
(e.g. via Docker dev containers accessed by IP), navigator.clipboard is
undefined and copy silently fails — the UI shows 'copied' but nothing
reaches the clipboard.
Add a copyTextToClipboard utility that falls back to the legacy
document.execCommand('copy') approach with a temporary textarea when
the Clipboard API is unavailable, ensuring copy works in all contexts.
|
@ptlzc is attempting to deploy a commit to the Benji Taylor's Projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
The Clipboard API (
navigator.clipboard.writeText) is only available in secure contexts (HTTPS orlocalhost). When agentation runs over plain HTTP — e.g. a Vite dev server inside a Docker container accessed by IP —navigator.clipboardisundefinedand the copy button silently fails. The UI shows the "copied" checkmark, but nothing actually reaches the clipboard.The existing catch block swallows the error without any fallback:
Fix
Add a
copyTextToClipboardutility that:navigator.clipboard.writeText()first (preferred, secure contexts)<textarea>+document.execCommand('copy')when the Clipboard API is unavailableThis ensures copy works in all contexts — HTTPS, localhost, and plain HTTP.
Testing
tsupCJS + ESM + types)