Skip to content

fall back to execCommand when clipboard API is unavailable - #23

Merged
ursucarina merged 1 commit into
mainfrom
carina/cppolyfill
Jul 14, 2026
Merged

fall back to execCommand when clipboard API is unavailable#23
ursucarina merged 1 commit into
mainfrom
carina/cppolyfill

Conversation

@ursucarina

Copy link
Copy Markdown
Contributor

navigator.clipboard is only available in secure contexts (HTTPS or localhost), so on deployments served over plain HTTP the copy button threw Uncaught TypeError: Cannot read properties of undefined (reading 'writeText'). This makes useCopyToClipboard async and resilient: it uses the native Clipboard API when available in a secure context, otherwise falls back to a hidden <textarea> + document.execCommand('copy'), and wraps everything in try/catch so a copy failure can never throw. Window/document/navigator access goes through the SSR-safe getWindow()/getDocument()/getNavigator() helpers to satisfy the no-restricted-globals lint rule.

Copilot AI review requested due to automatic review settings July 14, 2026 18:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the clipboard copy behavior in the UI so copy actions don’t throw on HTTP (non-secure) deployments and remain SSR-safe by routing global access through windowUtils.

Changes:

  • Makes useCopyToClipboard asynchronous and wraps clipboard operations in error handling.
  • Uses navigator.clipboard.writeText in secure contexts and falls back to a hidden <textarea> + document.execCommand('copy') otherwise.
  • Switches direct global access to getWindow()/getDocument()/getNavigator() helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/CopyButton.tsx
Signed-off-by: Carina Ursu <carina@union.ai>
@ursucarina
ursucarina enabled auto-merge July 14, 2026 19:31
@ursucarina
ursucarina added this pull request to the merge queue Jul 14, 2026
Merged via the queue into main with commit dfc97b4 Jul 14, 2026
1 check passed
@ursucarina
ursucarina deleted the carina/cppolyfill branch July 14, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants