fix: clipboard fallback for non-secure contexts (HTTP on LAN IPs)#163
Open
zhaoqirong wants to merge 1 commit intobenjitaylor:mainfrom
Open
fix: clipboard fallback for non-secure contexts (HTTP on LAN IPs)#163zhaoqirong wants to merge 1 commit intobenjitaylor:mainfrom
zhaoqirong wants to merge 1 commit intobenjitaylor:mainfrom
Conversation
`navigator.clipboard.writeText` requires a secure context (HTTPS, localhost, or 127.0.0.1). When the page is served over plain HTTP on a LAN IP such as `http://10.2.3.4:3000`, the Clipboard API is unavailable and the copy button silently fails. This adds a `copyTextToClipboard` utility that tries the modern Clipboard API first, then falls back to the legacy `document.execCommand("copy")` approach which works in all contexts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Someone 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.
Summary
navigator.clipboard.writeTextrequires a secure context (HTTPS,localhost, or127.0.0.1). When the page is served over plain HTTP on a LAN IP (e.g.http://10.2.3.4:3000), the Clipboard API is unavailable and the copy button silently fails.copyTextToClipboard()utility that tries the modern Clipboard API first, then falls back to the legacydocument.execCommand("copy")approach which works in all contexts.Changes
package/src/utils/clipboard.tsnavigator.clipboard.writeText, falls back to hidden<textarea>+execCommand("copy")package/src/utils/clipboard.test.tspackage/src/components/page-toolbar-css/index.tsxnavigator.clipboard.writeTextcall withcopyTextToClipboard()Why this happens
Browsers treat these as secure contexts (Clipboard API works):
https://any domainhttp://localhost/http://127.0.0.1(special-cased)Browsers treat these as non-secure contexts (Clipboard API unavailable):
http://10.x.x.x,http://192.168.x.x, or any plain HTTP on a non-loopback addressThis is a common scenario for development teams testing on LAN.
Test plan
pnpm test)pnpm build)copyToClipboardprop behavior is unchanged🤖 Generated with Claude Code